在 Ubuntu 上使用 pgAdmin 连接 PostgreSQL 数据库,一般分两种情况:连接本地 PostgreSQL 和 连接远程 PostgreSQL。下面按常见步骤说明。
sudo apt update
sudo apt install pgadmin4 pgadmin4-web
安装完成后初始化:
sudo /usr/pgadmin4/bin/setup-web.sh
按提示设置登录邮箱和密码。
启动 Apache:
sudo systemctl restart apache2
浏览器访问:
http://localhost/pgadmin4
sudo apt install pgadmin4-desktop
直接从应用菜单打开 pgAdmin。
sudo systemctl status postgresql
若未启动:
sudo systemctl start postgresql
localdb)localhost5432postgrespostgres⚠️ 如果不知道 postgres 密码:
sudo -u postgres psql
\password postgres
在远程服务器上修改:
postgresql.conf
listen_addresses = '*'
pg_hba.conf
host all all 0.0.0.0/0 md5
重启 PostgreSQL:
sudo systemctl restart postgresql
sudo ufw allow 5432
connection refused → PostgreSQL 没启动或只监听 localhostpassword authentication failed → 用户名或密码错误如果你愿意,可以告诉我:
我可以一步步帮你排错。