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,7 +1952,10 @@ 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 */
if (primary_conn != NULL)
{
initPQExpBuffer(&event_details); initPQExpBuffer(&event_details);
/* Add details about relevant runtime options used */ /* Add details about relevant runtime options used */
@@ -1951,12 +1972,13 @@ stop_backup:
_("; --force: %s"), _("; --force: %s"),
runtime_options.force ? "Y" : "N"); runtime_options.force ? "Y" : "N");
create_event_record(upstream_conn, create_event_record(primary_conn,
&options, &options,
options.node, options.node,
"standby_clone", "standby_clone",
true, true,
event_details.data); event_details.data);
}
PQfinish(upstream_conn); PQfinish(upstream_conn);
exit(retval); exit(retval);