Re: Streamify more code paths

From: Mihail Nikalayeu <mihailnikalayeu(at)gmail(dot)com>
To: Xuneng Zhou <xunengzhou(at)gmail(dot)com>
Cc: Andres Freund <andres(at)anarazel(dot)de>, Michael Paquier <michael(at)paquier(dot)xyz>, pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Nazir Bilal Yavuz <byavuz81(at)gmail(dot)com>
Subject: Re: Streamify more code paths
Date: 2026-08-03 12:25:00
Message-ID: CADzfLwVEJ2_7ioX3ZSB1P7qXW40ghUy_ZCzeFvhDLoa_3Muztg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello, everyone!

While prototyping with a stress suite, I found memory corruption (and
possibly data corruption) issues related to those changes.

Issues is related to how the newer bfa3c4f106 affects the old 293e24e507.

The 293e24e507 caches the metapage as a pointer, but
read_stream_begin_relation may cause that pointer to become freed
because of:

hashbulkdelete() hash.c:543
read_stream_begin_relation(READ_STREAM_MAINTENANCE, ...)
read_stream_begin_impl() read_stream.c:806
get_tablespace_maintenance_io_concurrency(tablespace_id)
get_tablespace() spccache.c
SearchSysCache1(TABLESPACEOID, ...) ← cold cache → catalog scan
table_open(pg_tablespace)
LockRelationOid(1213) lmgr.c:136
AcceptInvalidationMessages() ← the flush point

causing something like:

ERROR: could not open file "base/5/16388.1" (target block 2139062145):
previous segment is only 66 blocks
CONTEXT: while scanning relation "public.t"

The simplest fix is to reorder a few lines of code - attached (with a
test generated by Claude based on my instructions).
But probably we should think broader to avoid such issues in the future.

Attachment Content-Type Size
nocfbot-v1-0001-hash-create-the-vacuum-read-stream-before-caching.patch application/octet-stream 6.6 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Kirill Reshke 2026-08-03 12:40:25 Re: GIN pageinspect support for entry tree and posting tree
Previous Message Aleksander Alekseev 2026-08-03 12:21:48 [PATCH] Remove unused PartitionDescData.last_found_part_index field