欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 明星 > Centos7安装PostgreSQL

Centos7安装PostgreSQL

2024/10/23 23:22:50 来源:https://blog.csdn.net/m0_37978198/article/details/141826868  浏览:    关键词:Centos7安装PostgreSQL

安装PostgreSQL

  1. 添加PostgreSQL的官方Yum仓库
# 添加PostgreSQL的官方Yum仓库:
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
  1. 安装PostgreSQL 14
# 安装PostgreSQL 14:
sudo yum install -y postgresql14-server
  1. 初始化数据库并启用自动启动
# 初始化 PostgreSQL
sudo /usr/pgsql-14/bin/postgresql-14-setup initdb;
# 设置开机启动
sudo systemctl enable postgresql-14;
# 启动 PostgreSQL
sudo systemctl start postgresql-14;

PostgreSQL配置

  1. 修改PostgreSQL配置文件
sudo vi /var/lib/pgsql/14/data/postgresql.conf

将listen_addresses改为*'以监听所有接口,如果是内网访问可以指定具体的IP地址。

在这里插入图片描述

  1. 修改pg_hba.conf文件以允许远程连接
sudo vi /var/lib/pgsql/14/data/pg_hba.conf

添加以下行以允许远程连接(替换0.0.0.0/0为你的具体IP范围):

host    all             all             0.0.0.0/0            md5

在这里插入图片描述

防火墙设置

默认端口:5432

sudo firewall-cmd --permanent --add-port=5432/tcp;
sudo firewall-cmd --reload;

创建用户

账号:root, 密码:123456

# 使用postgres用户
su postgres
# 进入pgsql
psql
# 创建超级管理用户,并赋予远程登录权限
create user root with superuser login password '123456';
# 查看所有用户
\du

在这里插入图片描述

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com