3
Database:PostgreSQL
Jeffery edited this page 2026-06-11 10:03:47 +08:00

簡介

PostgreSQL 是常用的開源關聯式資料庫。本文記錄在 Ubuntu 上安裝 PostgreSQL,並開放特定主機與使用者外部連線的步驟。

安裝 PostgreSQL

apt update && apt install -y postgresql

允許外部連線

編輯用戶端認證設定檔 pg_hba.conf(路徑中的 17 為 PostgreSQL 主版本號,請依實際版本調整)。

nano /etc/postgresql/17/main/pg_hba.conf

加入下列規則,允許來自 192.168.230.221 網段的 gitea 使用者,以 md5 密碼驗證存取 gitea 資料庫。

...
host    gitea           gitea           192.168.230.221/24      md5

注意:另需確認 postgresql.conflisten_addresses 已開放對應介面(例如設為 '*'),外部連線才會生效。

重啟服務

讓設定生效並檢視狀態。

systemctl restart postgresql && systemctl status postgresql