postgresql双机热备(流复制)及主备切换_windows postgre15如何双机热备

先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前阿里P7

深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年最新软件测试全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。
img
img
img
img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上软件测试知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

如果你需要这些资料,可以添加V获取:vip1024b (备注软件测试)
img

正文

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

RX packets:141173 errors:0 dropped:0 overruns:0 frame:0

TX packets:29124 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:198747523 (189.5 MiB) TX bytes:2168654 (2.0 MiB)

lo Link encap:Local Loopback

inet addr:127.0.0.1 Mask:255.0.0.0

inet6 addr: ::1/128 Scope:Host

UP LOOPBACK RUNNING MTU:16436 Metric:1

RX packets:636 errors:0 dropped:0 overruns:0 frame:0

TX packets:636 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:0

RX bytes:139280 (136.0 KiB) TX bytes:139280 (136.0 KiB)

利用ip地址漂移实现主备切换

切换前观察ip地址情况和数据库的主备情况

ip地址:主端

[root@node1 ~]# ifconfig

eth0 Link encap:Ethernet HWaddr 00:0C:29:EA:AF:6E

inet addr:192.168.11.68 Bcast:192.168.11.255 Mask:255.255.255.0

inet6 addr: fe80::20c:29ff:feea:af6e/64 Scope:Link

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

RX packets:29953 errors:0 dropped:0 overruns:0 frame:0

TX packets:141299 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:2174739 (2.0 MiB) TX bytes:198989432 (189.7 MiB)

eth0:1 Link encap:Ethernet HWaddr 00:0C:29:EA:AF:6E

inet addr:192.168.11.40 Bcast:192.168.11.255 Mask:255.255.255.0

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

lo Link encap:Local Loopback

inet addr:127.0.0.1 Mask:255.0.0.0

inet6 addr: ::1/128 Scope:Host

UP LOOPBACK RUNNING MTU:16436 Metric:1

RX packets:308 errors:0 dropped:0 overruns:0 frame:0

TX packets:308 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:0

RX bytes:55374 (54.0 KiB) TX bytes:55374 (54.0 KiB)

备端

[root@node2 ~]# ifconfig

eth0 Link encap:Ethernet HWaddr 00:0C:29:EA:AF:6E

inet addr:192.168.11.70 Bcast:192.168.11.255 Mask:255.255.255.0

inet6 addr: fe80::20c:29ff:feea:af6e/64 Scope:Link

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

RX packets:29953 errors:0 dropped:0 overruns:0 frame:0

TX packets:141299 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:2174739 (2.0 MiB) TX bytes:198989432 (189.7 MiB)

lo Link encap:Local Loopback

inet addr:127.0.0.1 Mask:255.0.0.0

inet6 addr: ::1/128 Scope:Host

UP LOOPBACK RUNNING MTU:16436 Metric:1

RX packets:308 errors:0 dropped:0 overruns:0 frame:0

TX packets:308 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:0

RX bytes:55374 (54.0 KiB) TX bytes:55374 (54.0 KiB)

数据库情况

主端

[postgres@node1 ~]$ pg_controldata

pg_control version number: 922

Catalog version number: 201204301

Database system identifier: 6377220794669856238

Database cluster state:
in production

pg_control last modified: Mon 23 Jan 2017 09:13:29 AM CST

Latest checkpoint location: 0/12015CD0

Prior checkpoint location: 0/12015C70

Latest checkpoint’s REDO location: 0/12015CD0

Latest checkpoint’s TimeLineID: 2

Latest checkpoint’s full_page_writes: on

Latest checkpoint’s NextXID: 0/1822

Latest checkpoint’s NextOID: 16397

Latest checkpoint’s NextMultiXactId: 1

Latest checkpoint’s NextMultiOffset: 0

Latest checkpoint’s oldestXID: 1802

Latest checkpoint’s oldestXID’s DB: 1

Latest checkpoint’s oldestActiveXID: 0

Time of latest checkpoint: Mon 23 Jan 2017 09:11:41 AM CST

Minimum recovery ending location: 0/0

Backup start location: 0/0

Backup end location: 0/0

End-of-backup record required: no

Current wal_level setting: hot_standby

Current max_connections setting: 100

Current max_prepared_xacts setting: 0

Current max_locks_per_xact setting: 64

Maximum data alignment: 8

Database block size: 8192

Blocks per segment of large relation: 131072

WAL block size: 8192

Bytes per WAL segment: 16777216

Maximum length of identifiers: 64

Maximum columns in an index: 32

Maximum size of a TOAST chunk: 1996

Date/time type storage: 64-bit integers

Float4 argument passing: by value

Float8 argument passing: by value

