Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uWlUR-0016Sj-S4 for pgsql-hackers@arkaria.postgresql.org; Wed, 02 Jul 2025 00:38:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uWlUP-008yDR-Vi for pgsql-hackers@arkaria.postgresql.org; Wed, 02 Jul 2025 00:38:18 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uWlUP-008yD3-3h for pgsql-hackers@lists.postgresql.org; Wed, 02 Jul 2025 00:38:18 +0000 Received: from m16.mail.163.com ([117.135.210.3]) by magus.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1uWlUI-005Byp-21 for pgsql-hackers@postgresql.org; Wed, 02 Jul 2025 00:38:15 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version: Content-Type; bh=uaBmjrkkcKuYlNvDigDSbU1ozbnhFhj4/Um3oPqfrUI=; b=O7XCy3ETdPOpnbFc8KAZ6zCfdvZvTMOFi3qG5E/FweP5DcZ9Bl9jFPXq6HmJkQ VXgvCG/c4WzA05J2854sEgWMRe407gimDhVwFH5yYSfJjfXKTGWtCpIqlZoc7FuS trnzpNLONIZS6VTYI8dNJRFHJUQ+emPu471pw2sOjytPk= Received: from lovely-coding (unknown []) by gzga-smtp-mtada-g1-1 (Coremail) with SMTP id _____wDXqxhpf2RoA2e+Bw--.9175S3; Wed, 02 Jul 2025 08:38:02 +0800 (CST) From: Andy Fan To: PostgreSQL Hackers Subject: A assert failure when initdb with track_commit_timestamp=on Date: Wed, 02 Jul 2025 00:38:01 +0000 Message-ID: <87plejmnpy.fsf@163.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-CM-TRANSID: _____wDXqxhpf2RoA2e+Bw--.9175S3 X-Coremail-Antispam: 1Uf129KBjvJXoW7Cw4UuF13urW3WFy8Zr1UJrb_yoW8CFyrpa 48Awn8KFWvqry8ur4kZa18XF4Iyr1DtryUXFW7tFsxAw1jkw1FkFZayry3Kry5ZFs5A3yj qF4jkrn8CF45Za7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07Uwjj9UUUUU= X-Originating-IP: [113.250.190.7] X-CM-SenderInfo: x2klx3xlid0iqsrtqiywtou0bp/xtbBhRB+U2hkekFdVgAAsE List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --=-=-= Content-Type: text/plain 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 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=v1-0001-Fix-the-Assert-failure-when-initdb-with-track_com.patch From b5e921ef42763dbb1126d60313b25ae40f8ec140 Mon Sep 17 00:00:00 2001 From: Andy Fan Date: Tue, 1 Jul 2025 23:50:37 +0000 Subject: [PATCH v1 1/1] Fix the Assert failure when initdb with track_commit_timestamp=on the real commit message depends on which solution is adopted. --- src/backend/access/transam/commit_ts.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/backend/access/transam/commit_ts.c b/src/backend/access/transam/commit_ts.c index 113fae1437a..da8bfb7167c 100644 --- a/src/backend/access/transam/commit_ts.c +++ b/src/backend/access/transam/commit_ts.c @@ -157,6 +157,13 @@ TransactionTreeSetCommitTsData(TransactionId xid, int nsubxids, if (!commitTsShared->commitTsActive) return; + /* + * There is no point to record a commit_ts for BootStrapCommitTs or + * FrozenTransactionId. + */ + if (unlikely(xid == BootstrapTransactionId || xid == FrozenTransactionId)) + return; + /* * Figure out the latest Xid in this batch: either the last subxid if * there's any, otherwise the parent xid. @@ -252,8 +259,6 @@ TransactionIdSetCommitTs(TransactionId xid, TimestampTz ts, int entryno = TransactionIdToCTsEntry(xid); CommitTimestampEntry entry; - Assert(TransactionIdIsNormal(xid)); - entry.time = ts; entry.nodeid = nodeid; -- 2.45.1 --=-=-=--