确保PostgreSQL 9.x hot standy复制仍然正常运行的最方便的方法是什么?

假设我已经将热点服务器复制设置得很好,我可以定期采取哪些最简单或最方便的步骤来确保热点服务器复制仍然正常工作。

我想比较SELECT txid_current_snapshot(); 在两个服务器上。 如果2 txid s匹配,那么是否足够好又安全地假定复制工作正常?

PostgreSQL的wiki 在stream式复制的页面上有这个信息:

您可以通过比较主服务器上当前的WAL写位置与备用服务器接收/重播的最后一个WAL位置来计算复制延迟。 可以分别使用主服务器上的pg_current_xlog_location和备用服务器上的pg_last_xlog_receive_location / pg_last_xlog_replay_location来检索它们。

这些函数返回一个id/offsetforms的string,其中idoffset是hex数字。 要将它们转换为64位数字进行比较,您可以使用以下公式,取自check_postgres Nagios插件:

 0xff000000 * from_hex(id) + from_hex(offset) 

在bash脚本中,可以使用这个函数完成:

 xlog_location_to_64bits() { id="${1%%/*}" offset="${1##*/}" echo $((0xFF000000 * 0x$id + 0x$offset)) } 

从主设备上的值减去从设备上的值会导致复制滞后字节。

对我来说,最方便的方法就是本页第12步提到的方法:

 # The displayed LSNs indicate the byte position that the standby server has # written up to in the xlogs. [primary] $ ps -ef | grep sender postgres 6879 6831 0 10:31 ? 00:00:00 postgres: wal sender process postgres 127.0.0.1(44663) streaming 0/2000000 [standby] $ ps -ef | grep receiver postgres 6878 6872 1 10:31 ? 00:00:01 postgres: wal receiver process streaming 0/2000000