[postgres@node2 ~]$ pg_controldata

pg_control version number: 922

Catalog version number: 201204301

Database system identifier: 6377220794669856238

Database cluster state:
in archive recovery

pg_control last modified: Mon 23 Jan 2017 09:13:09 AM CST

Latest checkpoint location: 0/12015D30

Prior checkpoint location: 0/12015C10

Latest checkpoint’s REDO location: 0/12015D30

Latest checkpoint’s TimeLineID: 3

Latest checkpoint’s full_page_writes: on

Latest checkpoint’s NextXID: 0/1822

Latest checkpoint’s NextOID: 16397

Latest checkpoint’s NextMultiXactId: 1

Latest checkpoint’s NextMultiOffset: 0

Latest checkpoint’s oldestXID: 1802

Latest checkpoint’s oldestXID’s DB: 1

Latest checkpoint’s oldestActiveXID: 0

Time of latest checkpoint: Mon 23 Jan 2017 09:13:09 AM CST

Minimum recovery ending location: 0/0

Backup start location: 0/0

Backup end location: 0/0

End-of-backup record required: no

Current wal_level setting: hot_standby

Current max_connections setting: 100

Current max_prepared_xacts setting: 0

Current max_locks_per_xact setting: 64

Maximum data alignment: 8

Database block size: 8192

Blocks per segment of large relation: 131072

WAL block size: 8192

Bytes per WAL segment: 16777216

Maximum length of identifiers: 64

Maximum columns in an index: 32

Maximum size of a TOAST chunk: 1996

Date/time type storage: 64-bit integers

Float4 argument passing: by value

Float8 argument passing: by value

备端情况

首先,关闭主库

[postgres@node1 data]$ pg_ctl stop -m fast

[root@node1 ~]# ifdown eth0:1

[root@node1 ~]# ifconfig

eth0 Link encap:Ethernet HWaddr 00:0C:29:EA:AF:6E

inet addr:192.168.11.68 Bcast:192.168.11.255 Mask:255.255.255.0

inet6 addr: fe80::20c:29ff:feea:af6e/64 Scope:Link

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

RX packets:30248 errors:0 dropped:0 overruns:0 frame:0

TX packets:141525 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:2199137 (2.0 MiB) TX bytes:199102358 (189.8 MiB)

lo Link encap:Local Loopback

inet addr:127.0.0.1 Mask:255.0.0.0

inet6 addr: ::1/128 Scope:Host

UP LOOPBACK RUNNING MTU:16436 Metric:1

RX packets:348 errors:0 dropped:0 overruns:0 frame:0

TX packets:348 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:0

RX bytes:60247 (58.8 KiB) TX bytes:60247 (58.8 KiB)

备库

[root@node2 ~]# ifup eth0:1

Active connection state: activating

Active connection path: /org/freedesktop/NetworkManager/ActiveConnection/1

state: activated

Connection activated

[root@node2 ~]# ifconfig

eth0 Link encap:Ethernet HWaddr 00:0C:29:EA:AF:6E

inet addr:192.168.11.70 Bcast:192.168.11.255 Mask:255.255.255.0

inet6 addr: fe80::20c:29ff:feea:af6e/64 Scope:Link

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

RX packets:29953 errors:0 dropped:0 overruns:0 frame:0

TX packets:141299 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:2174739 (2.0 MiB) TX bytes:198989432 (189.7 MiB)

eth0:1 Link encap:Ethernet HWaddr 00:0C:29:EA:AF:6E

inet addr:192.168.11.40 Bcast:192.168.11.255 Mask:255.255.255.0

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

lo Link encap:Local Loopback

inet addr:127.0.0.1 Mask:255.0.0.0

inet6 addr: ::1/128 Scope:Host

UP LOOPBACK RUNNING MTU:16436 Metric:1

RX packets:308 errors:0 dropped:0 overruns:0 frame:0

TX packets:308 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:0

RX bytes:55374 (54.0 KiB) TX bytes:55374 (54.0 KiB)

备库进行切换

[postgres@node2 ~]$ pg_ctl promote

server promoting

原备库状态

[highgo@node2 ~]$ pg_controldata

pg_control version number: 922

Catalog version number: 201204301

Database system identifier: 6377220794669856238

Database cluster state:
in production

pg_control last modified: Mon 23 Jan 2017 09:13:09 AM CST

Latest checkpoint location: 0/12015D30

Prior checkpoint location: 0/12015C10

Latest checkpoint’s REDO location: 0/12015D30

Latest checkpoint’s TimeLineID: 3

Latest checkpoint’s full_page_writes: on

Latest checkpoint’s NextXID: 0/1822

Latest checkpoint’s NextOID: 16397

