在 Ubuntu 下安装 pgAdmin(PostgreSQL 的图形化管理工具)常见有三种方式,最推荐的是 APT 安装 pgAdmin 4(Web 模式)。下面按常用程度给你详细说明。
适用于 Ubuntu 20.04 / 22.04 / 24.04。
pgAdmin 通常与 PostgreSQL 官方源一起使用,版本更新。
sudo apt update
sudo apt install curl ca-certificates gnupg -y
导入 PostgreSQL 官方 GPG 密钥:
curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | sudo tee /usr/share/keyrings/postgresql-keyring.gpg > /dev/null
添加仓库(以 Ubuntu 22.04 为例):
echo "deb [signed-by=/usr/share/keyrings/postgresql-keyring.gpg] http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list
更新软件源:
sudo apt update
sudo apt install pgadmin4 -y
安装完成后,系统会提供 Web 模式 的 pgAdmin。
sudo /usr/pgadmin4/bin/setup-web.sh
按提示操作:
在浏览器中访问:
http://localhost/pgadmin4
或:
http://127.0.0.1/pgadmin4
✅ 输入刚才设置的邮箱和密码即可登录。
适合开发环境,但配置复杂。
sudo apt install python3 python3-pip python3-venv -y
python3 -m venv pgadmin4
source pgadmin4/bin/activate
pip install pgadmin4
然后手动运行:
pgadmin4
⚠️ 不推荐生产环境使用。
如果你已安装 Docker:
docker run -d \
--name pgadmin \
-p 5050:80 \
-e PGADMIN_DEFAULT_EMAIL=admin@admin.com \
-e PGADMIN_DEFAULT_PASSWORD=admin \
dpage/pgadmin4
访问:
http://localhost:5050
在 pgAdmin 中:
localhost5432postgressudo systemctl restart apache2
重新运行:
sudo /usr/pgadmin4/bin/setup-web.sh
| 场景 | 推荐方式 |
|---|---|
| 本地 / 桌面 | APT 安装 |
| 服务器 | Docker |
| 开发测试 | Docker / pip |
如果你愿意,可以告诉我:
我可以给你 最合适的一套安装命令 ✅