pgsql: Improve checks for GUC recovery_target_timeline

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Improve checks for GUC recovery_target_timeline
Date: 2025-07-03 02:24:03
Message-ID: E1uX9cI-004RXy-2v@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Improve checks for GUC recovery_target_timeline

Currently check_recovery_target_timeline() converts any value that is
not "current", "latest", or a valid integer to 0. So, for example, the
following configuration added to postgresql.conf followed by a startup:
recovery_target_timeline = 'bogus'
recovery_target_timeline = '9999999999'

... results in the following error patterns:
FATAL: 22023: recovery target timeline 0 does not exist
FATAL: 22023: recovery target timeline 1410065407 does not exist

This is confusing, because the server does not reflect the intention of
the user, and just reports incorrect data unrelated to the GUC.

The origin of the problem is that we do not perform a range check in the
GUC value passed-in for recovery_target_timeline. This commit improves
the situation by using strtou64() and by providing stricter range
checks. Some test cases are added for the cases of an incorrect, an
upper-bound and a lower-bound timeline value, checking the sanity of the
reports based on the contents of the server logs.

Author: David Steele <david(at)pgmasters(dot)net>
Discussion: https://postgr.es/m/e5d472c7-e9be-4710-8dc4-ebe721b62cea@pgbackrest.org

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/fd7d7b719137b5c427681a50c0a0ac2d745b68bd

Modified Files
--------------
src/backend/access/transam/xlogrecovery.c | 18 +++++++++--
src/test/recovery/t/003_recovery_targets.pl | 50 +++++++++++++++++++++++++++++
2 files changed, 65 insertions(+), 3 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Fujii Masao 2025-07-03 06:30:01 pgsql: Support multi-line headers in COPY FROM command.
Previous Message Richard Guo 2025-07-03 01:58:45 pgsql: Enable use of Memoize for ANTI joins