“CentOS 上 PostgreSQL 崩了”原因有很多种,下面按常见原因 → 排查方法给你一个实用清单,你可以对照看看是哪一种。
CentOS 在内存耗尽时,会杀掉占用内存最多的进程,PostgreSQL 经常中招。
现象
killed processdmesg 里有 Out of memory排查
dmesg | grep -i "killed"
free -h
解决
shared_buffers、work_memmax_connectionsPostgreSQL 对磁盘非常敏感,写不进 WAL 就会直接挂。
排查
df -h
du -sh /var/lib/pgsql/*
解决
改了 postgresql.conf 或 pg_hba.conf 后启动不了。
常见错误
shared_buffers 超过系统内存listen_addresses 写错max_connections 过大排查
systemctl status postgresql
journalctl -xe
CentOS 宕机、强制重启后,PostgreSQL 可能进入恢复模式或直接崩溃。
现象
database system was not properly shut down解决
pg_resetwal(有风险)CentOS 常用 XFS,磁盘异常可能导致 PG 数据文件损坏。
排查
dmesg | grep -i error
fsck(离线)
排查
rpm -qa | grep postgres
which psql
# 1. 看服务状态
systemctl status postgresql
# 2. 看系统日志
journalctl -u postgresql
# 3. 看 PG 日志(默认)
/var/lib/pgsql/<版本>/data/log/
# 4. 看内核
dmesg | tail -50
我可以更精准判断:
如果你愿意,把 PG 日志最后 30 行贴出来,我可以直接帮你判断是哪一种崩法。