在 Linux 下配置 pgAdmin(主要用于管理 PostgreSQL 数据库),常见有两种方式:pgAdmin 4(Web 模式,推荐) 和 pgAdmin 4 Desktop 模式。下面按最常见、最稳妥的方式一步一步说明。
sudo apt update
sudo apt install curl wget gnupg2
curl -fsSL https://www.pgadmin.org/static/packages_pgadmin_org.pub | sudo gpg --dearmor -o /usr/share/keyrings/pgadmin.gpg
echo "deb [signed-by=/usr/share/keyrings/pgadmin.gpg] https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/$(lsb_release -cs) pgadmin4 main" | sudo tee /etc/apt/sources.list.d/pgadmin4.list
sudo apt update
sudo apt install pgadmin4-web
sudo apt install pgadmin4-desktop
sudo /usr/pgadmin4/bin/setup-web.sh
会提示你:
✅ 记住这个账号,这是 pgAdmin 的登录账号,不是 PostgreSQL 的账号。
sudo systemctl restart apache2
访问地址:
http://localhost/pgadmin4
或:
http://服务器IP/pgadmin4
使用刚才设置的 邮箱 + 密码
local-db)127.0.0.1 或 PostgreSQL 服务器 IP5432postgrespostgressudo nano /etc/postgresql/版本/main/pg_hba.conf
确保有:
host all all 0.0.0.0/0 md5
sudo nano /etc/postgresql/版本/main/postgresql.conf
listen_addresses = '*'
重启 PostgreSQL:
sudo systemctl restart postgresql
sudo systemctl status apache2
sudo journalctl -xe
sudo -u postgres psql
CREATE USER youruser WITH PASSWORD 'yourpassword';
GRANT ALL PRIVILEGES ON DATABASE yourdb TO youruser;
如果你只是本地开发:
sudo apt install pgadmin4-desktop
pgadmin4
直接打开 GUI 界面,无需 Apache。
| 场景 | 推荐方式 |
|---|---|
| 服务器 | pgAdmin 4 Web |
| 本地开发 | pgAdmin 4 Desktop |
| 生产环境 | pgAdmin + Nginx + HTTPS |
如果你愿意,可以告诉我:
我可以给你完全针对你环境的配置命令。