A assert failure when initdb with track_commit_timestamp=on

From: Andy Fan <zhihuifan1213(at)163(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: A assert failure when initdb with track_commit_timestamp=on
Date: 2025-07-02 00:38:01
Message-ID: 87plejmnpy.fsf@163.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


Hi,

When working with the commit_ts module, I find the following issue:

After configure with --enable-cassert option, then initdb with:

initdb -D x2 -c track_commit_timestamp=on

Then we can get the following core dump:

0 in raise of /lib/x86_64-linux-gnu/libc.so.6
1 in abort of /lib/x86_64-linux-gnu/libc.so.6
2 in ExceptionalCondition of assert.c:66
3 in TransactionIdSetCommitTs of commit_ts.c:257
4 in SetXidCommitTsInPage of commit_ts.c:236
5 in TransactionTreeSetCommitTsData of commit_ts.c:192
6 in RecordTransactionCommit of xact.c:1468
7 in CommitTransaction of xact.c:2365
8 in CommitTransactionCommandInternal of xact.c:3202
9 in CommitTransactionCommand of xact.c:3163
10 in BootstrapModeMain of bootstrap.c:390
11 in main of main.c:210

The reason are TransactionIdSetCommitTs think the given xid must be
normal

static void
TransactionIdSetCommitTs(TransactionId xid, TimestampTz ts,
RepOriginId nodeid, int slotno)
{
...
Assert(TransactionIdIsNormal(xid));
}

However this is not true in BootstrapMode, this failure is masked by
default because TransactionTreeSetCommitTsData returns fast when
track_commit_timestamp is off.

void
TransactionTreeSetCommitTsData(TransactionId xid, int nsubxids,
TransactionId *subxids, TimestampTz timestamp,
RepOriginId nodeid)
{

/*
* No-op if the module is not active.
*
*/
if (!commitTsShared->commitTsActive)
return;

..
}

I can't think out a meaningful reason to record the commit timestamp for a
BootstrapTransactionId or FrozenTransactionId, so I think bypass it in
TransactionTreeSetCommitTsData could be a solution. Another solution is
just removing the Assert in TransactionIdSetCommitTs, it works during
initdb test at least.

I include both fixes in the attachment, I think just one of them could
be adopted however.

--
Best Regards
Andy Fan

Attachment Content-Type Size
v1-0001-Fix-the-Assert-failure-when-initdb-with-track_com.patch text/x-diff 1.3 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2025-07-02 00:46:42 Re: A assert failure when initdb with track_commit_timestamp=on
Previous Message Aya Iwata (Fujitsu) 2025-07-02 00:21:56 RE: [WIP]Vertical Clustered Index (columnar store extension) - take2