以下是在Ubuntu中配置PostgreSQL的步驟:
sudo apt update
和sudo apt upgrade
,確保系統軟件包最新。sudo apt install postgresql postgresql-contrib
安裝,postgresql-contrib
包含額外功能模塊,可根據需要選擇安裝。sudo systemctl status postgresql
檢查狀態,若未啟動則用sudo systemctl start postgresql
啟動,再用sudo systemctl enable postgresql
設置開機自啟。/etc/postgresql/<版本>/main/postgresql.conf
,將listen_addresses
設為'*'
;編輯/etc/postgresql/<版本>/main/pg_hba.conf
,添加如host all all 0.0.0.0/0 scram-sha-256
的規則,然后重啟服務sudo systemctl restart postgresql
。postgres
用戶sudo -i -u postgres
,使用createuser --interactive
創建新用戶,用createdb
創建數據庫,再通過GRANT
語句賦予權限。