Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6db2703

Browse files
committed
Fix portability issues with parsing of recovery_target_xid
The parsing of this parameter has been using strtoul(), which is notportable across platforms. On most Unix platforms, unsigned long has asize of 64 bits, while on Windows it is 32 bits. It is common inrecovery scenarios to rely on the output of txid_current() or even thenewer pg_current_xact_id() to get a transaction ID for setting uprecovery_target_xid. The value returned by those functions includes theepoch in the computed result, which would cause strtoul() to fail whereunsigned long has a size of 32 bits once the epoch is incremented.WAL records and 2PC data include only information about 32-bit XIDs andit is not possible to have XIDs across more than one epoch, sodiscarding the high bits from the transaction ID set has no impact onrecovery. On the contrary, the use of strtoul() prevents a consistentbehavior across platforms depending on the size of unsigned long.This commit changes the parsing of recovery_target_xid to usepg_strtouint64() instead, available down to 9.6. There is one TAP teststressing recovery with recovery_target_xid, where a tweak based onpg_reset{xlog,wal} is added to bump the XID epoch so as this change getstested, as per an idea from Alexander Lakhin.Reported-by: Alexander LakhinDiscussion:https://postgr.es/m/16780-107fd0c0385b1035@postgresql.orgBackpatch-through: 9.6
1 parentff76983 commit6db2703

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

‎src/backend/utils/misc/guc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11938,7 +11938,7 @@ check_recovery_target_xid(char **newval, void **extra, GucSource source)
1193811938
TransactionId*myextra;
1193911939

1194011940
errno=0;
11941-
xid= (TransactionId)strtoul(*newval,NULL,0);
11941+
xid= (TransactionId)pg_strtouint64(*newval,NULL,0);
1194211942
if (errno==EINVAL||errno==ERANGE)
1194311943
return false;
1194411944

‎src/test/recovery/t/003_recovery_targets.pl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ sub test_recovery_standby
5050
my$node_primary = get_new_node('primary');
5151
$node_primary->init(has_archiving=> 1,allows_streaming=> 1);
5252

53+
# Bump the transaction ID epoch. This is useful to stress the portability
54+
# of recovery_target_xid parsing.
55+
system_or_bail('pg_resetwal','--epoch','1',$node_primary->data_dir);
56+
5357
# Start it
5458
$node_primary->start;
5559

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp