Linux CentOS 7 安装PostgreSQL14

  1. 安装rpm文件
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
  1. 安装PostgreSQL
sudo yum install -y  --nogpgcheck postgresql14-server
  1. 初始化数
sudo /usr/pgsql-14/bin/postgresql-14-setup initdb
  1. 设备开机启动
sudo systemctl enable postgresql-14
  1. 启动PostgreSQL服务
sudo systemctl start postgresql-14
  1. 设置数据库密码
  • 数据库安装后,默认创建账号postgres

  • 使用postgres账号身份操作

su - postgres
  • 使用postgres账号登录数据库
psql -U postgres
  • 设置密码
alter user postgres with password '123456'
  • 退出
\q    #退出数据库
exit  #退出postgres账号
  1. 开启远程访问
  • 对所有IP开放访问

  • 打开postgresql.conf文件

vi /var/lib/pgsql/14/data/postgresql.conf
  • 修改listen_address配置(对所有IP开发访问)
listen_address = '*'
  • 增加信任连接

  • 打开pg_hba.conf文件

vi /var/lib/pgsql/14/data/pg_hba.conf
  • 增加新人连接配置
# IPv4 local connections:
host    all             all             0.0.0.0/0               trust
  • 重启服务
systemctl restart postgresql-14
  1. 添加防火墙端口号
  • 添加端口号
firewall-cmd --zone=public --add-port=5432/tcp --permanent
  • 重载防火墙立即生效
firewall-cmd --reload
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容