在 Linux 上用 pgAdmin 连接 PostgreSQL,一般分 pgAdmin 安装 → 数据库准备 → 建立连接 三步。下面按最常见场景说明(pgAdmin 4 + PostgreSQL)。
sudo systemctl status postgresql
如果没启动:
sudo systemctl start postgresql
pg_hba.conf路径一般在:
/var/lib/pgsql/15/data/pg_hba.conf
# 或
/etc/postgresql/15/main/pg_hba.conf
确保有类似这一行(允许本地连接):
local all all md5
# 或
host all all 127.0.0.1/32 md5
修改后重启:
sudo systemctl restart postgresql
sudo -u postgres psql
ALTER USER postgres PASSWORD 'your_password';
\q
sudo apt update
sudo apt install pgadmin4
浏览器访问:
http://127.0.0.1/pgadmin4
python3 -m venv pgadmin
source pgadmin/bin/activate
pip install pgadmin4
pgadmin4
浏览器访问:
http://127.0.0.1:5050
(端口可能不同)
local-db)localhost 或 127.0.0.15432postgrespostgres| 问题 | 解决方法 |
|---|---|
| password authentication failed | 用户名/密码错误 |
| could not connect | PostgreSQL 没启动 |
| timeout | 防火墙 / 端口不对 |
| FATAL: role does not exist | 用户不存在 |
postgresql.conflisten_addresses = '*'
pg_hba.confhost all all 0.0.0.0/0 md5
sudo ufw allow 5432
如果你愿意,可以告诉我:
我可以给你 精确到命令级别 的教程。