ubuntu

PostgreSQL在Ubuntu上如何配置

小樊
45
2025-08-28 00:15:26
栏目: 云计算

以下是在Ubuntu上配置PostgreSQL的步骤:

  1. 更新系统sudo apt update && sudo apt upgrade -y
  2. 安装PostgreSQLsudo apt install postgresql postgresql-contrib -y
  3. 启动服务:安装后服务通常自动启动,可用sudo systemctl status postgresql查看状态,未启动则用sudo systemctl start postgresql启动,设置开机自启用sudo systemctl enable postgresql
  4. 登录数据库sudo -i -u postgres psql
  5. 修改默认用户密码:在psql中执行ALTER USER postgres WITH PASSWORD 'your_password';
  6. 创建新用户和数据库(可选):可参考文档使用命令创建。
  7. 配置远程访问(可选):编辑postgresql.conf,将listen_addresses改为'*';编辑pg_hba.conf,添加允许远程连接的规则,如host all all 0.0.0.0/0 md5,然后重启服务sudo systemctl restart postgresql
  8. 配置防火墙(若启用)sudo ufw allow 5432/tcpsudo ufw reload

0
看了该问题的人还看了