pg_ctl促进不迅速暂停复制

时间:2019-05-10 11:06:07

标签: postgresql database-replication

我有一个两节点的PostgreSQL集群。一个是主服务器(192.168.50.3),另一个是辅助服务器(192.168.50.4)。我的recovery.conf看起来像下面的192.168.50.4。

standby_mode          = 'on'
primary_conninfo      = 'host=192.168.50.3 port=5432 user=myuser password=<password_here> sslmode=require sslcompression=0'
trigger_file = '/tmp/make_master'
recovery_target_timeline = 'latest'

现在,我在辅助服务器(192.168.50.4)上运行pg_ctl promote,一旦命令成功,我就从主服务器(192.168.50.3)删除了一些数据,并且删除的数据也从辅助服务器上删除了(192.168.50.4)。

pg_ctl promote是否需要时间才能真正挂起复制? 如何确定复制已正确暂停?

来自/var/log/messages的192.168.50.4日志:

May 10 06:17:45 cluster-node6 sudo: myuser : TTY=pts/0 ; PWD=/home/myuser ; USER=postgres ; COMMAND=/usr/pgsql-11/bin/pg_ctl promote --pgdata=/var/lib/pgsql/11/data
May 10 06:17:45 cluster-node6 sudo: pam_unix(sudo:session): session opened for user postgres by csadmin(uid=0)
May 10 06:17:45 cluster-node6 postmaster: 2019-05-10 06:17:45 UTC LOG:  received promote request
May 10 06:17:45 cluster-node6 postmaster: 2019-05-10 06:17:45 UTC LOG:  received promote request
May 10 06:17:45 cluster-node6 postmaster: 2019-05-10 06:17:45 UTC FATAL:  terminating walreceiver process due to administrator command
May 10 06:17:45 cluster-node6 postmaster: 2019-05-10 06:17:45 UTC FATAL:  terminating walreceiver process due to administrator command
May 10 06:17:45 cluster-node6 postmaster: 2019-05-10 06:17:45 UTC LOG:  redo done at 0/891BFB8
May 10 06:17:45 cluster-node6 postmaster: 2019-05-10 06:17:45 UTC LOG:  redo done at 0/891BFB8
May 10 06:17:45 cluster-node6 postmaster: 2019-05-10 06:17:45 UTC LOG:  last completed transaction was at log time 2019-05-10 06:17:45.550363+00
May 10 06:17:45 cluster-node6 postmaster: 2019-05-10 06:17:45 UTC LOG:  last completed transaction was at log time 2019-05-10 06:17:45.550363+00
May 10 06:17:45 cluster-node6 postmaster: 2019-05-10 06:17:45 UTC LOG:  selected new timeline ID: 2
May 10 06:17:45 cluster-node6 postmaster: 2019-05-10 06:17:45 UTC LOG:  selected new timeline ID: 2
May 10 06:17:45 cluster-node6 postmaster: 2019-05-10 06:17:45 UTC LOG:  archive recovery complete
May 10 06:17:45 cluster-node6 postmaster: 2019-05-10 06:17:45 UTC LOG:  archive recovery complete
May 10 06:17:45 cluster-node6 postmaster: 2019-05-10 06:17:45 UTC LOG:  database system is ready to accept connections
May 10 06:17:45 cluster-node6 postmaster: 2019-05-10 06:17:45 UTC LOG:  database system is ready to accept connections
May 10 06:17:45 cluster-node6 sudo: pam_unix(sudo:session): session closed for user postgres

1 个答案:

答案 0 :(得分:1)

促销是异步的。它会向邮局主管发送信号,然后由邮局主管执行您在日志中看到的顺序。

因此,pg_ctl promote成功发送信号后,复制会持续一会儿是正常的。

如果您需要确保升级完成,请继续调用函数pg_is_in_recovery(),直到返回FALSE

从PostgreSQL v12开始,您可以调用我的函数pg_promote()来升级备用数据库,默认情况下,它将等待升级完成。