当前位置:网站首页>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 recovery
2.流复制同步情况检查
select * from pg_stat_replication;
四 主备切换
1.主库宕机
# 128主机模拟数据库关闭
pg_ctl -D /data/dbdata/pgsql/14/5432/data stop -m smart
2.主备切换
# 129主机切换为主库
pg_ctl promote -D /data/dbdata/pgsql/14/5432/data
3.原主库调整为备库
# 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 start
4.主备状态检查
pg_controldata -D /data/dbdata/pgsql/14/5432/data/
128:Database cluster state: in archive recovery
129:Database cluster state: in production
5.流复制同步情况检查
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 skimming -- sum of two integers 371 medium
搭建自己的语义分割平台deeplabV3+
Let your HMI have more advantages. Fet-g2ld-c core board is a good choice
How to intercept the value of a key from the JSON string returned by wechat?
How to choose a third-party software testing organization for automated acceptance testing of mobile applications
[experience cloud] how to get the metadata of experience cloud in vscode
Basic knowledge of cryptography
LeetCode刷题——去除重复字母#316#Medium
Build your own semantic segmentation platform deeplabv3+
自定义异常
随机推荐
04. Some thoughts on enterprise application construction after entering cloud native
6090. 极大极小游戏
Redux——详解
Leetcode skimming -- sum of two integers 371 medium
Summary of the first three passes of sqli Labs
提前批院校名称
[leetcode] 19 delete the penultimate node of the linked list
Case introduction and problem analysis of microservice
损失函数与正负样本分配:YOLO系列
6.12 企业内部upp平台(Unified Process Platform)的关键一刻
[leetcode] 877 stone game
Force deduction solution summarizes the lucky numbers in 1380 matrix
FPGA - clock-03-clock management module (CMT) of internal structure of 7 Series FPGA
Party History Documentary theme public welfare digital cultural and creative products officially launched
Semantic segmentation learning notes (1)
There are 7 seats with great variety, Wuling Jiachen has outstanding product power, large humanized space, and the key price is really fragrant
(4) Flink's table API and SQL table schema
How to find a sense of career direction
YOLOV5 代码复现以及搭载服务器运行
【LeetCode】695-岛屿的最大面积