下面以 Debian 11 / 12 为例,介绍几种常见方式来配置 pgAdmin(PostgreSQL 的图形管理工具)。
pgAdmin 有两种常见形态:
服务器环境推荐使用 Web 模式。
sudo apt update
sudo apt install -y curl ca-certificates gnupg lsb-release
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 -y pgadmin4-web
sudo /usr/pgadmin4/bin/setup-web.sh
按提示:
安装完成后,pgAdmin 会自动配置 Apache:
http://<服务器IP>/pgadmin4
如果 Apache 未启动:
sudo systemctl enable apache2
sudo systemctl start apache2
如果你想不用 /pgadmin4 路径,而是用独立端口(如 8080):
编辑配置文件:
sudo nano /etc/pgadmin4/config_local.py
添加:
SERVER_MODE = True
DEFAULT_SERVER = '0.0.0.0'
DEFAULT_SERVER_PORT = 8080
重启服务:
sudo systemctl restart apache2
访问:
http://<IP>:8080
localhost 或数据库 IP5432postgres若 PostgreSQL 不在本机,请确保:
postgresql.conf中listen_addresses = '*'pg_hba.conf允许远程连接
sudo systemctl status apache2
sudo journalctl -xe
sudo /usr/pgadmin4/venv/bin/python /usr/pgadmin4/web/setup.py
DEFAULT_SERVER = '127.0.0.1'
然后通过 SSH 端口转发访问。
如果你告诉我:
我可以给你更精确的配置方案。