在 Linux 上通过 pgAdmin 远程访问 PostgreSQL,一般分为两种情况:
postgresql.conf找到配置文件(常见路径):
sudo vim /etc/postgresql/15/main/postgresql.conf
修改或确认:
listen_addresses = '*'
如果是源码安装,路径可能是
/usr/local/pgsql/data/postgresql.conf
pg_hba.confsudo vim /etc/postgresql/15/main/pg_hba.conf
添加允许远程连接(示例允许所有 IP):
host all all 0.0.0.0/0 md5
或更安全一点:
host all all 192.168.1.0/24 md5
sudo systemctl restart postgresql
sudo ufw allow 5432/tcp
# 或
sudo firewall-cmd --add-port=5432/tcp --permanent
sudo firewall-cmd --reload
如果是云服务器,还要在 安全组 放行 5432 端口。
sudo apt install pgadmin4-web
sudo /usr/pgadmin4/bin/setup-web.sh
http://服务器IP:80
localhost 或 127.0.0.15432pg_hba.conf 没配置localhost 而不是服务器 IPpsql -h 服务器IP -U 用户名 -d 数据库名
如果你能说明:
我可以给你更精确的配置步骤。