温馨提示×

centos怎么查看postgresql

小樊
61
2026-10-18 02:07:44
栏目: 云计算

在 CentOS 上“查看 PostgreSQL”通常包含几种常见需求,下面按最常用场景给你说明:


一、查看 PostgreSQL 是否安装

rpm -qa | grep postgres

或

yum list installed | grep postgresql

二、查看 PostgreSQL 服务状态

1️⃣ CentOS 7 / 8(systemd)

systemctl status postgresql

或(带版本号,如 12、13、14)

systemctl status postgresql-14

启动 / 停止 / 重启:

systemctl start postgresql
systemctl stop postgresql
systemctl restart postgresql

三、查看 PostgreSQL 版本

psql --version

或进入数据库后:

psql -U postgres
SELECT version();

四、查看 PostgreSQL 是否在运行

ps aux | grep postgres

或

netstat -tunlp | grep 5432

PostgreSQL 默认端口是 5432


五、查看 PostgreSQL 配置文件位置

psql -U postgres -c "SHOW config_file;"
psql -U postgres -c "SHOW data_directory;"

常见路径:

  • 配置:/var/lib/pgsql/14/data/postgresql.conf
  • 数据目录:/var/lib/pgsql/14/data

六、查看数据库 / 表

psql -U postgres
\l      -- 查看数据库
\dt     -- 查看表
\du     -- 查看用户

七、查看 PostgreSQL 日志

tail -f /var/lib/pgsql/14/data/log/postgresql-*.log

如果你是想问 “怎么连接 / 怎么装 / 怎么配置远程访问”,可以告诉我具体场景,我可以直接给你命令。

0 踩