当前位置:网站首页>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 宕机方式,主备切换方式同上。
边栏推荐
- Solve the problem of frequent interruption of mobaxterm remote connection
- Pytorch 保存tensor到.mat文件
- 03. Preliminary use of golang
- [leetcode] 877 stone game
- Leetcode question brushing - parity linked list 328 medium
- 面对“缺芯”挑战,飞凌如何为客户产能提供稳定强大的保障?
- 党史纪实主题公益数字文创产品正式上线
- [leetcode] 977 square of ordered array
- 18_ Redis_ Redis master-slave replication & cluster building
- 6.12 企业内部upp平台(Unified Process Platform)的关键一刻
猜你喜欢

Loss function and positive and negative sample allocation: Yolo series

Party History Documentary theme public welfare digital cultural and creative products officially launched

SQL transaction

PTA 天梯赛习题集 L2-001 城市间紧急救援

Storage read-write speed and network measurement based on rz/g2l | ok-g2ld-c development board

Facing the challenge of "lack of core", how can Feiling provide a stable and strong guarantee for customers' production capacity?

Let your HMI have more advantages. Fet-g2ld-c core board is a good choice

Solve the problem of frequent interruption of mobaxterm remote connection

14_ Redis_ Optimistic lock

2022 college students in Liaoning Province mathematical modeling a, B, C questions (related papers and model program code online disk download)
随机推荐
【LeetCode】1162-地图分析
18_ Redis_ Redis master-slave replication & cluster building
6091. 划分数组使最大差为 K
【LeetCode】1905-统计子岛屿
夏季高考文化成绩一分一段表
【LeetCode】695-岛屿的最大面积
How to intercept the value of a key from the JSON string returned by wechat?
Case introduction and problem analysis of microservice
【LeetCode】189-轮转数组
Be a good gatekeeper on the road of anti epidemic -- infrared thermal imaging temperature detection system based on rk3568
Leetcode skimming -- sum of two integers 371 medium
[network security] network asset collection
[leetcode] 1905 statistics sub Island
Bing. Site Internet
Name of institution approved in advance
Custom exception
folium,确诊和密接轨迹上图
Equipped with Ti am62x processor, Feiling fet6254-c core board is launched!
LeetCode_ String_ Simple_ 412.Fizz Buzz
There are 7 seats with great variety, Wuling Jiachen has outstanding product power, large humanized space, and the key price is really fragrant