在 CentOS 上查看 PostgreSQL 的状态,常用方法取决于你是使用 systemd 还是直接通过 PostgreSQL 自带的工具。下面按常见场景说明。
systemctl status postgresql
或(如果安装了多个版本,例如 PostgreSQL 14):
systemctl status postgresql-14
✅ 成功状态示例:
Active: active (running) since ...
❌ 未运行示例:
Active: inactive (dead)
systemctl is-enabled postgresql
sudo systemctl start postgresql
sudo systemctl stop postgresql
sudo systemctl restart postgresql
sudo -i -u postgres
pg_isready
✅ 正常输出示例:
/var/run/postgresql:5432 - accepting connections
❌ 异常示例:
no response
psql
\l
SELECT * FROM pg_stat_activity;
ps aux | grep postgres
或:
pgrep -a postgres
ss -lntp | grep postgres
或:
netstat -lntp | grep postgres
默认端口:
5432
日志位置通常在:
/var/lib/pgsql/data/log/
或:
/var/log/postgresql/
查看最新日志:
tail -f /var/lib/pgsql/data/log/postgresql-*.log
systemctl status postgresql
pg_isready
ps aux | grep postgres
如果你愿意,可以告诉我:
我可以给你更精确的命令。