重庆思庄Oracle、Redhat认证学习论坛

标题: postgres主从复制(流复制) [打印本页]

作者: mahan    时间: 2024-7-14 13:05
标题: postgres主从复制(流复制)
环境:两个pg14数据库

主库操作
1、创建复制账号
create user repl replication encrypted password 'replica' ;
2、修改pg_hba.conf
vim pg_hba.conf
host    replication     repl             0.0.0.0/0            scram-sha-256
3、修改postgresql.conf
vim postgresql.conf
wal_level = replica
4、重启数据库
systemctl restart postgresql
从库操作
1、关闭数据库进程
systemctl stop postgresql
2、当前基础数据做基础备份
mkdir pgsqldata
pg_basebackup -F -p -P -R -D pgsqldata -h xxx.xxx.xxx.xxx. -p 54321 -U repl -W
注:当前pgsqldata需为空目录,权限750

3、修改postgresql.conf
vim postgresql.conf
hot_standby = on
max_standby_streaming_delay = 30s
wal_receiver_status_interval = 10s
hot_standby_feedback=on
4、启动从数据库
systemctl start postgresql
检查是否同步
主库sql

select client_addr,sync_state from pg_stat_replication;





欢迎光临 重庆思庄Oracle、Redhat认证学习论坛 (http://bbs.cqsztech.com/) Powered by Discuz! X3.2