当前位置:网站首页>PostgresSQL 流复制 主备切换 主库无读写宕机场景
PostgresSQL 流复制 主备切换 主库无读写宕机场景
2022-07-02 12:13:00 【六位元素】
目录
一 场景介绍
PostgreSQL 流复制主备环境,主库并无读写,数据库宕机,原备库切换为主库,原主库切换为备库。主库宕机方式有smart、fast、immediate,基于这三种方式的主库宕机,主备如何切换。
二 基础环境
主库:192.168.5.128
备库:192.168.5.129
三 状态检查
1.主备状态检查
pg_controldata -D /data/dbdata/pgsql/14/5432/data/
128:Database cluster state: in production
129:Database cluster state: in archive recovery2.流复制同步情况检查
select * from pg_stat_replication;
四 主备切换
1.主库宕机
# 128主机模拟数据库关闭
pg_ctl -D /data/dbdata/pgsql/14/5432/data stop -m smart2.主备切换
# 129主机切换为主库
pg_ctl promote -D /data/dbdata/pgsql/14/5432/data3.原主库调整为备库
# 128主机切换为备库
touch /data/dbdata/pgsql/14/5432/data/standby.signal
echo "primary_conninfo = 'host=192.168.5.129 port=5432 user=repl password=repl'" >> /data/dbdata/pgsql/14/5432/data/postgresql.conf
pg_ctl -D /data/dbdata/pgsql/14/5432/data start4.主备状态检查
pg_controldata -D /data/dbdata/pgsql/14/5432/data/
128:Database cluster state: in archive recovery
129:Database cluster state: in production5.流复制同步情况检查
select * from pg_stat_replication;
6.数据验证
# 现主库129更新数据
pgbench=# select * from t1 where id=1;
id | t | mod_time
----+------+----------
1 | 测试 |
(1 row)
pgbench=# update t1 set t='测试1' where id=1;
pgbench=# select * from t1 where id=1;
id | t | mod_time
----+-------+----------
1 | 测试1 |
(1 row)
# 现备库128查询数据
pgbench=# select * from t1 where id=1;
id | t | mod_time
----+-------+----------
1 | 测试1 |
(1 row)7.结果
主备切换后,主备状态正常,数据更新正常。
8.主备切换切回
按上述步骤切回即可
五 其他
另外,主库 fast 和 immediate 宕机方式,主备切换方式同上。
边栏推荐
- [leetcode] 1254 - count the number of closed Islands
- 17_ Redis_ Redis publish subscription
- 【LeetCode】977-有序數組的平方
- 【LeetCode】19-删除链表的倒数第N个结点
- Name of institution approved in advance
- 夏季高考文化成绩一分一段表
- 密码学基础知识
- Basic knowledge of cryptography
- Two traversal sequences are known to construct binary trees
- . Net again! Happy 20th birthday
猜你喜欢

Basic knowledge of cryptography

LeetCode刷题——去除重复字母#316#Medium

JVM architecture, classloader, parental delegation mechanism

FPGA - clock-03-clock management module (CMT) of internal structure of 7 Series FPGA

Semantic segmentation learning notes (1)

5. Practice: jctree implements the annotation processor at compile time

I made an istio workshop. This is the first introduction

Finally, I understand the event loop, synchronous / asynchronous, micro task / macro task, and operation mechanism in JS (with test questions attached)

Case introduction and problem analysis of microservice

百变大7座,五菱佳辰产品力出众,人性化大空间,关键价格真香
随机推荐
[leetcode] 344 reverse string
[leetcode] 977 - carré du tableau ordonné
提前批院校名称
Pytoch saves tensor to Mat file
2022 年辽宁省大学生数学建模A、B、C题(相关论文及模型程序代码网盘下载)
【LeetCode】189-轮转数组
PTA 天梯赛习题集 L2-001 城市间紧急救援
Leetcode skimming -- incremental ternary subsequence 334 medium
NBA player analysis
18_ Redis_ Redis master-slave replication & cluster building
【Leetcode】167-两数之和II -输入有序数组
6090. 极大极小游戏
Case introduction and problem analysis of microservice
自定义异常
飞凌嵌入式RZ/G2L处理器核心板及开发板上手评测
Engineer evaluation | rk3568 development board hands-on test
【Experience Cloud】如何在VsCode中取得Experience Cloud的MetaData
面对“缺芯”挑战,飞凌如何为客户产能提供稳定强大的保障?
Party History Documentary theme public welfare digital cultural and creative products officially launched
19_ Redis_ Manually configure the host after downtime