在CentOS系统中,PostgreSQL的日志文件通常位于 /var/log/postgresql/ 目录下,具体文件名可能是 postgresql-{版本号}-main.log 或 postgresql-{版本号}-instance_name.log 。要查看PostgreSQL的日志,您可以使用以下方法:
cat /var/log/postgresql/postgresql-{版本号}-main.log
tail -f /var/log/postgresql/postgresql-{版本号}-main.log
less /var/log/postgresql/postgresql-{版本号}-main.log
grep "error" /var/log/postgresql/postgresql-{版本号}-main.log
PostgreSQL的日志配置通常在 postgresql.conf 文件中进行。要启用日志记录,您需要设置以下参数:
logging_collector:开启日志收集功能。log_directory:指定日志文件的存储目录(例如:‘pg_log’)。log_filename:定义日志文件的命名模式,通常包含时间戳和进程ID等信息,便于区分和排序(例如:‘postgresql-%Y-%m-%d_%H%M%S.log’)。以上就是在CentOS系统中查看PostgreSQL日志的方法,希望对您有所帮助。