暂无图片
暂无图片
暂无图片
暂无图片
暂无图片
PostgreSQL12主备切换
1471
6页
17次
2019-12-27
5墨值下载
本文通过单机不同端口实例模拟异步流复制主备切换过程,先搭建主备,再做切换,最后再切换回
来。
第一次主(5555)备(5556)
第二次主(5556)备(5555)
第三次主(5555)备(5556)
注意:主备的postgresql.conf文件不必非要一样,单机如果配置归档或者WAL路径一样的话会存
在问题。
1.初始化数据目录并启动主库
1 $initdbDdata5555UpostgresW
2
3 $vidata5555/postgresql.conf
4 port=5555
5 wal_level=replica
6 archive_mode=on
7 archive_command='cp%p/opt/archive5555/%f'
8 max_wal_senders=10
9 wal_keep_segments=512
10 hot_standby=on
11 primary_conninfo='host=127.0.0.1port=5556user=repuser'
12 #restore_command='cp/opt/archive5555/%f%p'
13
14 $pg_ctlDdata5555start&
2.插入数据
1 $psqlp5555Upostgres
2 createuserrepuserreplicationloginconnectionlimit5encryptedpasswo
rd'123456';
3 createtablet(idint,infotext);
4 insertintotvalues(1,now());
5 insertintotvalues(2,now());
3.基础备份恢复出备库5556
1 $pg_basebackupD/opt/data5556FpXsvPh127.0.0.1p5555Urepus
er
4.恢复备份
1 $vidata5556/postgresql.conf
2 port=5556
3 wal_level=replica
4 archive_mode=on
5 archive_command='cp%p/opt/archive5556/%f'
6 max_wal_senders=10
7 wal_keep_segments=512
8 hot_standby=on
9 primary_conninfo='host=127.0.0.1port=5555user=repuser'
10 #restore_command='cp/opt/archive5556/%f%p'
11
12 $touchdata5556/standby.signal
13
14 $pg_ctlDdata5556start&
5.查看主备进程
1 $psfupostgres
2 PIDTTYSTATTIMECOMMAND
3 4450pts/0S+0:00bash
4 1639pts/2S0:00bash
5 4850pts/2R+0:00\_psfupostgres
6 1380pts/1S+0:01bash
7 4838?Ss0:00/opt/pg12/bin/postgresDdata5556
8 4839?Ss0:00\_postgres:startuprecovering000000010000000000000005
9 4840?Ss0:00\_postgres:checkpointer
10 4841?Ss0:00\_postgres:backgroundwriter
11 4842?Ss0:00\_postgres:statscollector
12 4843?Ss0:00\_postgres:walreceiverstreaming0/5000060
13 4713?Ss0:00/opt/pg12/bin/postgresDdata5555
14 4715?Ss0:00\_postgres:checkpointer
15 4716?Ss0:00\_postgres:backgroundwriter
16 4717?Ss0:00\_postgres:walwriter
17 4718?Ss0:00\_postgres:autovacuumlauncher
18 4719?Ss0:00\_postgres:archiverlastwas000000010000000000000004.
00000028.backup
19 4720?Ss0:00\_postgres:statscollector
20 4721?Ss0:00\_postgres:logicalreplicationlauncher
21 4844?Ss0:00\_postgres:walsenderrepuser127.0.0.1(32224)streamin
g0/5000060
可以看到5555端口启动了walsender,5556启动了walreceiver
of 6
5墨值下载
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文档的来源(墨天轮),文档链接,文档作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论

关注
最新上传
暂无内容,敬请期待...
下载排行榜
Top250 周榜 月榜