当前位置:网站首页>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 宕机方式,主备切换方式同上。
边栏推荐
- Summary of the first three passes of sqli Labs
- [leetcode] 189 rotation array
- (4) Flink's table API and SQL table schema
- 6095. 强密码检验器 II
- 04.进入云原生后的企业级应用构建的一些思考
- 【LeetCode】977-有序数组的平方
- PTA ladder game exercise set l2-001 inter city emergency rescue
- Equipped with Ti am62x processor, Feiling fet6254-c core board is launched!
- 14_ Redis_ Optimistic lock
- [leetcode] 344 reverse string
猜你喜欢

2022 college students in Liaoning Province mathematical modeling a, B, C questions (related papers and model program code online disk download)

5. Practice: jctree implements the annotation processor at compile time
![[leetcode] 1905 statistics sub Island](/img/82/d2f7b829f5beb7f9f1eabe8d101ecb.png)
[leetcode] 1905 statistics sub Island

Be a good gatekeeper on the road of anti epidemic -- infrared thermal imaging temperature detection system based on rk3568

PTA ladder game exercise set l2-001 inter city emergency rescue

Bing.com网站

Bing. Com website

MySQL -- Index Optimization -- order by

03. Preliminary use of golang

Bing. Site Internet
随机推荐
Force deduction solution summary 2029 stone game IX
Wechat Alipay account system and payment interface business process
2022 college students in Liaoning Province mathematical modeling a, B, C questions (related papers and model program code online disk download)
PTA ladder game exercise set l2-001 inter city emergency rescue
百变大7座,五菱佳辰产品力出众,人性化大空间,关键价格真香
Leetcode skimming -- incremental ternary subsequence 334 medium
Two traversal sequences are known to construct binary trees
Case introduction and problem analysis of microservice
Force deduction solution summarizes the lucky numbers in 1380 matrix
[experience cloud] how to get the metadata of experience cloud in vscode
[leetcode] 1254 - count the number of closed Islands
6.12 critical moment of Unified Process Platform
【LeetCode】1162-地图分析
Basic knowledge of cryptography
Bing. Com website
终于搞懂了JS中的事件循环,同步/异步,微任务/宏任务,运行机制(附笔试题)
4. Jctree related knowledge learning
(Video + graphic) machine learning introduction series - Chapter 5 machine learning practice
JVM architecture, classloader, parental delegation mechanism
2303. 计算应缴税款总额