From 22b9fbbdad857577c5df6d83b0a031859c8708a6 Mon Sep 17 00:00:00 2001 From: Shinya Kato Date: Tue, 10 Feb 2026 13:54:01 +0900 Subject: [PATCH v3 2/2] Use pg_current_xact_id() instead of deprecated txid_current() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace txid_current() with pg_current_xact_id() in test code. The previous commit added arithmetic operators for xid8, so places that need "xid + 1" can now use pg_current_xact_id() + 1 directly. Author: Shinya Kato Reviewed-by: Álvaro Herrera Reviewed-by: Tom Lane Discussion: https://postgr.es/m/CAOzEurQetW=-1+OnMo8baeVQF=-kAr-wNtFcgRNo+ErPk=xsDQ@mail.gmail.com --- contrib/pg_visibility/t/001_concurrent_transaction.pl | 2 +- contrib/test_decoding/expected/slot_creation_error.out | 6 +++--- contrib/test_decoding/specs/slot_creation_error.spec | 2 +- src/bin/pg_combinebackup/t/002_compare_backups.pl | 4 ++-- src/test/modules/commit_ts/expected/commit_timestamp.out | 4 ++-- .../modules/commit_ts/expected/commit_timestamp_1.out | 4 ++-- src/test/modules/commit_ts/sql/commit_timestamp.sql | 4 ++-- src/test/modules/xid_wraparound/t/004_notify_freeze.pl | 4 ++-- src/test/recovery/t/021_row_visibility.pl | 2 +- src/test/recovery/t/031_recovery_conflict.pl | 2 +- src/test/recovery/t/040_standby_failover_slots_sync.pl | 4 ++-- src/test/regress/expected/create_index.out | 2 +- src/test/regress/sql/create_index.sql | 2 +- src/test/subscription/t/035_conflicts.pl | 8 ++++---- 14 files changed, 25 insertions(+), 25 deletions(-) diff --git a/contrib/pg_visibility/t/001_concurrent_transaction.pl b/contrib/pg_visibility/t/001_concurrent_transaction.pl index 3aa556892a6..889cae927fd 100644 --- a/contrib/pg_visibility/t/001_concurrent_transaction.pl +++ b/contrib/pg_visibility/t/001_concurrent_transaction.pl @@ -30,7 +30,7 @@ my $bsession = $node->background_psql('other_database'); $bsession->query_safe( qq[ BEGIN; - SELECT txid_current(); + SELECT pg_current_xact_id(); ]); # Create a sample table and run vacuum diff --git a/contrib/test_decoding/expected/slot_creation_error.out b/contrib/test_decoding/expected/slot_creation_error.out index 25883b508fb..95591752371 100644 --- a/contrib/test_decoding/expected/slot_creation_error.out +++ b/contrib/test_decoding/expected/slot_creation_error.out @@ -2,7 +2,7 @@ Parsed test spec with 2 sessions starting permutation: s1_b s1_xid s2_init s1_view_slot s1_cancel_s2 s1_view_slot s1_c step s1_b: BEGIN; -step s1_xid: SELECT 'xid' FROM txid_current(); +step s1_xid: SELECT 'xid' FROM pg_current_xact_id(); ?column? -------- xid @@ -43,7 +43,7 @@ step s1_c: COMMIT; starting permutation: s1_b s1_xid s2_init s1_c s1_view_slot s1_drop_slot step s1_b: BEGIN; -step s1_xid: SELECT 'xid' FROM txid_current(); +step s1_xid: SELECT 'xid' FROM pg_current_xact_id(); ?column? -------- xid @@ -78,7 +78,7 @@ pg_drop_replication_slot starting permutation: s1_b s1_xid s2_init s1_terminate_s2 s1_c s1_view_slot step s1_b: BEGIN; -step s1_xid: SELECT 'xid' FROM txid_current(); +step s1_xid: SELECT 'xid' FROM pg_current_xact_id(); ?column? -------- xid diff --git a/contrib/test_decoding/specs/slot_creation_error.spec b/contrib/test_decoding/specs/slot_creation_error.spec index d1e35bf58b5..6983f24eae6 100644 --- a/contrib/test_decoding/specs/slot_creation_error.spec +++ b/contrib/test_decoding/specs/slot_creation_error.spec @@ -4,7 +4,7 @@ session "s1" setup { SET synchronous_commit=on; } step s1_b { BEGIN; } -step s1_xid { SELECT 'xid' FROM txid_current(); } +step s1_xid { SELECT 'xid' FROM pg_current_xact_id(); } step s1_c { COMMIT; } step s1_cancel_s2 { SELECT pg_cancel_backend(pid) diff --git a/src/bin/pg_combinebackup/t/002_compare_backups.pl b/src/bin/pg_combinebackup/t/002_compare_backups.pl index b509296a94a..42d252b2242 100644 --- a/src/bin/pg_combinebackup/t/002_compare_backups.pl +++ b/src/bin/pg_combinebackup/t/002_compare_backups.pl @@ -105,9 +105,9 @@ my $lsn = $primary->safe_psql('postgres', "SELECT pg_current_wal_lsn();"); # Make sure that the WAL segment containing that LSN has been archived. # PostgreSQL won't issue two consecutive XLOG_SWITCH records, and the backup -# just issued one, so call txid_current() to generate some WAL activity +# just issued one, so call pg_current_xact_id() to generate some WAL activity # before calling pg_switch_wal(). -$primary->safe_psql('postgres', 'SELECT txid_current();'); +$primary->safe_psql('postgres', 'SELECT pg_current_xact_id();'); $primary->safe_psql('postgres', 'SELECT pg_switch_wal()'); # Now wait for the LSN we chose above to be archived. diff --git a/src/test/modules/commit_ts/expected/commit_timestamp.out b/src/test/modules/commit_ts/expected/commit_timestamp.out index bb2fda27681..0d08e0684a2 100644 --- a/src/test/modules/commit_ts/expected/commit_timestamp.out +++ b/src/test/modules/commit_ts/expected/commit_timestamp.out @@ -71,7 +71,7 @@ SELECT * FROM pg_xact_commit_timestamp_origin('2'::xid); -- ok, NULL (1 row) -- Test transaction without replication origin -SELECT txid_current() as txid_no_origin \gset +SELECT pg_current_xact_id() as txid_no_origin \gset SELECT x.timestamp > '-infinity'::timestamptz AS ts_low, x.timestamp <= now() AS ts_high, roident != 0 AS valid_roident @@ -104,7 +104,7 @@ SELECT pg_replication_origin_session_setup('regress_commit_ts: get_origin'); (1 row) -SELECT txid_current() as txid_with_origin \gset +SELECT pg_current_xact_id() as txid_with_origin \gset SELECT x.timestamp > '-infinity'::timestamptz AS ts_low, x.timestamp <= now() AS ts_high, r.roname diff --git a/src/test/modules/commit_ts/expected/commit_timestamp_1.out b/src/test/modules/commit_ts/expected/commit_timestamp_1.out index f37e701f37a..21f09b89cac 100644 --- a/src/test/modules/commit_ts/expected/commit_timestamp_1.out +++ b/src/test/modules/commit_ts/expected/commit_timestamp_1.out @@ -63,7 +63,7 @@ SELECT * FROM pg_xact_commit_timestamp_origin('2'::xid); -- ok, NULL (1 row) -- Test transaction without replication origin -SELECT txid_current() as txid_no_origin \gset +SELECT pg_current_xact_id() as txid_no_origin \gset SELECT x.timestamp > '-infinity'::timestamptz AS ts_low, x.timestamp <= now() AS ts_high, roident != 0 AS valid_roident @@ -90,7 +90,7 @@ SELECT pg_replication_origin_session_setup('regress_commit_ts: get_origin'); (1 row) -SELECT txid_current() as txid_with_origin \gset +SELECT pg_current_xact_id() as txid_with_origin \gset SELECT x.timestamp > '-infinity'::timestamptz AS ts_low, x.timestamp <= now() AS ts_high, r.roname diff --git a/src/test/modules/commit_ts/sql/commit_timestamp.sql b/src/test/modules/commit_ts/sql/commit_timestamp.sql index 3bb7bb27a74..a2f0e68317d 100644 --- a/src/test/modules/commit_ts/sql/commit_timestamp.sql +++ b/src/test/modules/commit_ts/sql/commit_timestamp.sql @@ -34,7 +34,7 @@ SELECT * FROM pg_xact_commit_timestamp_origin('1'::xid); -- ok, NULL SELECT * FROM pg_xact_commit_timestamp_origin('2'::xid); -- ok, NULL -- Test transaction without replication origin -SELECT txid_current() as txid_no_origin \gset +SELECT pg_current_xact_id() as txid_no_origin \gset SELECT x.timestamp > '-infinity'::timestamptz AS ts_low, x.timestamp <= now() AS ts_high, roident != 0 AS valid_roident @@ -48,7 +48,7 @@ SELECT x.timestamp > '-infinity'::timestamptz AS ts_low, SELECT pg_replication_origin_create('regress_commit_ts: get_origin') != 0 AS valid_roident; SELECT pg_replication_origin_session_setup('regress_commit_ts: get_origin'); -SELECT txid_current() as txid_with_origin \gset +SELECT pg_current_xact_id() as txid_with_origin \gset SELECT x.timestamp > '-infinity'::timestamptz AS ts_low, x.timestamp <= now() AS ts_high, r.roname diff --git a/src/test/modules/xid_wraparound/t/004_notify_freeze.pl b/src/test/modules/xid_wraparound/t/004_notify_freeze.pl index d0a1f1fe2fc..9a8300186f7 100644 --- a/src/test/modules/xid_wraparound/t/004_notify_freeze.pl +++ b/src/test/modules/xid_wraparound/t/004_notify_freeze.pl @@ -35,9 +35,9 @@ for my $i (1 .. 10) } # Consume enough XIDs to trigger truncation, and one more with -# 'txid_current' to bump up the freeze horizon. +# 'pg_current_xact_id' to bump up the freeze horizon. $node->safe_psql('postgres', 'select consume_xids(10000000);'); -$node->safe_psql('postgres', 'select txid_current()'); +$node->safe_psql('postgres', 'select pg_current_xact_id()'); # Remember current datfrozenxid before vacuum freeze so that we can # check that it is advanced. (Taking the min() this way assumes that diff --git a/src/test/recovery/t/021_row_visibility.pl b/src/test/recovery/t/021_row_visibility.pl index 0a4d22b3698..9626d431852 100644 --- a/src/test/recovery/t/021_row_visibility.pl +++ b/src/test/recovery/t/021_row_visibility.pl @@ -94,7 +94,7 @@ UPDATE test_visibility SET data = 'first update' RETURNING data; qr/^UPDATE 1$/m), 'UPDATE'); -$node_primary->psql('postgres', "SELECT txid_current();"); # ensure WAL flush +$node_primary->psql('postgres', "SELECT pg_current_xact_id();"); # ensure WAL flush $node_primary->wait_for_catchup($node_standby); ok( send_query_and_wait( diff --git a/src/test/recovery/t/031_recovery_conflict.pl b/src/test/recovery/t/031_recovery_conflict.pl index 7a740f69806..3f52b5c82b6 100644 --- a/src/test/recovery/t/031_recovery_conflict.pl +++ b/src/test/recovery/t/031_recovery_conflict.pl @@ -239,7 +239,7 @@ BEGIN; LOCK TABLE $table2; PREPARE TRANSACTION 'lock'; INSERT INTO $table1(a) VALUES (170); -SELECT txid_current(); +SELECT pg_current_xact_id(); ]); $node_primary->wait_for_replay_catchup($node_standby); diff --git a/src/test/recovery/t/040_standby_failover_slots_sync.pl b/src/test/recovery/t/040_standby_failover_slots_sync.pl index 47d64d05ad1..eb2dde8050d 100644 --- a/src/test/recovery/t/040_standby_failover_slots_sync.pl +++ b/src/test/recovery/t/040_standby_failover_slots_sync.pl @@ -433,11 +433,11 @@ $standby1->safe_psql('postgres', "SELECT pg_sync_replication_slots();"); $primary->safe_psql( 'postgres', qq( BEGIN; - SELECT txid_current(); + SELECT pg_current_xact_id(); SELECT pg_log_standby_snapshot(); COMMIT; BEGIN; - SELECT txid_current(); + SELECT pg_current_xact_id(); SELECT pg_log_standby_snapshot(); COMMIT; )); diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out index 55538c4c41e..31cd896dc17 100644 --- a/src/test/regress/expected/create_index.out +++ b/src/test/regress/expected/create_index.out @@ -1452,7 +1452,7 @@ COMMIT; CREATE FUNCTION predicate_stable() RETURNS bool IMMUTABLE LANGUAGE plpgsql AS $$ BEGIN - EXECUTE 'SELECT txid_current()'; + EXECUTE 'SELECT pg_current_xact_id()'; RETURN true; END; $$; CREATE INDEX CONCURRENTLY concur_index8 ON concur_heap (f1) diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql index 82e4062a215..96e2aee98b2 100644 --- a/src/test/regress/sql/create_index.sql +++ b/src/test/regress/sql/create_index.sql @@ -517,7 +517,7 @@ COMMIT; CREATE FUNCTION predicate_stable() RETURNS bool IMMUTABLE LANGUAGE plpgsql AS $$ BEGIN - EXECUTE 'SELECT txid_current()'; + EXECUTE 'SELECT pg_current_xact_id()'; RETURN true; END; $$; CREATE INDEX CONCURRENTLY concur_index8 ON concur_heap (f1) diff --git a/src/test/subscription/t/035_conflicts.pl b/src/test/subscription/t/035_conflicts.pl index 426ad74cf33..68c511b6767 100644 --- a/src/test/subscription/t/035_conflicts.pl +++ b/src/test/subscription/t/035_conflicts.pl @@ -332,7 +332,7 @@ like( 'update target row was deleted in tab'); # Remember the next transaction ID to be assigned -my $next_xid = $node_A->safe_psql('postgres', "SELECT txid_current() + 1;"); +my $next_xid = $node_A->safe_psql('postgres', "SELECT pg_current_xact_id() + 1;"); # Confirm that the xmin value is advanced to the latest nextXid. If no # transactions are running, the apply worker selects nextXid as the candidate @@ -391,7 +391,7 @@ $node_A->safe_psql('postgres', "ALTER SUBSCRIPTION $subname_AB REFRESH PUBLICATION"); # Remember the next transaction ID to be assigned -$next_xid = $node_A->safe_psql('postgres', "SELECT txid_current() + 1;"); +$next_xid = $node_A->safe_psql('postgres', "SELECT pg_current_xact_id() + 1;"); # Confirm that the xmin value is advanced to the latest nextXid. If no # transactions are running, the apply worker selects nextXid as the candidate @@ -540,7 +540,7 @@ if ($injection_points_supported != 0) # Remember the next transaction ID to be assigned $next_xid = - $node_A->safe_psql('postgres', "SELECT txid_current() + 1;"); + $node_A->safe_psql('postgres', "SELECT pg_current_xact_id() + 1;"); # Confirm that the xmin value is advanced to the latest nextXid after the # prepared transaction on the publisher has been committed. @@ -591,7 +591,7 @@ $node_B->safe_psql('postgres', "INSERT INTO tab VALUES (5, 5);"); # Advance the xid on Node A to trigger the next cycle of oldest_nonremovable_xid # advancement. -$node_A->safe_psql('postgres', "SELECT txid_current() + 1;"); +$node_A->safe_psql('postgres', "SELECT pg_current_xact_id() + 1;"); $log_offset = -s $node_A->logfile; -- 2.47.3