From a2068768ab3847e71b41e4171f2426eac19e61b8 Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Fri, 9 Feb 2018 12:09:16 +0900 Subject: [PATCH] Execute a CHECKPOINT immediately after promoting the server This ensures "pg_control" is updated with the latest timeline, mainly to ensure that if "pg_rewind" is executed as part of a switchover that it sees the latest timeline. Per suggestion from GitHub user "superflav" in GitHub #378. See also: https://www.postgresql.org/message-id/flat/20150428180253.GU30322%40tamriel.snowman.net --- repmgr-action-standby.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/repmgr-action-standby.c b/repmgr-action-standby.c index 26bad895..6eaa07d0 100644 --- a/repmgr-action-standby.c +++ b/repmgr-action-standby.c @@ -1976,6 +1976,13 @@ _do_standby_promote_internal(PGconn *conn, const char *data_dir) log_verbose(LOG_INFO, _("standby promoted to primary after %i second(s)"), i); + /* + * Execute a CHECKPOINT as soon as possible after promotion. The primary + * reason for this is to ensure that "pg_control" has the latest timeline + * before it's read by "pg_rewind", typically during a switchover operation. + */ + checkpoint(conn); + /* update node information to reflect new status */ if (update_node_record_set_primary(conn, config_file_options.node_id) == false) {