以下是在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
语句赋予权限。