在 Debian 上排查 PostgreSQL 错误,一般可以按下面几个层次来做。
systemctl status postgresql
或(旧版本)
service postgresql status
如果没启动:
systemctl start postgresql
journalctl -u postgresql -xe
Debian 下 PostgreSQL 日志位置通常在:
/var/log/postgresql/postgresql-<版本>-main.log
例如:
tail -n 100 /var/log/postgresql/postgresql-15-main.log
实时查看:
tail -f /var/log/postgresql/postgresql-15-main.log
journalctl -u postgresql
只看最近错误:
journalctl -u postgresql -p err
sudo -u postgres psql
查看当前日志设置:
SHOW log_destination;
SHOW logging_collector;
SHOW log_directory;
postgresql.conf 中:listen_addresses = 'localhost'
pg_hba.conf 是否允许你的 IP / 用户peer 认证:只能用系统同名用户/etc/postgresql/<版本>/main/pg_hba.conf
然后:systemctl reload postgresql
重点看:
journalctl -xe
/var/log/postgresql/*.log
常见原因:
在 postgresql.conf:
log_min_messages = info
log_min_error_statement = error
log_connections = on
log_disconnections = on
改完重启或 reload。
如果你愿意,可以把具体报错信息或日志内容贴出来,我可以直接帮你定位原因。