standby clone: warn about missing pg_rewind prerequisites

These are not essential for cloning a standby, but useful to warn
as early as possible in case the user is intending to use pg_rewind.
This commit is contained in:
Ian Barwick
2020-04-06 15:28:57 +09:00
parent 09f0be8ceb
commit cd80f265ac
5 changed files with 90 additions and 4 deletions

View File

@@ -5,6 +5,8 @@
repmgr: ensure postgresql.auto.conf is created with correct permissions (Ian)
repmgr: minimize requirement to check upstream data directory location
during "standby clone" (Ian)
repmgr: warn about missing pg_rewind prerequisites when excuting
"standby clone" (Ian)
repmgr: add --upstream option to "node check"
repmgr: report error code on follow/rejoin failure due to non-available
replication slot (Ian)

View File

@@ -48,7 +48,7 @@ static PGconn * _establish_replication_connection_from_params(PGconn *conn, cons
static PGconn *_get_primary_connection(PGconn *standby_conn, int *primary_id, char *primary_conninfo_out, bool quiet);
static bool _set_config(PGconn *conn, const char *config_param, const char *sqlquery);
static bool _get_pg_setting(PGconn *conn, const char *setting, char *str_output, int *int_output);
static bool _get_pg_setting(PGconn *conn, const char *setting, char *str_output, bool *bool_output, int *int_output);
static RecordStatus _get_node_record(PGconn *conn, char *sqlquery, t_node_info *node_info, bool init_defaults);
static void _populate_node_record(PGresult *res, t_node_info *node_info, int row, bool init_defaults);
@@ -1076,7 +1076,7 @@ guc_set(PGconn *conn, const char *parameter, const char *op,
bool
get_pg_setting(PGconn *conn, const char *setting, char *output)
{
bool success = _get_pg_setting(conn, setting, output, NULL);
bool success = _get_pg_setting(conn, setting, output, NULL, NULL);
if (success == true)
{
@@ -1086,11 +1086,24 @@ get_pg_setting(PGconn *conn, const char *setting, char *output)
return success;
}
bool
get_pg_setting_bool(PGconn *conn, const char *setting, bool *output)
{
bool success = _get_pg_setting(conn, setting, NULL, output, NULL);
if (success == true)
{
log_verbose(LOG_DEBUG, _("get_pg_setting(): returned value is \"%s\""),
*output == true ? "TRUE" : "FALSE");
}
return success;
}
bool
get_pg_setting_int(PGconn *conn, const char *setting, int *output)
{
bool success = _get_pg_setting(conn, setting, NULL, output);
bool success = _get_pg_setting(conn, setting, NULL, NULL, output);
if (success == true)
{
@@ -1102,7 +1115,7 @@ get_pg_setting_int(PGconn *conn, const char *setting, int *output)
bool
_get_pg_setting(PGconn *conn, const char *setting, char *str_output, int *int_output)
_get_pg_setting(PGconn *conn, const char *setting, char *str_output, bool *bool_output, int *int_output)
{
PQExpBufferData query;
PGresult *res = NULL;
@@ -1144,9 +1157,24 @@ _get_pg_setting(PGconn *conn, const char *setting, char *str_output, int *int_ou
if (strcmp(PQgetvalue(res, i, 0), setting) == 0)
{
if (str_output != NULL)
{
snprintf(str_output, MAXLEN, "%s", PQgetvalue(res, i, 1));
}
else if (bool_output != NULL)
{
/*
* Note we assume the caller is sure this is a boolean parameter
*/
printf("YYY %s\n", PQgetvalue(res, i, 1));
if (strncmp(PQgetvalue(res, i, 1), "on", MAXLEN) == 0)
*bool_output = true;
else
*bool_output = false;
}
else if (int_output != NULL)
{
*int_output = atoi(PQgetvalue(res, i, 1));
}
success = true;
break;

View File

@@ -429,6 +429,7 @@ bool set_config(PGconn *conn, const char *config_param, const char *config_valu
bool set_config_bool(PGconn *conn, const char *config_param, bool state);
int guc_set(PGconn *conn, const char *parameter, const char *op, const char *value);
bool get_pg_setting(PGconn *conn, const char *setting, char *output);
bool get_pg_setting_bool(PGconn *conn, const char *setting, bool *output);
bool get_pg_setting_int(PGconn *conn, const char *setting, int *output);
bool alter_system_int(PGconn *conn, const char *name, int value);
bool pg_reload_conf(PGconn *conn);

View File

@@ -49,6 +49,16 @@
<title>General improvements</title>
<para>
<itemizedlist>
<listitem>
<para>
<link linkend="repmgr-standby-clone"><command>repmgr standby clone</command></link>:
Warn if neither of data page checksums or <option>wal_log_hints</option> are active,
as this will preclude later usage of <command>pg_rewind</command>.
</para>
</listitem>
<listitem>
<para>
<link linkend="repmgr-standby-promote"><command>repmgr standby promote</command></link>:

View File

@@ -6194,6 +6194,51 @@ check_upstream_config(PGconn *conn, int server_version_num, t_node_info *upstrea
}
}
/*
* Finally, add some checks for recommended settings
*/
{
bool data_checksums = false;
bool wal_log_hints = false;
/* data_checksums available from PostgreSQL 9.3; can be read by any user */
if (get_pg_setting_bool(conn, "data_checksums", &data_checksums) == false)
{
/* highly unlikely this will happen */
log_error(_("unable to determine value for \"data_checksums\""));
exit(ERR_BAD_CONFIG);
}
/* wal_log_hints available from PostgreSQL 9.4; can be read by any user */
if (PQserverVersion(conn) >= 90400)
{
if (get_pg_setting_bool(conn, "wal_log_hints", &wal_log_hints) == false)
{
/* highly unlikely this will happen */
log_error(_("unable to determine value for \"wal_log_hints\""));
exit(ERR_BAD_CONFIG);
}
}
printf("XXX %i\n", PQserverVersion(conn));
if (data_checksums == false && wal_log_hints == false)
{
/*
* If anyone's still on 9.3, there's not a lot we can do anyway
*/
if (PQserverVersion(conn) < 90400)
{
log_warning(_("data checksums are not enabled"));
}
else
{
log_warning(_("data checksums are not enabled and \"wal_log_hints\" is \"off\""));
log_detail(_("pg_rewind requires \"wal_log_hints\" to be enabled"));
}
}
}
return config_ok;
}