检查PostgreSQL服务状态
确保服务已启动:
sudo systemctl status postgresql
若未运行,启动服务:
sudo systemctl start postgresql
检查pg_hba.conf配置
修改配置文件(路径:/etc/postgresql/<版本>/main/pg_hba.conf),添加允许远程连接的规则:
host all all 0.0.0.0/0 md5
重启服务使配置生效:
sudo systemctl restart postgresql
检查防火墙设置
允许PostgreSQL默认端口(5432)的流量:
sudo ufw allow 5432/tcp
sudo ufw reload
验证pgAdmin配置
确保连接参数(主机、端口、用户名、密码)正确,本地连接可尝试将主机设为localhost或127.0.0.1。
查看日志文件
分析PostgreSQL和pgAdmin的日志,定位具体错误:
sudo tail -f /var/log/postgresql/postgres.log
sudo tail -f /var/log/pgadmin/pgadmin4.log
处理权限与版本兼容性
psql命令行验证。其他高级操作
rm -rf ~/.pgadmin*
然后重启pgAdmin。