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.98.2) (envelope-from ) id 1xTD46-00000000Bc6-3yrn for pgsql-bugs@arkaria.postgresql.org; Tue, 17 Nov 2026 06:53:15 +0000 Received: from localhost ([127.0.0.1]:44610 helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xTD46-00000003DJk-1I2E for pgsql-bugs@arkaria.postgresql.org; Tue, 17 Nov 2026 06:53:14 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]:35280) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xTBMW-00000002naS-1QGB for pgsql-bugs@lists.postgresql.org; Tue, 17 Nov 2026 05:04:08 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xTBMT-000000007AP-1mhy for pgsql-bugs@lists.postgresql.org; Tue, 17 Nov 2026 05:04:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Message-ID:Date:Reply-To:Cc:From:To:Subject: Content-Transfer-Encoding:MIME-Version:Content-Type:Sender:Content-ID: Content-Description:In-Reply-To:References; bh=1AtCKt+3ny5MgmQ1xOw4rTfQoFPWiULlGRN0FObh03Q=; b=xOaZjcdzwFhhestDCUMuXif20C 7d/zrPUVbqV+X2GGZi8thHuSpcFbRMSC6nb7tc4jbaj3DaR3W5T5x5JZtLfHoXRiCOnJxTbqpDOYg bwpizoDsZA/YNBDGHuGJOkjUE+hM86pG44FdlEv4MH1MHbs8wwQlSnGGUAwneDn6ojHdb1kIl4Gjf E1Qhz356NIrYEQ8DzdirNHCqAe8h3bKa3hs4CpLAdotLtfmdlLL019uDLntE/Zloa62iYfwjQSmIm ELunmSId9NZH488QGaCtO4uJgPdjkD8u6//90Sby9mUqlWC2O+xJQBiccBKFb+wl9wUoBi8wwqFo4 UYE70Z5w==; Received: from wrigleys.postgresql.org ([2a02:16a8:dc51::60]) by mahout.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xTBMR-00000000Gb6-24xj for pgsql-bugs@lists.postgresql.org; Tue, 17 Nov 2026 05:04:04 +0000 Received: from localhost ([127.0.0.1] helo=wrigleys.postgresql.org) by wrigleys.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xTBMQ-00000000fq0-10gJ for pgsql-bugs@lists.postgresql.org; Tue, 17 Nov 2026 05:04:02 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19909: BRIN redo: BufferIsPinned assert in brin_xlog_insert_update() if index was dropped or truncated To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: hackerzheng666@gmail.com Reply-To: hackerzheng666@gmail.com, pgsql-bugs@lists.postgresql.org Date: Tue, 17 Nov 2026 05:03:04 +0000 Message-ID: <19909-6bd7fafaead0184c@postgresql.org> X-Auto-Response-Suppress: All Auto-Submitted: auto-generated List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk The following bug has been logged on the website: Bug reference: 19909 Logged by: Zheng Hacker Email address: hackerzheng666@gmail.com PostgreSQL version: 19rc2 Operating system: Linux x86_64 (Debian), clang 14.0.6, cassert Description: =20 In an assert-enabled build, crash recovery (and a standby restart) aborts in the startup process: TRAP: failed Assert("BufferIsPinned(buffer)"), File: "bufmgr.c", Line: 4479 The stack is brin_redo -> brin_xlog_insert_update -> BufferGetBlockNumber. Cause (source at 70c4a57; REL_18_STABLE and REL_11 through REL_18 have the same lines): src/backend/access/brin/brin_xlog.c line 68: action =3D XLogReadBufferForRedo(record, 0, &buffer); line 72: regpgno =3D BufferGetBlockNumber(buffer); (unconditional) line 97: if (BufferIsValid(buffer)) UnlockReleaseBuffer(buffer); XLogReadBufferForRedo() returns BLK_NOTFOUND with an InvalidBuffer when the block is beyond the end of the file (xlogutils.c:527-530). The comment at xlogutils.c:462-465 says this is expected: the caller should silently skip the update. BufferGetBlockNumber(InvalidBuffer) fails the assertion at bufmgr.c:4479. The validity check comes after the call. Reproduction (assert-enabled build, the same binary settings as in the Environment section, no harness in the loop): -- settings: fsync=3Doff, full_page_writes=3Doff, wal_level=3Dlogical CREATE TABLE t (a int); INSERT INTO t VALUES (1); CREATE INDEX ib ON t USING brin (a) WITH (pages_per_range =3D 1); CHECKPOINT; SELECT brin_desummarize_range('ib', 0); SELECT brin_summarize_range('ib', 0); DROP INDEX ib; -- then, with no checkpoint in between: -- pg_ctl -m immediate stop; pg_ctl start Result: the startup process aborts with the TRAP above and the server does not start. Observed 15 of 15 runs of this sequence (5 + 10). The same pattern with a 30000-row table reproduced 20/20 with DROP TABLE, 20/20 with DROP INDEX, 20/20 with REINDEX INDEX and 20/20 with TRUNCATE. A streaming standby that replays a DROP TABLE and is then killed and restarted hit the same TRAP 8/8 times. Controls (no TRAP, restart OK): no drop 0/10; CHECKPOINT after the drop 0/20 (the file is unlinked by the checkpoint); no CHECKPOINT between the index build and the inserts 0/20; no brin_summarize (no BRIN records) 0/10; full_page_writes=3Don 0/20; standby without a drop 0/4. WAL at the crash (pg_waldump from the checkpoint REDO point): BRIN DESUMMARIZE, then BRIN INSERT heapBlk 0 with blkref #0 =3D index block 2 and no full-page image, then SAMEPAGE_UPDATE, then the COMMIT that drops the index. The index file is 0 bytes at the crash. DROP/REINDEX/TRUNCATE truncate the main fork to zero length at commit and unlink it only after the next checkpoint (md.c, mdunlinkfork, non-redo path). So block 2 is beyond EOF when the INSERT is replayed. The reading that the INSERT is the trapping record is an inference (first non-SAMEPAGE BRIN record in the replayed range; no debugger breakpoint was used). Release-like behaviour: the same sequences on an ASan build without assertions (no cassert, launched with the usual ASan settings) start normally: restart OK and server ready in 10 of 10 runs for this sequence and in 10 of 10 for the 30000-row DROP TABLE sequence, with no PANIC in the log. This is an inference from the same code path; it was not checked at memory level. Suggested fix (not built or tested): replace line 72 with XLogRecGetBlockTag(record, 0, NULL, NULL, ®pgno); This is the same pattern that brin_xlog_revmap_extend() already uses (line 220). Optionally, also skip the revmap update (block 1) when block 0 returned BLK_NOTFOUND, since no index tuple was inserted. Whether block 1 can need redo while block 0 is missing has not been checked. Severity: assertion-level in assert-enabled builds. In such a build, a server cannot finish crash recovery, or a standby restart, while this WAL is pending. In the ASan build tested, no effect was visible. The unguarded read in non-assert builds (GetBufferDescriptor(-1)) is only used if block 1 also needs redo, which has not been observed (not verified). Environment and limits - The binary is assumed to be built from 70c4a57. The line mapping of brin_xlog.c:72 and bufmgr.c:4479 in the binary supports this, but the commit was not proven from the binary. - The non-assert comparison used a binary of unknown commit (not verified). - Tested on git master (20devel, commit 70c4a57b64d3). Master HEAD 7fc2f0423320 (2026-11-16) has the identical code at the same lines (read from master brin_xlog.c; not built). - REL_11 through REL_18 have the same code at the same lines (gh contents), but were not run. - UPDATE records (brin_xlog_update calls brin_xlog_insert_update too) were present in one test, but the trap was not isolated to them. - No commit between 70c4a57 and master HEAD 7fc2f0423320 touches src/backend/access/brin/brin_xlog.c (checked in the GitHub commit list). A patch with a regression test will follow as a reply on this thread.