postgresql13主从搭建

1、安装好网络源(主1.11、从1.12)

yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

 

2、安装postgresql(主、从)

yum -y install postgresql13 
yum -y install postgresql13-server

 

3、创建数据目录(主、从)

mkdir /postgres_data

 

4、修改systemd管理启动脚本(主)

vim /usr/lib/systemd/system/postgresql-13.service

将PGDATA修改为创建的数据目录

 

5、修改数据目录属组(主、从)

chown postgres:postgres  /postgtes_data

 

6、初始化数据库(主)

su - postgres
/usr/pgsql-13/bin/initdb -D /postgres_data

 

7、修改配置文件(主)

vim /postgres_data/postgresql.conf
    #修改以下配置信息
    listen_addresses = '*' 
    port = 5432
    max_connections = 100 
    max_wal_size = 1GB
    min_wal_size = 80MB
    log_timezone = 'Asia/Shanghai'
    wal_level = replica
    max_wal_senders = 10
    wal_sender_timeout = 60s
    hot_standby = on
vim
/postgres_data/pg_hba.conf #添加以下配置 host all all 0.0.0.0/0 md5 host replication replica 192.168.1.12/32 md5

 

8、重启数据库(主)

systemctl restart postgresql-13

 

9、修改postgres用户密码,创建主从复制用户(主)

su - postgres
psql
postgres=# ALTER USER postgres ENCRYPTED PASSWORD '123456';
postgres=# create user replica replication login connection limit 3 encrypted password '123456';

 

10、执行主库基础备份(从)

su - postgres
/usr/pgsql-13/bin/pg_basebackup -h 192.168.1.11 -p 5432 -U replica -P -X stream -D /postgres_data -R

 

11、启动备库(从)

su - postgres
/usr/pgsql-13/bin/pg_ctl -D /postgres_data start 

 

posted @ 2022-10-23 23:05  难止汗  阅读(710)  评论(0编辑  收藏  举报