在 CentOS 上停止 PostgreSQL 的方法取决于你是通过 系统服务 安装的,还是 源码/手动部署 的。下面是最常见的几种方式。
systemctl list-units --type=service | grep postgres
常见服务名:
postgresqlpostgresql-14postgresql-15postgresql-12sudo systemctl stop postgresql
如果是带版本号的:
sudo systemctl stop postgresql-14
sudo systemctl disable postgresql
sudo service postgresql stop
或指定版本:
sudo service postgresql-14 stop
su - postgres
pg_ctl stop -D /var/lib/pgsql/14/data
常用参数:
pg_ctl stop -D /path/to/data -m smart # 等待所有连接结束
pg_ctl stop -D /path/to/data -m fast # 立即断开(常用)
pg_ctl stop -D /path/to/data -m immediate # 强制(类似 kill -9)
✅ 推荐使用 -m fast
ps -ef | grep postgres
或:
systemctl status postgresql
sudo -u postgres pg_ctl stop -D /path/to/data
ss -lntp | grep 5432
# CentOS 7/8/9
sudo systemctl stop postgresql
如果你愿意,可以告诉我:
我可以给你更精确的命令 ✅