repmgr: add "--node-id" option to "cluster cleanup"

Implements GitHub #493.
This commit is contained in:
Ian Barwick
2018-09-25 15:54:22 +09:00
parent b660cb9fe4
commit 688337dec3
7 changed files with 74 additions and 19 deletions

View File

@@ -1,6 +1,7 @@
4.2.0 2018-??-?? 4.2.0 2018-??-??
repmgr: add parameter "shutdown_check_timeout" for use by "standby switchover"; repmgr: add parameter "shutdown_check_timeout" for use by "standby switchover";
GitHub #504 (Ian) GitHub #504 (Ian)
repmgr: add "--node-id" option to "repmgr cluster cleanup"; GitHub #493 (Ian)
4.1.1 2018-09-05 4.1.1 2018-09-05
logging: explicitly log the text of failed queries as ERRORs to logging: explicitly log the text of failed queries as ERRORs to

View File

@@ -4167,7 +4167,7 @@ add_monitoring_record(PGconn *primary_conn,
int int
get_number_of_monitoring_records_to_delete(PGconn *primary_conn, int keep_history) get_number_of_monitoring_records_to_delete(PGconn *primary_conn, int keep_history, int node_id)
{ {
PQExpBufferData query; PQExpBufferData query;
int record_count = -1; int record_count = -1;
@@ -4181,8 +4181,15 @@ get_number_of_monitoring_records_to_delete(PGconn *primary_conn, int keep_histor
" WHERE pg_catalog.age(pg_catalog.now(), last_monitor_time) >= '%d days'::interval", " WHERE pg_catalog.age(pg_catalog.now(), last_monitor_time) >= '%d days'::interval",
keep_history); keep_history);
res = PQexec(primary_conn, query.data); if (node_id != UNKNOWN_NODE_ID)
{
appendPQExpBuffer(&query,
" AND standby_node_id = %i", node_id);
}
log_verbose(LOG_DEBUG, "get_number_of_monitoring_records_to_delete():\n %s", query.data);
res = PQexec(primary_conn, query.data);
if (PQresultStatus(res) != PGRES_TUPLES_OK) if (PQresultStatus(res) != PGRES_TUPLES_OK)
{ {
@@ -4202,7 +4209,7 @@ get_number_of_monitoring_records_to_delete(PGconn *primary_conn, int keep_histor
bool bool
delete_monitoring_records(PGconn *primary_conn, int keep_history) delete_monitoring_records(PGconn *primary_conn, int keep_history, int node_id)
{ {
PQExpBufferData query; PQExpBufferData query;
bool success = true; bool success = true;
@@ -4210,12 +4217,18 @@ delete_monitoring_records(PGconn *primary_conn, int keep_history)
initPQExpBuffer(&query); initPQExpBuffer(&query);
if (keep_history > 0) if (keep_history > 0 || node_id != UNKNOWN_NODE_ID)
{ {
appendPQExpBuffer(&query, appendPQExpBuffer(&query,
"DELETE FROM repmgr.monitoring_history " "DELETE FROM repmgr.monitoring_history "
" WHERE pg_catalog.age(pg_catalog.now(), last_monitor_time) >= '%d days'::INTERVAL ", " WHERE pg_catalog.age(pg_catalog.now(), last_monitor_time) >= '%d days'::INTERVAL ",
keep_history); keep_history);
if (node_id != UNKNOWN_NODE_ID)
{
appendPQExpBuffer(&query,
" AND standby_node_id = %i", node_id);
}
} }
else else
{ {

View File

@@ -491,8 +491,8 @@ add_monitoring_record(PGconn *primary_conn,
long long unsigned int apply_lag_bytes long long unsigned int apply_lag_bytes
); );
int get_number_of_monitoring_records_to_delete(PGconn *primary_conn, int keep_history); int get_number_of_monitoring_records_to_delete(PGconn *primary_conn, int keep_history, int node_id);
bool delete_monitoring_records(PGconn *primary_conn, int keep_history); bool delete_monitoring_records(PGconn *primary_conn, int keep_history, int node_id);

View File

@@ -20,6 +20,7 @@
<para><emphasis>???, 2018</emphasis></para> <para><emphasis>???, 2018</emphasis></para>
<para> <para>
</para> </para>
<sect2> <sect2>
<title>Configuration file changes</title> <title>Configuration file changes</title>
<para> <para>
@@ -39,6 +40,23 @@
</para> </para>
</sect2> </sect2>
<sect2>
<title>repmgr enhancements</title>
<para>
<itemizedlist>
<listitem>
<para>
<command><link linkend="repmgr-cluster-cleanup">repmgr cluster cleanup</link></command>
now accepts the <option>--node-id</option> option to delete records for only one
node. (GitHub #493).
</para>
</listitem>
</itemizedlist>
</para>
</sect2>
</sect1> </sect1>
<sect1 id="release-4.1.1"> <sect1 id="release-4.1.1">

View File

@@ -51,6 +51,20 @@
</para> </para>
</refsect1> </refsect1>
<refsect1>
<title>Options</title>
<variablelist>
<varlistentry>
<term><option>--node-id</option></term>
<listitem>
<para>
Only delete monitoring records for the specified node.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1> <refsect1>
<title>See also</title> <title>See also</title>

View File

@@ -1372,7 +1372,9 @@ do_cluster_cleanup(void)
log_debug(_("number of days of monitoring history to retain: %i"), runtime_options.keep_history); log_debug(_("number of days of monitoring history to retain: %i"), runtime_options.keep_history);
entries_to_delete = get_number_of_monitoring_records_to_delete(primary_conn, runtime_options.keep_history); entries_to_delete = get_number_of_monitoring_records_to_delete(primary_conn,
runtime_options.keep_history,
runtime_options.node_id);
if (entries_to_delete < 0) if (entries_to_delete < 0)
{ {
@@ -1392,7 +1394,7 @@ do_cluster_cleanup(void)
initPQExpBuffer(&event_details); initPQExpBuffer(&event_details);
if (delete_monitoring_records(primary_conn, runtime_options.keep_history) == false) if (delete_monitoring_records(primary_conn, runtime_options.keep_history, runtime_options.node_id) == false)
{ {
appendPQExpBuffer(&event_details, appendPQExpBuffer(&event_details,
_("unable to delete monitoring records")); _("unable to delete monitoring records"));
@@ -1418,8 +1420,21 @@ do_cluster_cleanup(void)
log_detail("%s", PQerrorMessage(primary_conn)); log_detail("%s", PQerrorMessage(primary_conn));
} }
appendPQExpBuffer(&event_details, if (runtime_options.keep_history == 0)
_("monitoring records deleted")); {
appendPQExpBuffer(&event_details,
_("all monitoring records deleted"));
}
else
{
appendPQExpBuffer(&event_details,
_("monitoring records deleted"));
}
if (runtime_options.node_id != UNKNOWN_NODE_ID)
appendPQExpBuffer(&event_details,
_(" for node %i"),
runtime_options.node_id);
if (runtime_options.keep_history > 0) if (runtime_options.keep_history > 0)
appendPQExpBuffer(&event_details, appendPQExpBuffer(&event_details,
@@ -1433,18 +1448,11 @@ do_cluster_cleanup(void)
true, true,
event_details.data); event_details.data);
log_notice("%s", event_details.data);
termPQExpBuffer(&event_details); termPQExpBuffer(&event_details);
PQfinish(primary_conn); PQfinish(primary_conn);
if (runtime_options.keep_history > 0)
{
log_notice(_("monitoring records older than %i day(s) deleted"),
runtime_options.keep_history);
}
else
{
log_info(_("all monitoring records deleted"));
}
return; return;
} }

View File

@@ -1520,6 +1520,7 @@ check_cli_parameters(const int action)
case PRIMARY_UNREGISTER: case PRIMARY_UNREGISTER:
case STANDBY_UNREGISTER: case STANDBY_UNREGISTER:
case WITNESS_UNREGISTER: case WITNESS_UNREGISTER:
case CLUSTER_CLEANUP:
case CLUSTER_EVENT: case CLUSTER_EVENT:
case CLUSTER_MATRIX: case CLUSTER_MATRIX:
case CLUSTER_CROSSCHECK: case CLUSTER_CROSSCHECK: