centos7 install postgres-15 多实例

1.install 默认实例

参考:centos7 install postgres-15-CSDN博客

2.copy service

cp /usr/lib/systemd/system/postgresql-15.service   /usr/lib/systemd/system/postgresql-15-3.service

3.修改/usr/lib/systemd/system/postgresql-15-3.service

# Location of database directory
Environment=PGDATA=/var/lib/pgsql/15/data3/

 4.创建对应目录:

mkdir /var/lib/pgsql/15/data3/
chown postgres:postgres /var/lib/pgsql/15/data3/

5.初始化数据库


sudo /usr/pgsql-15/bin/postgresql-15-setup initdb postgresql-15-3

6.修改数据库配置

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


# 修改如下配置

#listen_addresses = 'localhost'         # what IP address(es) to listen on;
listen_addresses = '0.0.0.0'            # what IP address(es) to listen on;
                                        # comma-separated list of addresses;
                                        # defaults to 'localhost'; use '*' for all
                                        # (change requires restart)
#port = 5432                            # (change requires restart)
port = 5433                             # (change requires restart)

6.修改配置文件vi /var/lib/pgsql/15/data3/pg_hba.conf

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

# 修改端口
host    all             all             192.168.1.0/24         password

7.修改防火墙

firewall-cmd --zone=public --add-port=5433/tcp --permanent
配置生效
firewall-cmd --reload   # 配置立即生效

8.启动服务

sudo systemctl enable postgresql-15-3
sudo systemctl start postgresql-15-3

9.修改密码

 sudo -u postgres psql -p 5433 
 
psql (15.4)
Type "help" for help.
 
postgres=# ALTER USER postgres WITH PASSWORD 'xxxxxxxxxxx';
ALTER ROLE
postgres=# \q

完毕,可以连接新实例了

你可能感兴趣的:(运维,数据库,运维,linux,centos,postgresql)