BUG #18509: Logical decoding behaves badly when processing a change record for a table with altered column - Mailing list pgsql-bugs

From PG Bug reporting form
Subject BUG #18509: Logical decoding behaves badly when processing a change record for a table with altered column
Date
Msg-id 18509-983f064d174ea880@postgresql.org
Whole thread Raw
List pgsql-bugs
The following bug has been logged on the website:

Bug reference:      18509
Logged by:          Alexander Lakhin
Email address:      exclusion@gmail.com
PostgreSQL version: 17beta1
Operating system:   Ubuntu 22.04
Description:

The following script:
numjobs=10
for ((j=1;j<=numjobs;j++)); do
psql -c "CREATE TABLE t$j(t1 text, i2 int);"
done

for i in `seq 50`; do
echo "iteration $i";

for ((j=1;j<=numjobs;j++)); do
cat << EOF | psql >/dev/null &
BEGIN;
SELECT txid_current();
SELECT pg_sleep(0.01);
EOF

cat << EOF | psql >/dev/null &
ALTER TABLE t$j RENAME COLUMN t1 TO i1;
SELECT pg_sleep(0.001);
ALTER TABLE t$j ALTER COLUMN i1 TYPE int4 USING (i1::int4);
SELECT pg_sleep(0.001);
INSERT INTO t$j(i1) VALUES (1);
SELECT pg_sleep(0.001);
INSERT INTO t$j(i1) VALUES (1);
SELECT pg_sleep(0.001);
INSERT INTO t$j(i1) VALUES (1);
EOF

cat << EOF | psql >/dev/null &
SELECT 'init' FROM pg_create_logical_replication_slot(
  'regression_slot$j', 'test_decoding');

SELECT data FROM pg_logical_slot_get_changes(
  'regression_slot$j', NULL,NULL);
EOF
done
wait

for ((j=1;j<=numjobs;j++)); do
cat << EOF | psql >/dev/null
SELECT pg_drop_replication_slot('regression_slot$j');
ALTER TABLE t$j ALTER COLUMN i1 TYPE text USING (i1::text);
ALTER TABLE t$j RENAME COLUMN i1 TO t1;
EOF
done

grep 'TRAP' server.log  && { break; }
done

produces errors like:
2024-06-14 17:10:58.349 UTC|law|regression|666c79a2.3fe3a4|ERROR:  could not
map filenumber "base/16384/16453" to relation OID
2024-06-14 17:10:58.349 UTC|law|regression|666c79a2.3fe3a4|BACKTRACE:
ReorderBufferProcessTXN at reorderbuffer.c:2218:7
ReorderBufferReplay at reorderbuffer.c:2701:2
ReorderBufferCommit at reorderbuffer.c:2725:2
DecodeCommit at decode.c:733:3
xact_decode at decode.c:243:5
LogicalDecodingProcessRecord at decode.c:123:1
pg_logical_slot_get_changes_guts at logicalfuncs.c:269:7
pg_logical_slot_get_changes at logicalfuncs.c:334:1
...
2024-06-14 17:10:58.349 UTC|law|regression|666c79a2.3fe3a4|STATEMENT:
SELECT data FROM pg_logical_slot_get_changes(
      'regression_slot3', NULL,NULL);

and an assertion failure:
TRAP: failed Assert("TupleDescAttr(relation->rd_att, i)->attcacheoff ==
-1"), File: "relcache.c", Line: 673, PID: 4187156
...
#3  0x00007f03c690e476 in __GI_raise (sig=sig@entry=6) at
../sysdeps/posix/raise.c:26
#4  0x00007f03c68f47f3 in __GI_abort () at ./stdlib/abort.c:79
#5  0x000055c3c86d95f1 in ExceptionalCondition (
    conditionName=0x55c3c8930198 "TupleDescAttr(relation->rd_att,
i)->attcacheoff == -1", 
    fileName=0x55c3c8930108 "relcache.c", lineNumber=673) at assert.c:66
#6  0x000055c3c86c2dd3 in RelationBuildTupleDesc (relation=0x7f03b75dd1a8)
at relcache.c:673
#7  0x000055c3c86c3ce6 in RelationBuildDesc (targetRelId=16430,
insertIt=true) at relcache.c:1185
#8  0x000055c3c86c5922 in RelationIdGetRelation (relationId=16430) at
relcache.c:2116
#9  0x000055c3c8428276 in ReorderBufferProcessTXN (...) at
reorderbuffer.c:2222
#10 0x000055c3c84290c5 in ReorderBufferReplay (...) at
reorderbuffer.c:2701
#11 0x000055c3c8429147 in ReorderBufferCommit (...) at
reorderbuffer.c:2725
#12 0x000055c3c8414350 in DecodeCommit (...) at decode.c:733
#13 0x000055c3c84135a1 in xact_decode (...) at decode.c:242
#14 0x000055c3c84130fb in LogicalDecodingProcessRecord (...) at
decode.c:116
#15 0x000055c3c841ce60 in pg_logical_slot_get_changes_guts (...) at
logicalfuncs.c:266
#16 0x000055c3c841cfd1 in pg_logical_slot_get_changes (...) at
logicalfuncs.c:333
...

Also, with tables created as "CREATE TABLE t$j(t1 text);" it produces:
WARNING:  problem in alloc set text conversion context: bad block offset for
chunk 0x55bdb51ced18 in block 0x55bdb51ce0c8
(and other "problem in alloc" warnings)
and
TRAP: failed Assert("!HdrMaskIsExternal(chunk->hdrmask) ||
HdrMaskCheckMagic(chunk->hdrmask)"), File:
"../../../../src/include/utils/memutils_memorychunk.h", Line: 210, PID:
4188259

Reproduced on REL_12_STABLE .. master.


pgsql-bugs by date:

Previous
From: PG Bug reporting form
Date:
Subject: BUG #18508: Not all packages are present in the repo on rhel 8
Next
From: PG Bug reporting form
Date:
Subject: BUG #18510: jsonpath does not support trailing backslash at the end of the query