Improve checks for GUC recovery_target_xid

From: David Steele <david(at)pgbackrest(dot)org>
To: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Improve checks for GUC recovery_target_xid
Date: 2026-02-20 05:41:59
Message-ID: f14463ab-990b-4ae9-a177-998d2677aae0@pgbackrest.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hackers,

Currently check_recovery_target_xid() converts invalid values to 0. So,
for example, the following configuration added to postgresql.conf
followed by a startup:

recovery_target_xid = 'bogus'
recovery_target_xid = '1.1'
recovery_target_xid = '0'

... does not generate an error but recovery does not complete. There are
many values that can prevent recovery from completing but we should at
least catch obvious misconfiguration by the user.

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

Also add a comment that truncation of the input value is expected since
users will generally be using the output from pg_current_xact_id() (or
similar) to set recovery_target_xid (just as our tests do).

This patch was promised in [1] -- here at last!

Regards,
-David

[1]
https://www.postgresql.org/message-id/cf04b7c6-7774-4ffb-86f5-ca85462d5fd6%40pgbackrest.org

Attachment Content-Type Size
recovery-target-xid-v1.patch text/plain 3.8 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2026-02-20 05:45:41 Re: Add into REFRESH PUBLICATION parameter exception_behaviour
Previous Message Ashutosh Sharma 2026-02-20 05:26:09 Re: Skipping schema changes in publication