RE: BUG #19519: REPACK can fail due to missing chunk for toast value
От
Zhijie Hou (Fujitsu)
Тема
RE: BUG #19519: REPACK can fail due to missing chunk for toast value
Дата
Msg-id
TY4PR01MB17718138275019C783FFA043094CF2@TY4PR01MB17718.jpnprd01.prod.outlook.com
Ответ на
Re: BUG #19519: REPACK can fail due to missing chunk for toast value (Michael Paquier)
Список
Дерево обсуждения
BUG #19519: REPACK can fail due to missing chunk for toast value PG Bug reporting form <noreply@postgresql.org>
Re: BUG #19519: REPACK can fail due to missing chunk for toast value Srinath Reddy Sadipiralla <srinath2133@gmail.com>
Re: BUG #19519: REPACK can fail due to missing chunk for toast value Imran Zaheer <imran.zhir@gmail.com>
On Thursday, July 9, 2026 10:47 AM Michael Paquier wrote: > > An updated patch is attached, with the "flags" business added, and something > for the other issue reported by Imran for the case where > reform_and_rewrite_tuple() was not handled correctly. If we have a sort, > that means going back to a more aggressive detoasting to check if some > chunks are missing if a tuple has been found as recently dead. > I was wondering about doing a split into two patches for > build_range_scan() and copy_for_cluster(), but refrained from that due to the > detoast_external_attr_extended() required in both cases. > > Anyway, thoughts and reviews are welcome. Thank you for updating the patch. I've reviewed it and have a few comments below. 1. I think there could be a memory leak in the early return path of heap_toast_insert_or_update() when failing to retrieve a toast value. In toast_tuple_init, each attribute is detoasted one by one. This means that if there are multiple toasted columns, it's possible that some columns have already been detoasted while the remaining ones cannot be accessed (e.g., they were removed by vacuum). This can happen because we have a "HOT" mechanism that avoids updating unchanged toast columns, so if a user only updates one toast column value, the other toast columns in the table can still point to old chunks that may no longer be available. In such cases, the code continues rewriting without freeing the already detoasted values, unlike what we do in toast_tuple_cleanup. 2. This patch does not add TOAST_MISSING_OK to the end_heap_rewrite->raw_heap_insert call path, but it does seem possible to trigger the similar bug there. In rewrite_heap_tuple(), the tuple being updated is added to the rs_unresolved_tups hash. If that tuple has an unavailable toast value, then when end_heap_rewrite() is reached, it will attempt to read that toast value and report a "missing chunk" error. Please see the attachment which contains a script that I had AI generate to reproduce both issues. Best Regards, Zhijie Hou
В списке pgsql-bugs по дате отправления
От: Laurenz Albe
Дата:
От: Rui Zhao
Дата: