admin 管理员组文章数量: 1184232
前言:
经过测试,postgres的主备切换后,同步会出现问题,新的备库不会从主库同步数据过来。需要使用pg_rewind重新修复新的备库
参考文档:
http://postgres/docs/10/app-pgrewind.html
-- 主备信息
PG版本 :10.15
主库 192.168.2.80 主机名test
备库 192.168.2.81 主机名test1
-- 查看主备库的信息
[root@test /opt/pgpool/bin]$pg_controldata | grep "Database cluster state"
Database cluster state: in production
[root@test /opt/pgpool/bin]$
[root@test1 /root]$pg_controldata | grep "Database cluster state"
Database cluster state: in archive recovery
[root@test1 /root]$
postgres=# \x
Expanded display is on.
postgres=# select * from pg_stat_replication;
-[ RECORD 1 ]----+------------------------------
pid | 13456
usesysid | 16406
usename | repl
application_name | walreceiver
client_addr | 192.168.2.81
client_hostname |
client_port | 47797
backend_start | 2021-08-27 08:13:11.217507+08
backend_xmin |
state | streaming
sent_lsn | 0/10000350
write_lsn | 0/10000350
flush_lsn | 0/10000350
replay_lsn | 0/10000350
write_lag |
flush_lag |
replay_lag |
sync_priority | 0
sync_state | async
postgres=#
-- 停掉主库 ,同时将原来备库上的recovery.con文件copy一份到主库,后面变更主库为备库的时候会用到。(或者不copy也行,在后面使用pg_rewind的时候,会自动copy过来,包括pg_hba.conf,postgres.conf,recovery.conf文件等,所以做好conf文件的备份)
pg_ctl stop -m fast
pg_controldata | grep "Database cluster state"
[postgres@test /home/postgres]$pg_ctl stop -m fast
waiting for server to shut down.... done
server stopped
[postgres@test /home/postgres]$
[postgres@test /home/postgres]$pg_controldata | grep "Database cluster state"
Database cluster state: shut down
[postgres@test /home/postgres]$
-- 提升从库为新的主库,可以看到原来的从库上面,recovery.conf变成了recovery.done
pg_ctl promote
pg_controldata | grep "Database cluster state"
[postgres@test1 /home/postgres]$pg_ctl promote
waiting for server to promote.... done
server promoted
[postgres@test1 /home/postgres]$pg_controldata | grep "Database cluster state"
Database cluster state: in production
[postgres@test1 /home/postgres]$
[postgres@test1 /opt/PostgreSQL/10/data]$ls *recov*
recovery.done
[postgres@test1 /opt/PostgreSQL/10/data]$more recovery.done
standby_mode = 'on'
primary_conninfo = 'user=repl password=oracle host=192.168.2.80 port=5432 sslmode=prefer sslcompression=1 krbsrvname=
版权声明:本文标题:Postgres主备切换及pg_rewind的使用 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/b/1763930609a3279544.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论