Latest checkpoint’s NextMultiXactId: 1

Latest checkpoint’s NextMultiOffset: 0

Latest checkpoint’s oldestXID: 1802

Latest checkpoint’s oldestXID’s DB: 1

Latest checkpoint’s oldestActiveXID: 0

Time of latest checkpoint: Mon 23 Jan 2017 09:13:09 AM CST

Minimum recovery ending location: 0/0

Backup start location: 0/0

Backup end location: 0/0

End-of-backup record required: no

Current wal_level setting: hot_standby

Current max_connections setting: 100

Current max_prepared_xacts setting: 0

Current max_locks_per_xact setting: 64

Maximum data alignment: 8

Database block size: 8192

Blocks per segment of large relation: 131072

WAL block size: 8192

Bytes per WAL segment: 16777216

Maximum length of identifiers: 64

Maximum columns in an index: 32

Maximum size of a TOAST chunk: 1996

Date/time type storage: 64-bit integers

Float4 argument passing: by value

Float8 argument passing: by value

[postgres@node2 ~]$ ps -ef | grep postgres

postgres 2538 1 0 09:11 pts/0 00:00:00 /opt/pgsql/bin/postgres

postgres 2539 2538 0 09:11 ? 00:00:00 postgres: logger process

postgres 2541 2538 0 09:11 ? 00:00:00 postgres: checkpointer process

postgres 2542 2538 0 09:11 ? 00:00:00 postgres: writer process

postgres 2543 2538 0 09:11 ? 00:00:00 postgres: stats collector process

postgres 2625 2538 0 09:13 ? 00:00:00

postgres: wal writer process

postgres 2626 2538 0 09:13 ? 00:00:00 postgres: autovacuum launcher process

postgres 2432 2425 0 09:06 ? 00:00:00 postgres: stats collector process

postgrs 2435 2425 0 09:06 ? 00:00:00
postgres: archiver process last was 000000.4history

root 3348 1992 0 10:06 pts/0 00:00:00 su - postgres

postgres 3349 3348 0 10:06 pts/0 00:00:00 -bash

postgres 3395 3349 0 10:13 pts/0 00:00:00 ps -ef

postgres 3396 3349 0 10:13 pts/0 00:00:00 grep postgres

在原主库配置recovery.conf文件

[postgres@node1 data]$ vi recovery.conf

standby_mode=‘on’

recovery_target_timeline = ‘latest’

primary_conninfo=‘host=192.168.11.68 port=5866 user=standby password=standby’

trigger_file=‘opt/pgsql/trigger_node’

启动原主库

[postgres@node2 ~]$ pg_ctl start

[postgres@node2 ~]$ ps -ef | grep postgres

postgres 2169 1 0 09:04 pts/0 00:00:00 /opt/pgsql/bin/postgres

postgres 2170 2169 0 09:04 ? 00:00:00 postgres: logger process

postgres 2171 2169 0 09:04 ? 00:00:00 postgres: startup process waiting for 000000020000000000000012

postgres 2172 2169 0 09:04 ? 00:00:00 postgres: checkpointer process

postgres 2173 2169 0 09:04 ? 00:00:00 postgres: writer process

postgres 2175 2169 0 09:04 ? 00:00:00 postgres: stats collector process

root 2241 1992 0 09:06 pts/0 00:00:00 su - postgres

postgres 2242 2241 0 09:06 pts/0 00:00:00 -bash

postgres 2283 2169 0 09:07 ? 00:00:00
postgres: wal receiver process

postgres 2288 2242 0 09:09 pts/0 00:00:00 ps -ef

postgres 2289 2242 0 09:09 pts/0 00:00:00 grep postgres

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以添加V获取:vip1024b (备注软件测试)
img

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
s 2171 2169 0 09:04 ? 00:00:00 postgres: startup process waiting for 000000020000000000000012

postgres 2172 2169 0 09:04 ? 00:00:00 postgres: checkpointer process

postgres 2173 2169 0 09:04 ? 00:00:00 postgres: writer process

postgres 2175 2169 0 09:04 ? 00:00:00 postgres: stats collector process

root 2241 1992 0 09:06 pts/0 00:00:00 su - postgres

postgres 2242 2241 0 09:06 pts/0 00:00:00 -bash

postgres 2283 2169 0 09:07 ? 00:00:00
postgres: wal receiver process

postgres 2288 2242 0 09:09 pts/0 00:00:00 ps -ef

postgres 2289 2242 0 09:09 pts/0 00:00:00 grep postgres

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以添加V获取:vip1024b (备注软件测试)
[外链图片转存中…(img-MlZaoG5i-1713343409497)]

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

  • 27
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值