要在Ubuntu上使用PgAdmin連接數據庫,請按照以下步驟操作:
sudo apt update
sudo apt install postgresql pgadmin4
sudo systemctl start postgresql
sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD 'your_password';"
配置Web服務器:確保已經安裝并配置了Web服務器(如Nginx)以托管pgAdmin,并生成SSL證書以提高安全性。
啟用遠程連接:
/etc/postgresql/12/main/pg_hba.conf
(版本號可能會有所不同,請根據實際情況調整)。host all all 0.0.0.0/0 md5
sudo systemctl restart postgresql
pgadmin4
在PgAdmin的左側面板中,右鍵單擊“Servers”并選擇“Create” - “Server…”。
在“General”選項卡中,輸入一個名稱(例如,“My PostgreSQL Server”)。
轉到“Connection”選項卡,輸入以下信息:
Host name: localhost
Port: 5432(默認PostgreSQL端口)
Username: postgres
Password: your_password(在之前設置的密碼)
單擊“Save”以保存設置并連接到PostgreSQL服務器。
請注意,以上步驟假設您已經在Ubuntu系統上安裝并配置了PostgreSQL數據庫。如果您的數據庫位于遠程服務器上,請確保遠程服務器的防火墻允許從您的IP地址進行連接,并且您已經在遠程服務器上配置了相應的數據庫用戶和權限。