下面分 Ubuntu 系统环境 和 PgAdmin 版本 给你一个完整、实用的配置说明。目前主流是 PgAdmin 4(Web 版),我重点讲这个,最后也会简单提旧版 PgAdmin 3。
sudo apt update
sudo apt install pgadmin4
安装完成后,系统会自动配置好 Web 服务。
sudo /usr/pgadmin4/bin/setup-web.sh
会提示你输入:
示例:
Email: admin@example.com
Password: ********
sudo systemctl restart apache2
PgAdmin 4 是通过 Apache + WSGI 运行的。
浏览器访问:
http://localhost/pgadmin4
或服务器 IP:
http://<服务器IP>/pgadmin4
使用刚才设置的 Email + Password 登录。
local-db)| 参数 | 说明 |
|---|---|
| Host name/address | localhost 或数据库 IP |
| Port | 5432 |
| Maintenance database | postgres |
| Username | PostgreSQL 用户名 |
| Password | 用户密码 |
| Save password | ✅ 勾选 |
点击 Save 即可。
错误示例:
FATAL: Peer authentication failed for user "postgres"
编辑 PostgreSQL 配置文件:
sudo nano /etc/postgresql/15/main/pg_hba.conf
找到:
local all all peer
改为:
local all all md5
然后重启:
sudo systemctl restart postgresql
1️⃣ 修改 postgresql.conf
sudo nano /etc/postgresql/15/main/postgresql.conf
listen_addresses = '*'
2️⃣ 修改 pg_hba.conf
追加:
host all all 0.0.0.0/0 md5
3️⃣ 重启 PostgreSQL
sudo systemctl restart postgresql
检查 Apache 状态:
sudo systemctl status apache2
检查端口:
sudo netstat -tlnp | grep 80
Ubuntu 20.04 以后 不再官方支持 PgAdmin 3,建议直接用 PgAdmin 4。
# 安装
sudo apt install pgadmin4
# 初始化
sudo /usr/pgadmin4/bin/setup-web.sh
# 重启服务
sudo systemctl restart apache2
# 访问
http://localhost/pgadmin4
如果你愿意,可以告诉我:
我可以给你 更精确的配置方案 ✅