在 CentOS 上用 pgAdmin 连接 PostgreSQL,常见有两种方式:
下面按最常见场景说明(以 pgAdmin 4 + CentOS 7/8 为例)。
systemctl status postgresql
没启动就:
systemctl start postgresql
systemctl enable postgresql
编辑 PostgreSQL 配置文件:
vi /var/lib/pgsql/data/postgresql.conf
确保:
listen_addresses = '*'
vi /var/lib/pgsql/data/pg_hba.conf
添加(示例):
host all all 0.0.0.0/0 md5
改完重启:
systemctl restart postgresql
firewall-cmd --add-port=5432/tcp --permanent
firewall-cmd --reload
localhost 或 IP5432postgrespostgresdnf install -y epel-release
dnf install -y pgadmin4-web
初始化:
/usr/pgadmin4/bin/setup-web.sh
按提示设置登录邮箱和密码。
http://服务器IP/pgadmin4
和本地 pgAdmin 操作一样。
| 问题 | 解决 |
|---|---|
| 连接超时 | 防火墙 / 安全组未放行 5432 |
| password authentication failed | 密码错或 pg_hba 配置 |
| could not connect | listen_addresses 没改 |
| 拒绝连接 | PostgreSQL 没启动 |
psql -h localhost -U postgres
如果你能告诉我:
我可以直接给你精确步骤。