以下是PostgreSQL在CentOS上的故障排查方法:
systemctl status postgresql
查看服务是否运行。/var/log/postgresql/
,使用tail -f postgresql-<版本>-main.log
实时查看。journalctl -u postgresql
查看systemd管理的日志。postgresql.conf
:确认监听地址、端口、内存参数等配置正确。pg_hba.conf
:验证客户端认证规则(如远程访问权限)。pg_stat_activity
视图查看当前连接和查询。EXPLAIN
分析慢查询,优化性能。top
、free
、df -h
等命令排查CPU、内存、磁盘空间是否不足。pg_resetwal
或从备份恢复。sudo systemctl restart postgresql
。pgBadger
分析日志,定位性能瓶颈。pgAdmin
图形化管理数据库,查看状态。参考来源:[1,2,3,4,5,6,7,8,9,10,11,12,13,14]