The following bug has been logged on the website:
Bug reference: 18212
Logged by: Egor Chindyaskin
Email address: kyzevan23@mail.ru
PostgreSQL version: 16.1
Operating system: Ubuntu 23.10
Description:
Hello! Recently, Me and Andrew Bille came across a situation where the
txid_status() and pg_xact_status() functions return invalid status of the
specified transaction if xid is very far ahead.
The following script reproduces the situation:
# This script uses pg_resetwal and dd. This is a hack to move xid far
ahead
PGDATA=/tmp/pgsql/data
killall postgres
rm -rf $PGDATA
initdb -U postgres -k -D $PGDATA
pg_ctl -D $PGDATA -l log start
psql -U postgres -c "UPDATE pg_database SET datallowconn = 't' WHERE datname
= 'template0';"
pg_ctl -D $PGDATA -l log stop
pg_resetwal -x 536870911 -l 000000010000000000000004 $PGDATA
dd if=/dev/zero of=$PGDATA/pg_xact/01FF bs=8192 count=2048
pg_ctl -D $PGDATA -l log start
vacuumdb --all -U postgres
pg_ctl -D $PGDATA -l log stop
pg_resetwal -x 1073741822 -l 000000010000000000000004 $PGDATA
dd if=/dev/zero of=$PGDATA/pg_xact/03FF bs=8192 count=2048
pg_ctl -D $PGDATA -l log start
vacuumdb --all -U postgres
pg_ctl -D $PGDATA -l log stop
pg_resetwal -x 1610612733 -l 000000010000000000000004 $PGDATA
dd if=/dev/zero of=$PGDATA/pg_xact/05FF bs=8192 count=2048
pg_ctl -D $PGDATA -l log start
vacuumdb --all -U postgres
pg_ctl -D $PGDATA -l log stop
pg_resetwal -x 2147484382 -l 000000010000000000000004 $PGDATA
dd if=/dev/zero of=$PGDATA/pg_xact/0800 bs=8192 count=2048
pg_ctl -D $PGDATA -l log start
vacuumdb --all -U postgres
psql -U postgres -c "SELECT txid_current()"
psql -U postgres -c "SELECT txid_status(3)" -c "SELECT
pg_xact_status('3'::xid8)"
As a result, we get that, instead of the expected NULL, the functions return
the "in progress" status of transaction 3, which is far in the past:
...
txid_current
--------------
2147484382
(1 row)
txid_status
-------------
in progress
(1 row)
pg_xact_status
----------------
in progress
(1 row)
---
Best regards,
Egor Chindyaskin
Postgres Professional: http://postgrespro.com