Improve checks for GUC recovery_target_timeline
authorMichael Paquier <michael@paquier.xyz>
Thu, 3 Jul 2025 02:14:20 +0000 (11:14 +0900)
committerMichael Paquier <michael@paquier.xyz>
Thu, 3 Jul 2025 02:14:20 +0000 (11:14 +0900)
commitfd7d7b719137b5c427681a50c0a0ac2d745b68bd
tree999583ebba5990b105c36f895fbe88e645a315a2
parent0da29e4cb161f78a5ef534b3fb4467756a422e25
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@pgmasters.net>
Discussion: https://postgr.es/m/e5d472c7-e9be-4710-8dc4-ebe721b62cea@pgbackrest.org
src/backend/access/transam/xlogrecovery.c
src/test/recovery/t/003_recovery_targets.pl