在 CentOS 下启动 PostgreSQL,常见方式取决于安装方式和版本(系统自带或官方 RPM)。下面按最常见场景说明。
systemctl list-unit-files | grep postgres
常见服务名如:
postgresqlpostgresql-14postgresql-15sudo systemctl start postgresql
或指定版本:
sudo systemctl start postgresql-15
sudo systemctl enable postgresql
sudo systemctl status postgresql
sudo service postgresql start
sudo service postgresql status
su - postgres
pg_ctl -D /var/lib/pgsql/15/data start
查看状态:
pg_ctl -D /var/lib/pgsql/15/data status
停止:
pg_ctl -D /var/lib/pgsql/15/data stop
ss -lntp | grep 5432
或
netstat -lntp | grep 5432
psql -U postgres
查看日志:
journalctl -u postgresql
或
cat /var/lib/pgsql/15/data/pg_log/*.log
通常是未初始化数据库:
sudo postgresql-setup initdb
如果你愿意,可以告诉我:
我可以给你精确到命令级别的启动方案。