PostgreSQL 是常用的開源關聯式資料庫。本文記錄在 Ubuntu 上安裝 PostgreSQL,並開放特定主機與使用者外部連線的步驟。
apt update && apt install -y postgresql
編輯用戶端認證設定檔 pg_hba.conf(路徑中的 17 為 PostgreSQL 主版本號,請依實際版本調整)。
pg_hba.conf
17
nano /etc/postgresql/17/main/pg_hba.conf
加入下列規則,允許來自 192.168.230.221 網段的 gitea 使用者,以 md5 密碼驗證存取 gitea 資料庫。
192.168.230.221
gitea
... host gitea gitea 192.168.230.221/24 md5
注意:另需確認 postgresql.conf 的 listen_addresses 已開放對應介面(例如設為 '*'),外部連線才會生效。
postgresql.conf
listen_addresses
'*'
讓設定生效並檢視狀態。
systemctl restart postgresql && systemctl status postgresql
Deleting the wiki page "Database:PostgreSQL" cannot be undone. Continue?