在 Linux 上使用 pgAdmin 进行 SQL 查询的完整步骤
一 安装与启动 pgAdmin
sudo apt update && sudo apt install postgresql pgadmin4pgadmin4(首次会设置主密码)sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpmsudo dnf install -y pgadmin4/etc/httpd/conf.d/pgadmin4.conf,设置 DocumentRoot /usr/pgadmin4/web 与目录权限,然后 sudo systemctl restart httpd && sudo systemctl enable httpddocker run -p 680:80 -e 'PGADMIN_DEFAULT_EMAIL=admin@example.com' -e 'PGADMIN_DEFAULT_PASSWORD=StrongPass!' -d dpage/pgadmin4,浏览器访问 http://服务器IP:680。二 连接到 PostgreSQL 服务器
三 执行 SQL 查询
SELECT * FROM mytable;SELECT id, name FROM mytable WHERE age > 30;SELECT dept, COUNT(*) AS cnt FROM mytable GROUP BY dept HAVING COUNT(*) > 1;四 常见问题与排查
postgresql.conf 的 listen_addresses 与端口;在 pg_hba.conf 为客户端网段添加允许规则,例如:host all all 192.168.1.0/24 md5,然后重启数据库pg_hba.conf 添加如 host all all 0.0.0.0/0 md5(仅测试环境建议),并重启数据库;生产环境请限制为可信网段pgadmin4 并在浏览器打开正确端口。