以下是在Ubuntu上配置PostgreSQL的步骤:
sudo apt update && sudo apt upgrade -y
。sudo apt install postgresql postgresql-contrib -y
。sudo systemctl status postgresql
查看状态,未启动则用sudo systemctl start postgresql
启动,设置开机自启用sudo systemctl enable postgresql
。sudo -i -u postgres psql
。ALTER USER postgres WITH PASSWORD 'your_password';
。postgresql.conf
,将listen_addresses
改为'*'
;编辑pg_hba.conf
,添加允许远程连接的规则,如host all all 0.0.0.0/0 md5
,然后重启服务sudo systemctl restart postgresql
。sudo ufw allow 5432/tcp
,sudo ufw reload
。