From e27a6a91e0444bf70c3203b1d7efef6585917df7 Mon Sep 17 00:00:00 2001 From: Grigory Smolkin Date: Sun, 20 Jun 2021 02:13:35 +0300 Subject: [PATCH] [Issue #400] PostgreSQL 14 support --- src/backup.c | 4 ++-- src/catalog.c | 4 ++-- src/merge.c | 2 +- src/parsexlog.c | 12 ++++++++++++ src/show.c | 4 ++-- src/utils/pgut.c | 15 ++++++++++++++- tests/helpers/ptrack_helpers.py | 4 ++++ 7 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/backup.c b/src/backup.c index 6f1aa867..83785c1c 100644 --- a/src/backup.c +++ b/src/backup.c @@ -725,7 +725,7 @@ pgdata_basic_setup(ConnectionOptions conn_opt, PGNodeInfo *nodeInfo) elog(WARNING, "Current PostgreSQL role is superuser. " "It is not recommended to run backup or checkdb as superuser."); - StrNCpy(current.server_version, nodeInfo->server_version_str, + strlcpy(current.server_version, nodeInfo->server_version_str, sizeof(current.server_version)); return cur_conn; @@ -761,7 +761,7 @@ do_backup(pgSetBackupParams *set_backup_params, current.status = BACKUP_STATUS_RUNNING; current.start_time = current.backup_id; - StrNCpy(current.program_version, PROGRAM_VERSION, + strlcpy(current.program_version, PROGRAM_VERSION, sizeof(current.program_version)); current.compress_alg = instance_config.compress_alg; diff --git a/src/catalog.c b/src/catalog.c index 3ea4d9bc..3ba17e9f 100644 --- a/src/catalog.c +++ b/src/catalog.c @@ -2648,14 +2648,14 @@ readBackupControlFile(const char *path) if (program_version) { - StrNCpy(backup->program_version, program_version, + strlcpy(backup->program_version, program_version, sizeof(backup->program_version)); pfree(program_version); } if (server_version) { - StrNCpy(backup->server_version, server_version, + strlcpy(backup->server_version, server_version, sizeof(backup->server_version)); pfree(server_version); } diff --git a/src/merge.c b/src/merge.c index 3fd5b13a..f351975d 100644 --- a/src/merge.c +++ b/src/merge.c @@ -735,7 +735,7 @@ merge_chain(parray *parent_chain, pgBackup *full_backup, pgBackup *dest_backup, * We cannot set backup status to OK just yet, * because it still has old start_time. */ - StrNCpy(full_backup->program_version, PROGRAM_VERSION, + strlcpy(full_backup->program_version, PROGRAM_VERSION, sizeof(full_backup->program_version)); full_backup->parent_backup = INVALID_BACKUP_ID; full_backup->start_lsn = dest_backup->start_lsn; diff --git a/src/parsexlog.c b/src/parsexlog.c index 8dfb2c78..19078fb6 100644 --- a/src/parsexlog.c +++ b/src/parsexlog.c @@ -1798,6 +1798,18 @@ extractPageInfo(XLogReaderState *record, XLogReaderData *reader_data, * source system. */ } + else if (rmid == RM_XACT_ID && + ((rminfo & XLOG_XACT_OPMASK) == XLOG_XACT_COMMIT || + (rminfo & XLOG_XACT_OPMASK) == XLOG_XACT_COMMIT_PREPARED || + (rminfo & XLOG_XACT_OPMASK) == XLOG_XACT_ABORT || + (rminfo & XLOG_XACT_OPMASK) == XLOG_XACT_ABORT_PREPARED)) + { + /* + * These records can include "dropped rels". We can safely ignore + * them, we will see that they are missing and copy them from the + * source. + */ + } else if (info & XLR_SPECIAL_REL_UPDATE) { /* diff --git a/src/show.c b/src/show.c index c1482772..496c9d83 100644 --- a/src/show.c +++ b/src/show.c @@ -552,7 +552,7 @@ show_instance_plain(const char *instance_name, parray *backup_list, bool show_na time2iso(row->recovery_time, lengthof(row->recovery_time), backup->recovery_time, false); else - StrNCpy(row->recovery_time, "----", sizeof(row->recovery_time)); + strlcpy(row->recovery_time, "----", sizeof(row->recovery_time)); widths[cur] = Max(widths[cur], strlen(row->recovery_time)); cur++; @@ -587,7 +587,7 @@ show_instance_plain(const char *instance_name, parray *backup_list, bool show_na pretty_time_interval(difftime(backup->end_time, backup->start_time), row->duration, lengthof(row->duration)); else - StrNCpy(row->duration, "----", sizeof(row->duration)); + strlcpy(row->duration, "----", sizeof(row->duration)); widths[cur] = Max(widths[cur], strlen(row->duration)); cur++; diff --git a/src/utils/pgut.c b/src/utils/pgut.c index e1e52b24..1d8845c2 100644 --- a/src/utils/pgut.c +++ b/src/utils/pgut.c @@ -16,6 +16,10 @@ #include "libpq/pqsignal.h" #include "pqexpbuffer.h" +#if PG_VERSION_NUM >= 140000 +#include "common/string.h" +#endif + #include #include "pgut.h" @@ -75,7 +79,16 @@ prompt_for_password(const char *username) password = NULL; } -#if PG_VERSION_NUM >= 100000 +#if PG_VERSION_NUM >= 140000 + if (username == NULL) + password = simple_prompt("Password: ", false); + else + { + char message[256]; + snprintf(message, lengthof(message), "Password for user %s: ", username); + password = simple_prompt(message , false); + } +#elif PG_VERSION_NUM >= 100000 password = (char *) pgut_malloc(sizeof(char) * 100 + 1); if (username == NULL) simple_prompt("Password: ", password, 100, false); diff --git a/tests/helpers/ptrack_helpers.py b/tests/helpers/ptrack_helpers.py index b6dc6d02..bf84f266 100644 --- a/tests/helpers/ptrack_helpers.py +++ b/tests/helpers/ptrack_helpers.py @@ -139,6 +139,10 @@ def slow_start(self, replica=False): except testgres.QueryException as e: if 'database system is starting up' in e.message: pass + elif 'FATAL: the database system is not accepting connections' in e.message: + pass + elif replica and 'Hot standby mode is disabled' in e.message: + raise e else: raise e