Re: BUG #19082: Failing assert in index scan

Matthijs van der Vleuten <postgresql@zr40.nl>

From: "Matthijs van der Vleuten" <postgresql@zr40.nl>
To: "Peter Geoghegan" <pg@bowt.ie>
Cc: pgsql-bugs@lists.postgresql.org
Date: 2025-10-10T17:09:01Z
Lists: pgsql-bugs

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Remove overzealous _bt_killitems assertion.

  2. Make _bt_killitems drop pins it acquired itself.

On Fri, Oct 10, 2025, at 18:28, Peter Geoghegan wrote:
> On Fri, Oct 10, 2025 at 12:13 PM Matthijs van der Vleuten
> <postgresql@zr40.nl> wrote:
>> No, none of the tables and indexes in that database are unlogged or temporary.
>
> Are these backwards scans? In other words, does EXPLAIN show "Index
> Scan Backwards" for these queries? I see that the first query "ORDER
> BY "mentions"."id" ASC", but perhaps that index column is declared as
> DESC (in which case it'd be a backwards scan)?

No, the index columns aren't declared as DESC, and, as far as I've been able to verify, the query plan doesn't use backward scans.

I've isolated one particular row that triggers this assert. It's a different table but it fails the assertion the same way.

zr40@[local]:5432 mastodon_production=# explain SELECT "preview_cards_statuses".* FROM "preview_cards_statuses" WHERE "preview_cards_statuses"."status_id" = 114337794133378371 LIMIT 1;
                                                   QUERY PLAN                                                    
-----------------------------------------------------------------------------------------------------------------
 Limit  (cost=0.42..2.84 rows=1 width=81)
   ->  Index Scan using preview_cards_statuses_pkey on preview_cards_statuses  (cost=0.42..2.84 rows=1 width=81)
         Index Cond: (status_id = '114337794133378371'::bigint)
(3 rows)

zr40@[local]:5432 mastodon_production=# select "preview_cards_statuses".* FROM "preview_cards_statuses" WHERE "preview_cards_statuses"."status_id" = 114337794133378371 LIMIT 1;
server closed the connection unexpectedly
	This probably means the server terminated abnormally
	before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.
The connection to the server was lost. Attempting reset: Failed.

Server logs:

TRAP: failed Assert("!XLogRecPtrIsInvalid(so->currPos.lsn)"), File: "./build/../src/backend/access/nbtree/nbtutils.c", Line: 1782, PID: 50833
postgres: zr40 mastodon_production [local] SELECT(ExceptionalCondition+0x75) [0x5654f247eea5]
postgres: zr40 mastodon_production [local] SELECT(_bt_killitems+0x550) [0x5654f1ff4710]
postgres: zr40 mastodon_production [local] SELECT(+0x1eee95) [0x5654f1febe95]
postgres: zr40 mastodon_production [local] SELECT(_bt_next+0x92) [0x5654f1fed472]
postgres: zr40 mastodon_production [local] SELECT(btgettuple+0x7c) [0x5654f1fe9ddc]
postgres: zr40 mastodon_production [local] SELECT(index_getnext_tid+0x56) [0x5654f1fdab06]
postgres: zr40 mastodon_production [local] SELECT(index_getnext_slot+0x7b) [0x5654f1fdad4b]
postgres: zr40 mastodon_production [local] SELECT(+0x37bfbd) [0x5654f2178fbd]
postgres: zr40 mastodon_production [local] SELECT(+0x37e3e9) [0x5654f217b3e9]
postgres: zr40 mastodon_production [local] SELECT(standard_ExecutorRun+0x19b) [0x5654f215013b]
postgres: zr40 mastodon_production [local] SELECT(+0x531141) [0x5654f232e141]
postgres: zr40 mastodon_production [local] SELECT(PortalRun+0x2b0) [0x5654f232fa10]
postgres: zr40 mastodon_production [local] SELECT(+0x52e651) [0x5654f232b651]
postgres: zr40 mastodon_production [local] SELECT(PostgresMain+0x1618) [0x5654f232d088]
postgres: zr40 mastodon_production [local] SELECT(+0x49036b) [0x5654f228d36b]
postgres: zr40 mastodon_production [local] SELECT(PostmasterMain+0xeee) [0x5654f228e50e]
postgres: zr40 mastodon_production [local] SELECT(main+0x21c) [0x5654f1f6806c]
/lib/x86_64-linux-gnu/libc.so.6(+0x29ca8) [0x7f0b6922eca8]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x85) [0x7f0b6922ed65]
postgres: zr40 mastodon_production [local] SELECT(_start+0x21) [0x5654f1f68631]
2025-10-10 19:03:26 CEST 68e8cff4.6ce1 | LOG:  server process (PID 50833) was terminated by signal 6: Aborted
2025-10-10 19:03:26 CEST 68e8cff4.6ce1 | DETAIL:  Failed process was running: select "preview_cards_statuses".* FROM "preview_cards_statuses" WHERE "preview_cards_statuses"."status_id" = 114337794133378371 LIMIT 1;
2025-10-10 19:03:26 CEST 68e8cff4.6ce1 | LOG:  terminating any other active server processes