From 55e3b11bdc141fc1c8df183142a6aa652c5b7f1f Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Fri, 14 Feb 2020 10:39:28 +0900 Subject: [PATCH] Add optional check for unsupported future PostgreSQL releases This is for backbranches to prevent them running against newer PostgreSQL versions with which they are not compatible, for example 4.4.x with PostgreSQL 12 and later. --- repmgr-action-standby.c | 3 +++ repmgr-client.c | 44 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/repmgr-action-standby.c b/repmgr-action-standby.c index 6687835d..55ae34f6 100644 --- a/repmgr-action-standby.c +++ b/repmgr-action-standby.c @@ -1014,6 +1014,9 @@ _do_create_recovery_conf(void) /* check connection */ source_conn = establish_db_connection_by_params(&source_conninfo, true); + /* Verify that source is a supported server version */ + (void) check_server_version(source_conn, "source node", true, NULL); + /* determine node for primary_conninfo */ if (runtime_options.upstream_node_id != UNKNOWN_NODE_ID) diff --git a/repmgr-client.c b/repmgr-client.c index d914051b..3a32cf17 100644 --- a/repmgr-client.c +++ b/repmgr-client.c @@ -2850,15 +2850,25 @@ create_repmgr_extension(PGconn *conn) int check_server_version(PGconn *conn, char *server_type, bool exit_on_error, char *server_version_string) { - int conn_server_version_num = get_server_version(conn, server_version_string); + char version_string[MAXVERSIONSTR] = ""; + int conn_server_version_num = get_server_version(conn, version_string); + + /* Copy the version string, if the caller wants it */ + if (server_version_string != NULL) + strncpy(server_version_string, version_string, MAXVERSIONSTR); if (conn_server_version_num < MIN_SUPPORTED_VERSION_NUM) { if (conn_server_version_num > 0) + { log_error(_("%s requires %s to be PostgreSQL %s or later"), progname(), server_type, MIN_SUPPORTED_VERSION); + log_detail(_("%s server version is %s"), + server_type, + version_string); + } if (exit_on_error == true) { @@ -2869,6 +2879,38 @@ check_server_version(PGconn *conn, char *server_type, bool exit_on_error, char * return UNKNOWN_SERVER_VERSION_NUM; } + /* + * If it's clear a particular repmgr feature branch won't be able to support + * PostgreSQL from a particular PostgreSQL release onwards (e.g. 4.4 with PostgreSQL + * 12 and later due to recovery.conf removal), set MAX_UNSUPPORTED_VERSION and + * MAX_UNSUPPORTED_VERSION_NUM in "repmgr.h" to define the first PostgreSQL + * version which can't be suppored. + */ +#ifdef MAX_UNSUPPORTED_VERSION_NUM + if (conn_server_version_num >= MAX_UNSUPPORTED_VERSION_NUM) + { + if (conn_server_version_num > 0) + { + log_error(_("%s %s does not support PostgreSQL %s or later"), + progname(), + REPMGR_VERSION, + MAX_UNSUPPORTED_VERSION); + log_detail(_("%s server version is %s"), + server_type, + version_string); + log_hint(_("For details of supported versions see: https://repmgr.org/docs/current/install-requirements.html#INSTALL-COMPATIBILITY-MATRIX")); + } + + if (exit_on_error == true) + { + PQfinish(conn); + exit(ERR_BAD_CONFIG); + } + + return UNKNOWN_SERVER_VERSION_NUM; + } +#endif + return conn_server_version_num; }