pg.ddx.io  pgbackrest/pgbackrest GitHub issues and pull requests  
help / color / mirror / Atom feed
[pgbackrest/pgbackrest] PR #2925: Check PostgreSQL version before restore modifies the data directory.
10+ messages / 2 participants
[nested] [flat]

* [pgbackrest/pgbackrest] PR #2925: Check PostgreSQL version before restore modifies the data directory.
@ 2026-11-17 15:20 "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>
  0 siblings, 0 replies; 10+ messages in thread

From: dwsteele (@dwsteele) @ 2026-11-17 15:20 UTC (permalink / raw)
  To: pgbackrest/pgbackrest <noreply+pgbackrest-pgbackrest@github.com>

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.inc index 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.c index 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.h index 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.c index 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.c index 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"); } // *****************************************************************************************************************************
^ permalink raw [nested|flat] 10+ messages in thread

* Re: [pgbackrest/pgbackrest] PR #2925: Check PostgreSQL version before restore modifies the data directory.
@ 2026-11-17 15:20 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>
  8 siblings, 0 replies; 10+ messages in thread

From: dwsteele (@dwsteele) @ 2026-11-17 15:20 UTC (permalink / raw)
  To: pgbackrest/pgbackrest <noreply+pgbackrest-pgbackrest@github.com>

@dwsteele assigned @dwsteele.

^ permalink  raw  [nested|flat] 10+ messages in thread

* Re: [pgbackrest/pgbackrest] PR #2925: Check PostgreSQL version before restore modifies the data directory.
@ 2026-11-17 15:20 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>
  8 siblings, 0 replies; 10+ messages in thread

From: dwsteele (@dwsteele) @ 2026-11-17 15:20 UTC (permalink / raw)
  To: pgbackrest/pgbackrest <noreply+pgbackrest-pgbackrest@github.com>

@dwsteele applied label "enhancement".

^ permalink  raw  [nested|flat] 10+ messages in thread

* Re: [pgbackrest/pgbackrest] PR #2925: Check PostgreSQL version before restore modifies the data directory.
@ 2026-11-17 15:20 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>
  8 siblings, 0 replies; 10+ messages in thread

From: dwsteele (@dwsteele) @ 2026-11-17 15:20 UTC (permalink / raw)
  To: pgbackrest/pgbackrest <noreply+pgbackrest-pgbackrest@github.com>

@dwsteele applied label "module [core]".

^ permalink  raw  [nested|flat] 10+ messages in thread

* Re: [pgbackrest/pgbackrest] PR #2925: Check PostgreSQL version before restore modifies the data directory.
@ 2026-11-17 15:20 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>
  8 siblings, 0 replies; 10+ messages in thread

From: dwsteele (@dwsteele) @ 2026-11-17 15:20 UTC (permalink / raw)
  To: pgbackrest/pgbackrest <noreply+pgbackrest-pgbackrest@github.com>

@dwsteele set milestone to "2.61.0".

^ permalink  raw  [nested|flat] 10+ messages in thread

* Re: [pgbackrest/pgbackrest] PR #2925: Check PostgreSQL version before restore modifies the data directory.
@ 2026-11-17 15:20 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>
  8 siblings, 0 replies; 10+ messages in thread

From: dwsteele (@dwsteele) @ 2026-11-17 15:20 UTC (permalink / raw)
  To: pgbackrest/pgbackrest <noreply+pgbackrest-pgbackrest@github.com>

@dwsteele requested a review.

^ permalink  raw  [nested|flat] 10+ messages in thread

* Re: [pgbackrest/pgbackrest] PR #2925 (approved): Check PostgreSQL version before restore modifies the data directory.
@ 2026-11-17 16:40 ` "hunleyd (@hunleyd)" <noreply+hunleyd@github.com>
  8 siblings, 0 replies; 10+ messages in thread

From: hunleyd (@hunleyd) @ 2026-11-17 16:40 UTC (permalink / raw)
  To: pgbackrest/pgbackrest <noreply+pgbackrest-pgbackrest@github.com>



^ permalink  raw  [nested|flat] 10+ messages in thread

* Re: [pgbackrest/pgbackrest] PR #2925: Check PostgreSQL version before restore modifies the data directory.
@ 2026-11-17 17:10 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>
  8 siblings, 0 replies; 10+ messages in thread

From: dwsteele (@dwsteele) @ 2026-11-17 17:10 UTC (permalink / raw)
  To: pgbackrest/pgbackrest <noreply+pgbackrest-pgbackrest@github.com>

@dwsteele removed a review request.

^ permalink  raw  [nested|flat] 10+ messages in thread

* Re: [pgbackrest/pgbackrest] PR #2925: Check PostgreSQL version before restore modifies the data directory.
@ 2026-11-17 17:26 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>
  8 siblings, 0 replies; 10+ messages in thread

From: dwsteele (@dwsteele) @ 2026-11-17 17:26 UTC (permalink / raw)
  To: pgbackrest/pgbackrest <noreply+pgbackrest-pgbackrest@github.com>

@dwsteele merged this (commit 0592b4f935da).

^ permalink  raw  [nested|flat] 10+ messages in thread

* Re: [pgbackrest/pgbackrest] PR #2925: Check PostgreSQL version before restore modifies the data directory.
@ 2026-11-17 17:26 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>
  8 siblings, 0 replies; 10+ messages in thread

From: dwsteele (@dwsteele) @ 2026-11-17 17:26 UTC (permalink / raw)
  To: pgbackrest/pgbackrest <noreply+pgbackrest-pgbackrest@github.com>

@dwsteele closed this.

^ permalink  raw  [nested|flat] 10+ messages in thread


end of thread, other threads:[~2026-11-17 17:26 UTC | newest]

Thread overview: 10+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-11-17 15:20 [pgbackrest/pgbackrest] PR #2925: Check PostgreSQL version before restore modifies the data directory. "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>
2026-11-17 15:20 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>
2026-11-17 15:20 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>
2026-11-17 15:20 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>
2026-11-17 15:20 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>
2026-11-17 15:20 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>
2026-11-17 16:40 ` Re: [pgbackrest/pgbackrest] PR #2925 (approved): Check PostgreSQL version before restore modifies the data directory. "hunleyd (@hunleyd)" <noreply+hunleyd@github.com>
2026-11-17 17:10 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>
2026-11-17 17:26 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>
2026-11-17 17:26 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox