From: dwsteele (@dwsteele) <noreply+dwsteele@github.com>
To: pgbackrest/pgbackrest <noreply+pgbackrest-pgbackrest@github.com>
Subject: [pgbackrest/pgbackrest] PR #2925: Check PostgreSQL version before restore modifies the data directory.
Date: Tue, 17 Nov 2026 15:20:26 +0000
Message-ID: <gh-pgbackrest-pgbackrest-2925@github.com> (raw)
Restoring a backup of an unsupported PostgreSQL version (e.g. 9.6) failed in manifestSave() when pgControlVersion() could not find an interface for the version. By then restoreCleanBuild() had already modified PGDATA (e.g. removed pg_control and stray files with --delta) and an empty temporary manifest was left behind.
Add pgVersionCheck() and call it in restoreManifestValidate() to error before PGDATA is modified.
inline patch 1: src/command/restore/validate.c.inc, src/postgres/interface.c, src/postgres/interface.h and 2 more (+38/-1 lines) download inline-1.patchdiff --git a/src/command/restore/validate.c.inc b/src/command/restore/validate.c.incindex 5a1d4c898b..87f1b40fd5 100644--- a/src/command/restore/validate.c.inc+++ b/src/command/restore/validate.c.inc@@ -69,6 +69,9 @@ restoreManifestValidate(const Manifest *const manifest, const String *const back
"HINT: this indicates some sort of corruption (at the very least paths have been renamed).",
strZ(backupSet), strZ(data->backupLabel));
}
++ // Check that the PostgreSQL version is supported+ pgVersionCheck(data->pgVersion);
}
MEM_CONTEXT_TEMP_END();
diff --git a/src/postgres/interface.c b/src/postgres/interface.cindex 7952ca5057..9a150342a3 100644--- a/src/postgres/interface.c+++ b/src/postgres/interface.c@@ -452,6 +452,19 @@ pgControlVersion(const unsigned int pgVersion)
FUNCTION_TEST_RETURN(UINT32, pgInterfaceVersion(pgVersion)->controlVersion);
}
+/**********************************************************************************************************************************/+FN_EXTERN void+pgVersionCheck(const unsigned int pgVersion)+{+ FUNCTION_TEST_BEGIN();+ FUNCTION_TEST_PARAM(UINT, pgVersion);+ FUNCTION_TEST_END();++ pgInterfaceVersion(pgVersion);++ FUNCTION_TEST_RETURN_VOID();+}+
/***********************************************************************************************************************************
These WAL header fields are common to all versions of PostgreSQL, so we can use them to generate error messages when the WAL magic
cannot be found.
diff --git a/src/postgres/interface.h b/src/postgres/interface.hindex ced51968fd..ff5f2b3f06 100644--- a/src/postgres/interface.h+++ b/src/postgres/interface.h@@ -132,6 +132,9 @@ FN_EXTERN void pgControlCheckpointInvalidate(Buffer *buffer, const String *pgVer
// Get the control version for a PostgreSQL version
FN_EXTERN uint32_t pgControlVersion(unsigned int pgVersion);
+// Throws an error if version is not supported+FN_EXTERN void pgVersionCheck(unsigned int pgVersion);+
// Convert version string to version number and vice versa
FN_EXTERN unsigned int pgVersionFromStr(const String *version);
FN_EXTERN String *pgVersionToStr(unsigned int version);
diff --git a/test/src/module/command/restoreTest.c b/test/src/module/command/restoreTest.cindex 60466dd7c2..f937ae318e 100644--- a/test/src/module/command/restoreTest.c+++ b/test/src/module/command/restoreTest.c@@ -711,6 +711,17 @@ testRun(void)
restoreManifestValidate(manifest, STRDEF("20161219-212741F_20161219-212918I")), FormatError,
"requested backup '20161219-212741F_20161219-212918I' and manifest label '20161219-212741F' do not match\n"
"HINT: this indicates some sort of corruption (at the very least paths have been renamed).");
++ // -------------------------------------------------------------------------------------------------------------------------+ TEST_TITLE("error on unsupported version");++ manifest = testManifestMinimal(STRDEF("20161219-212741F"), 90600, STRDEF("/pg"));++ TEST_ERROR(+ restoreManifestValidate(manifest, STRDEF("20161219-212741F")), VersionNotSupportedError,+ "invalid PostgreSQL version 9.6\n"+ "HINT: is this version of PostgreSQL supported?\n"+ "HINT: is pgBackRest up to date on all hosts?");
}
// *****************************************************************************************************************************
diff --git a/test/src/module/postgres/interfaceTest.c b/test/src/module/postgres/interfaceTest.cindex 91f1dafac5..a10ac23746 100644--- a/test/src/module/postgres/interfaceTest.c+++ b/test/src/module/postgres/interfaceTest.c@@ -53,7 +53,7 @@ testRun(void)
}
// *****************************************************************************************************************************
- if (testBegin("pgControlVersion()"))+ if (testBegin("pgControlVersion() and pgVersionCheck()"))
{
TEST_ERROR(
pgControlVersion(70300), VersionNotSupportedError,
@@ -63,6 +63,13 @@ testRun(void)
TEST_RESULT_UINT(pgControlVersion(PG_VERSION_10), 1002, "10 control version");
TEST_RESULT_UINT(pgControlVersion(PG_VERSION_11), 1100, "11 control version");
TEST_RESULT_UINT(pgControlVersion(PG_VERSION_17), 1700, "17 control version");
++ TEST_ERROR(+ pgVersionCheck(90600), VersionNotSupportedError,+ "invalid PostgreSQL version 9.6\n"+ "HINT: is this version of PostgreSQL supported?\n"+ "HINT: is pgBackRest up to date on all hosts?");+ TEST_RESULT_VOID(pgVersionCheck(PG_VERSION_10), "10 supported");
}
// *****************************************************************************************************************************