环境:两个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;
最后修改时间:2024-07-11 08:05:09
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




