在 CentOS 上重启 PostgreSQL,通常是通过 systemd 来管理服务。下面按常见场景给你说明。
CentOS 7 及以上版本,PostgreSQL 服务名通常是:
postgresql
或者带版本号,例如:
postgresql-12
postgresql-13
postgresql-15
先查看实际服务名:
systemctl list-units --type=service | grep postgres
sudo systemctl restart postgresql
如果是带版本号的:
sudo systemctl restart postgresql-15
如果只是修改了配置文件(如 postgresql.conf、pg_hba.conf):
sudo systemctl reload postgresql
sudo systemctl stop postgresql
sudo systemctl start postgresql
sudo systemctl enable postgresql
查看状态:
sudo systemctl status postgresql
如果你是源码安装或非 systemd 管理的 PostgreSQL:
su - postgres
pg_ctl -D /var/lib/pgsql/data restart
⚠️ 注意:
-D 后面是数据目录pg_ctl,容易和 systemd 冲突查看详细日志:
journalctl -u postgresql -xe
或 PostgreSQL 日志:
/var/lib/pgsql/data/log/
ss -lntp | grep 5432
sudo systemctl restart postgresql
sudo systemctl status postgresql
如果你愿意,可以告诉我:
我可以给你更精确的命令。