repmgr: add "cluster_cleanup" event

GitHub #492.
This commit is contained in:
Ian Barwick
2018-08-20 16:47:24 +09:00
parent 6fc79470fc
commit e1e59e85d7
6 changed files with 49 additions and 3 deletions

View File

@@ -3,6 +3,7 @@
repmgr: improve messages emitted during "standby promote" (Ian) repmgr: improve messages emitted during "standby promote" (Ian)
repmgr: "standby clone" - don't copy external config files in --dry-run repmgr: "standby clone" - don't copy external config files in --dry-run
mode; GitHub #491 (Ian) mode; GitHub #491 (Ian)
repmgr: add "cluster_cleanup" event; GitHub #492 (Ian)
repmgrd: ensure that sending SIGHUP always results in the log file repmgrd: ensure that sending SIGHUP always results in the log file
being reopened; GitHub #485 (Ian) being reopened; GitHub #485 (Ian)
repmgrd: report version number *after* logger initialisation; GitHub #487 (Ian) repmgrd: report version number *after* logger initialisation; GitHub #487 (Ian)

View File

@@ -1760,7 +1760,6 @@ vacuum_table(PGconn *primary_conn, const char *table)
res = PQexec(primary_conn, query.data); res = PQexec(primary_conn, query.data);
termPQExpBuffer(&query); termPQExpBuffer(&query);
log_debug("%i", (int) PQresultStatus(res));
if (PQresultStatus(res) != PGRES_COMMAND_OK) if (PQresultStatus(res) != PGRES_COMMAND_OK)
{ {
success = false; success = false;
@@ -3336,7 +3335,7 @@ _create_event(PGconn *conn, t_configuration_options *options, int node_id, char
*/ */
if (notify_ok == false) if (notify_ok == false)
{ {
log_debug(_("Not executing notification script for event type \"%s\""), event); log_debug(_("not executing notification script for event type \"%s\""), event);
return success; return success;
} }
} }

View File

@@ -34,6 +34,12 @@
</para> </para>
</listitem> </listitem>
<listitem>
<para>
<command><link linkend="repmgr-cluster-cleanup">repmgr cluster cleanup</link></command>:
add <literal>cluster_cleanup</literal> event. (GitHub #492)
</para>
</listitem>
</itemizedlist> </itemizedlist>
</para> </para>

View File

@@ -193,6 +193,9 @@
<listitem> <listitem>
<simpara><literal>node_rejoin</literal></simpara> <simpara><literal>node_rejoin</literal></simpara>
</listitem> </listitem>
<listitem>
<simpara><literal>cluster_cleanup</literal></simpara>
</listitem>
<listitem> <listitem>
<simpara><literal>repmgrd_start</literal></simpara> <simpara><literal>repmgrd_start</literal></simpara>
</listitem> </listitem>

View File

@@ -44,6 +44,14 @@
</para> </para>
</refsect1> </refsect1>
<refsect1>
<title>Event notifications</title>
<para>
A <literal>cluster_cleanup</literal> <link linkend="event-notifications">event notification</link> will be generated.
</para>
</refsect1>
<refsect1> <refsect1>
<title>See also</title> <title>See also</title>
<para> <para>

View File

@@ -1332,6 +1332,7 @@ do_cluster_cleanup(void)
PGconn *conn = NULL; PGconn *conn = NULL;
PGconn *primary_conn = NULL; PGconn *primary_conn = NULL;
int entries_to_delete = 0; int entries_to_delete = 0;
PQExpBufferData event_details;
conn = establish_db_connection(config_file_options.conninfo, true); conn = establish_db_connection(config_file_options.conninfo, true);
@@ -1355,10 +1356,23 @@ do_cluster_cleanup(void)
log_debug("at least %i monitoring records for deletion", log_debug("at least %i monitoring records for deletion",
entries_to_delete); entries_to_delete);
initPQExpBuffer(&event_details);
if (delete_monitoring_records(primary_conn, runtime_options.keep_history) == false) if (delete_monitoring_records(primary_conn, runtime_options.keep_history) == false)
{ {
log_error(_("unable to delete monitoring records")); appendPQExpBuffer(&event_details,
_("unable to delete monitoring records"));
log_error("%s", event_details.data);
log_detail("%s", PQerrorMessage(primary_conn)); log_detail("%s", PQerrorMessage(primary_conn));
create_event_notification(primary_conn,
&config_file_options,
config_file_options.node_id,
"cluster_cleanup",
false,
event_details.data);
PQfinish(primary_conn); PQfinish(primary_conn);
exit(ERR_DB_QUERY); exit(ERR_DB_QUERY);
} }
@@ -1370,7 +1384,22 @@ do_cluster_cleanup(void)
log_detail("%s", PQerrorMessage(primary_conn)); log_detail("%s", PQerrorMessage(primary_conn));
} }
appendPQExpBuffer(&event_details,
_("monitoring records deleted"));
if (runtime_options.keep_history > 0)
appendPQExpBuffer(&event_details,
_("; records newer than %i day(s) retained"),
runtime_options.keep_history);
create_event_notification(primary_conn,
&config_file_options,
config_file_options.node_id,
"cluster_cleanup",
true,
event_details.data);
termPQExpBuffer(&event_details);
PQfinish(primary_conn); PQfinish(primary_conn);
if (runtime_options.keep_history > 0) if (runtime_options.keep_history > 0)