温馨提示×

pgadmin在centos上怎么用

小樊
45
2026-10-14 23:20:47
栏目: 智能运维

在 CentOS 上使用 pgAdmin(PostgreSQL 的图形化管理工具)通常有两种方式:

  1. pgAdmin 桌面版(不推荐在服务器上跑)
  2. ✅ pgAdmin 4 Web 版(推荐在 CentOS 上使用)

下面重点讲 pgAdmin 4 Web 模式在 CentOS 上的安装与使用。


一、前提条件

  • CentOS 7 / 8 / Stream
  • 已安装 PostgreSQL(如未安装可先装)
  • 有 sudo / root 权限

二、安装 pgAdmin 4(Web 版)

1. 添加 pgAdmin 官方仓库

sudo rpm -i https://ftp.postgresql.org/pub/pgadmin/pgadmin4/yum/pgadmin4-redhat-repo-2-1.noarch.rpm

2. 安装 pgAdmin 4(Web 模式)

sudo yum install -y pgadmin4-web

如果 CentOS 8+ 用 dnf:

sudo dnf install -y pgadmin4-web

三、初始化 pgAdmin

sudo /usr/pgadmin4/bin/setup-web.sh

执行时会让你:

  • 设置 pgAdmin 登录邮箱(管理员账号)
  • 设置密码
  • 是否配置 Apache(选 yes)

完成后会自动配置 Apache。


四、启动并访问 pgAdmin

1. 启动 Apache

sudo systemctl start httpd
sudo systemctl enable httpd

2. 防火墙放行

sudo firewall-cmd --add-service=http --permanent
sudo firewall-cmd --reload

3. 浏览器访问

http://服务器IP/pgadmin4

使用刚才设置的邮箱和密码登录。


五、连接 PostgreSQL

  1. 登录 pgAdmin
  2. 点击 Add New Server
  3. 填写:
    • General → Name(随便起)
    • Connection:
      • Host:localhost 或 IP
      • Port:5432
      • Username:postgres
      • Password:数据库密码

⚠️ 注意:

  • PostgreSQL 默认只允许本地连接
  • 若远程连接,需修改:
    • postgresql.conf
    • pg_hba.conf

六、常见问题

1. 页面打不开

检查:

systemctl status httpd
journalctl -xe

2. 登录后空白

sudo chown -R apache:apache /var/lib/pgadmin
sudo chown -R apache:apache /var/log/pgadmin

3. 忘记密码

sudo /usr/pgadmin4/bin/pgadmin4-cli重置

七、不推荐的方式(了解即可)

  • pgAdmin 桌面版依赖 GUI,CentOS 服务器一般无桌面
  • 可用 X11 转发,但麻烦且不稳定

如果你愿意,可以告诉我:

  • CentOS 版本
  • 是否已有 PostgreSQL
  • 是否本地或远程访问

我可以给你更精确的一步到位命令。

0 踩