温馨提示×

centos pgadmin怎么用

小樊
45
2026-10-03 05:40:29
栏目: 智能运维

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

  1. pgAdmin 网页版(pgAdmin 4,推荐服务器使用)
  2. pgAdmin 桌面版(较少在服务器上用)

下面我按 CentOS 7 / 8 / Stream 常见场景,给你一份实操指南。


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

1. 添加 pgAdmin 官方仓库

sudo dnf install -y https://ftp.postgresql.org/pub/pgadmin/pgadmin4/yum/pgadmin4-redhat-repo-1-1.noarch.rpm

(CentOS 7 用 yum 替代 dnf)


2. 安装 pgAdmin 4

sudo dnf install -y pgadmin4-web

3. 初始化 pgAdmin

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

过程中会让你:

  • 设置 pgAdmin 登录邮箱
  • 设置密码
  • 配置 Apache(自动完成)

4. 启动并开机自启

sudo systemctl enable httpd
sudo systemctl start httpd

5. 访问 pgAdmin

浏览器打开:

http://服务器IP/pgadmin4

登录你刚才设置的邮箱和密码即可。


二、连接 PostgreSQL 数据库

1. 确保 PostgreSQL 已安装并运行

systemctl status postgresql

2. 修改 PostgreSQL 允许连接(如需要)

编辑:

/var/lib/pgsql/data/postgresql.conf
listen_addresses = '*'

编辑:

/var/lib/pgsql/data/pg_hba.conf

添加:

host    all    all    0.0.0.0/0    md5

重启:

systemctl restart postgresql

3. 在 pgAdmin 中添加服务器

  1. 登录 pgAdmin
  2. 左侧 Servers → Add New Server
  3. 填写:
    • Name:自定义
    • Host:localhost 或 IP
    • Port:5432
    • Username:postgres
    • Password:数据库密码

三、常见问题

❌ 页面打不开

  • 防火墙:
firewall-cmd --add-service=http --permanent
firewall-cmd --reload
  • SELinux:
setsebool -P httpd_can_network_connect 1

❌ 登录 postgres 失败

先本地测试:

psql -U postgres

四、如果你只是本地开发

你也可以在 Windows / macOS 上安装 pgAdmin,直接连接 CentOS 上的 PostgreSQL,不需要在服务器装 pgAdmin。


如果你告诉我:

  • CentOS 版本
  • PostgreSQL 是否已安装
  • 是本地还是远程使用

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

0 踩