pg13 交换主备库的角色(failover)
【摘要】 数据库版本信息:postgres=# select version(); version---------------------------------------------------------------------------------------------------------...
数据库版本信息:
postgres=# select version();
version
---------------------------------------------------------------------------------------------------------
PostgreSQL 13.4 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39), 64-bit
(1 row)
主备数据库信息:
主:127.0.0.1 5433 目录 /data/s001
备:127.0.0.1 5432 目录/data/master
01.模拟主机故障,停止主数据库
-bash-4.2$ pg_ctl -D /data/s001/ stop
waiting for server to shut down....2021-10-24 16:55:32.054 CST [10171] LOG: received fast shutdown request
2021-10-24 16:55:32.064 CST [10171] LOG: aborting any active transactions
2021-10-24 16:55:32.071 CST [10171] LOG: background worker "logical replication launcher" (PID 10178) exited with exit code 1
2021-10-24 16:55:32.071 CST [10173] LOG: shutting down
2021-10-24 16:55:32.132 CST [10611] LOG: replication terminated by primary server
2021-10-24 16:55:32.132 CST [10611] DETAIL: End of WAL reached on timeline 1 at 0/3011FF8.
2021-10-24 16:55:32.132 CST [10611] FATAL: could not send end-of-streaming message to primary: no COPY in progress
2021-10-24 16:55:32.134 CST [10607] LOG: record length 1207964928 at 0/3011FF8 too long
2021-10-24 16:55:32.149 CST [10171] LOG: database system is shut down
2021-10-24 16:55:32.153 CST [14378] FATAL: could not connect to the primary server: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
done
server stopped
02,激活备库
-bash-4.2$ pg_ctl -D /data/master promote
waiting for server to promote.... done
server promoted
#备库提升主库日志:
2021-10-24 16:56:36.020 CST [10607] LOG: received promote request
2021-10-24 16:56:36.020 CST [10607] LOG: redo done at 0/3011F80
2021-10-24 16:56:36.020 CST [10607] LOG: last completed transaction was at log time 2021-10-24 16:49:03.893587+08
2021-10-24 16:56:36.044 CST [10607] LOG: selected new timeline ID: 2
2021-10-24 16:56:36.244 CST [10607] LOG: archive recovery complete
2021-10-24 16:56:36.269 CST [10606] LOG: database system is ready to accept connections
检查数据库状态,已经提升为主数据库:
postgres=# select pg_is_in_recovery();
pg_is_in_recovery
-------------------
f
(1 row)
03,原主库,重新提升为备机
重新同步数据库:
walpg_rewind -D $PGDATA --source-server='host=10.0.3.102 user=postgres password=’
或者使用
pg_basebackup
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)