温馨提示×

ubuntu pgadmin怎样添加服务器

小樊
35
2026-10-03 18:25:57
栏目: 云计算

在 Ubuntu 上使用 pgAdmin 添加 PostgreSQL 服务器,通常有两种常见方式:pgAdmin 4(桌面/Web 版) 和 pgAdmin 3(较老)。目前主流是 pgAdmin 4。下面以 pgAdmin 4 为例说明。


一、准备工作(很重要)

在添加服务器前,请确保:

  1. PostgreSQL 已安装并运行
sudo systemctl status postgresql

如果没运行:

sudo systemctl start postgresql
  1. 知道数据库连接信息
  • 主机(Host):通常是 localhost
  • 端口(Port):默认 5432
  • 用户名:如 postgres
  • 密码:安装时设置的(若未设置可能需要配置)
  1. 允许本地连接(默认已允许) 检查:
sudo nano /etc/postgresql/*/main/pg_hba.conf

应有类似:

local   all   all   peer
host    all   all   127.0.0.1/32   md5

二、pgAdmin 4 添加服务器步骤

方式 A:pgAdmin 4 桌面版(或浏览器打开)

  1. 打开 pgAdmin 4

    • 桌面版直接启动
    • Web 版访问:http://127.0.0.1:5050
  2. 左侧 Browser 面板:

    • 右键 Servers
    • 选择 Register → Server…
  3. General(常规)

    • Name:随便写,如 Local PostgreSQL
  4. Connection(连接)

    • Host name/address:localhost
    • Port:5432
    • Maintenance database:postgres
    • Username:postgres
    • Password:你的密码
    • 勾选 Save password
  5. 点击 Save

✅ 成功后会看到服务器出现在左侧


三、常见问题

1. 提示“密码认证失败”

  • 确认密码正确
  • 或重置 postgres 密码:
sudo -u postgres psql
ALTER USER postgres PASSWORD '新密码';

2. 无法连接 localhost

  • 确认 PostgreSQL 正在运行
  • 检查防火墙(本地一般不会拦)

3. pgAdmin 打不开

重装或重启:

sudo apt install pgadmin4

四、命令行快速验证(可选)

psql -U postgres -h localhost

能进说明连接没问题。


如果你用的是 pgAdmin 3 或 Docker / 远程服务器,可以告诉我,我给你对应方案。

0 踩