Ensure event logging doesn't generate an error when cloning from a standby

This commit is contained in:
Ian Barwick
2016-01-19 13:51:49 +09:00
parent ec3596521f
commit cc1ea00333

View File

@@ -1212,6 +1212,7 @@ do_standby_unregister(void)
static void static void
do_standby_clone(void) do_standby_clone(void)
{ {
PGconn *primary_conn = NULL;
PGconn *upstream_conn; PGconn *upstream_conn;
PGresult *res; PGresult *res;
@@ -1286,6 +1287,23 @@ do_standby_clone(void)
log_info(_("Successfully connected to upstream node. Current installation size is %s\n"), log_info(_("Successfully connected to upstream node. Current installation size is %s\n"),
cluster_size); cluster_size);
/*
* If the upstream node is a standby, try to connect to the primary too so we
* can write an event record
*/
if (is_standby(upstream_conn))
{
if (strlen(options.cluster_name))
{
primary_conn = get_master_connection(upstream_conn, options.cluster_name,
NULL, NULL);
}
}
else
{
primary_conn = upstream_conn;
}
/* /*
* If --recovery-min-apply-delay was passed, check that * If --recovery-min-apply-delay was passed, check that
* we're connected to PostgreSQL 9.4 or later * we're connected to PostgreSQL 9.4 or later
@@ -1934,29 +1952,33 @@ stop_backup:
log_hint(_("for example : /etc/init.d/postgresql start\n")); log_hint(_("for example : /etc/init.d/postgresql start\n"));
} }
/* Log the event */ /* Log the event - if we could connect to the primary */
initPQExpBuffer(&event_details);
/* Add details about relevant runtime options used */ if (primary_conn != NULL)
appendPQExpBuffer(&event_details, {
_("Cloned from host '%s', port %s"), initPQExpBuffer(&event_details);
runtime_options.host,
runtime_options.masterport);
appendPQExpBuffer(&event_details, /* Add details about relevant runtime options used */
_("; backup method: %s"), appendPQExpBuffer(&event_details,
runtime_options.rsync_only ? "rsync" : "pg_basebackup"); _("Cloned from host '%s', port %s"),
runtime_options.host,
runtime_options.masterport);
appendPQExpBuffer(&event_details, appendPQExpBuffer(&event_details,
_("; --force: %s"), _("; backup method: %s"),
runtime_options.force ? "Y" : "N"); runtime_options.rsync_only ? "rsync" : "pg_basebackup");
create_event_record(upstream_conn, appendPQExpBuffer(&event_details,
&options, _("; --force: %s"),
options.node, runtime_options.force ? "Y" : "N");
"standby_clone",
true, create_event_record(primary_conn,
event_details.data); &options,
options.node,
"standby_clone",
true,
event_details.data);
}
PQfinish(upstream_conn); PQfinish(upstream_conn);
exit(retval); exit(retval);