2、yum安装postgres15.3

发布时间 2023-05-23 15:08:26作者: 站着说话不腰疼

yum安装postgres15.3

1、选择安装的版本1.53

参考官网文档:https://www.postgresql.org/download/linux/redhat/

1684467740044

2、创建postgres用户

root用户执行

groupadd -g 15432 postgres
useradd -u 15432 -g postgres postgres
passwd postgres

3、执行yum安装命令

/usr/pgsql-15/bin/postgresql-15-setup是安装postgres路径

initdb是初始化postgres数据库

systemctl enable是开机启动

systemctl start是启动postgres

执行命令如下:

# Install the repository RPM:
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

# Install PostgreSQL:
sudo yum install -y postgresql15-server

# Optionally initialize the database and enable automatic start:
sudo /usr/pgsql-15/bin/postgresql-15-setup initdb
sudo systemctl enable postgresql-15
sudo systemctl start postgresql-15

系统会默认创建用户postgres,密码为空

sudo -i -u postgres

执行psql

[postgres@dbServer42 ~]$ psql
psql (15.3)
Type "help" for help.

postgres=# 

说明安装成功。

4、修改配置文件

关闭服务:

sudo systemctl stop postgresql-15

4.1、修改postgresql.conf

vi /var/lib/pgsql/15/data/postgresql.conf

修改配置如下:

/+关键字查询

listen_addresses = '*'
port = 5432
max_connections = 1000
password_encryption = scram-sha-256
log_directory = '/u01/pgdata/log'

:wq保存

4.2、修改pg_hba.conf

vi /var/lib/pgsql/15/data/pg_hba.conf

修改配置如下:

增加0.0.0.0/0 开发对应ip的权限

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             127.0.0.1/32            scram-sha-256
host    all             all             0.0.0.0/0               scram-sha-256
# IPv6 local connections:
host    all             all             ::1/128                 scram-sha-256
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     peer
host    replication     all             127.0.0.1/32            scram-sha-256
host    replication     all             ::1/128                 scram-sha-256
host    replication     all             0.0.0.0/0               scram-sha-256