温馨提示×

centos下pgadmin怎么使用

小樊
42
2026-09-24 10:16:19
栏目: 智能运维

在 CentOS 下使用 pgAdmin,通常有两种方式:

  1. pgAdmin 4(Web 版,推荐)
  2. pgAdmin 桌面版(依赖图形界面,CentOS 服务器一般不推荐)

下面重点讲 CentOS 服务器上常用的 pgAdmin 4 Web 方式。


一、在 CentOS 上安装 pgAdmin 4(Web 模式)

1. 添加 PostgreSQL 官方仓库

sudo dnf install -y https://download.postgresql.org/pub/repos/yum/repo/pgdg-redhat-repo-latest.noarch.rpm

(CentOS 7 用 yum,CentOS 8/Stream 用 dnf)


2. 安装 pgAdmin 4(Web 版)

sudo dnf install -y pgadmin4-web

3. 初始化 pgAdmin

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

会提示你:

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

4. 启动服务

sudo systemctl restart httpd
sudo systemctl enable httpd

(pgAdmin 4 默认通过 Apache 提供 Web 服务)


二、访问 pgAdmin

在浏览器中打开:

http://服务器IP/pgadmin4

例如:

http://192.168.1.100/pgadmin4

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


三、连接 PostgreSQL 数据库

  1. 登录 pgAdmin
  2. 左侧 Servers → Add New Server
  3. 填写:
    • General
      • Name:自定义(如 local-pg)
    • Connection
      • Host:127.0.0.1 或数据库 IP
      • Port:5432
      • Username:postgres
      • Password:数据库密码
  4. 保存

四、常见问题

1. 页面打不开

检查:

sudo systemctl status httpd
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --reload

2. 无法连接数据库

  • PostgreSQL 是否启动:
systemctl status postgresql
  • postgresql.conf 中:
listen_addresses = '*'
  • pg_hba.conf 允许访问

3. 想用桌面版(不推荐服务器)

仅适合有 GUI 的 CentOS:

sudo dnf install pgadmin4

然后命令行启动:

pgadmin4

五、总结建议

✅ 服务器环境:pgAdmin 4 Web
✅ 本地开发:桌面版或 Windows / macOS 客户端
✅ 生产环境:建议限制 IP + HTTPS

如果你告诉我:

  • CentOS 版本
  • PostgreSQL 是否已安装
  • 是否是云服务器

我可以给你更精确的步骤。

0 踩