pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Fix stale pg_index flags in the relcache for TOAST indexes 7+ messages / 1 participants [nested] [flat]
* pgsql: Fix stale pg_index flags in the relcache for TOAST indexes @ 2026-10-28 05:24 Michael Paquier <michael@paquier.xyz> 0 siblings, 0 replies; 7+ messages in thread From: Michael Paquier @ 2026-10-28 05:24 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix stale pg_index flags in the relcache for TOAST indexes RelationReloadIndexInfo() re-reads the mutable pg_index fields (indisready, indisvalid, indislive, etc.) only for indexes that are not system relations. The TOAST index of a user table lives in pg_toast and counts as one, but REINDEX CONCURRENTLY changes these fields on it like on any other index. A backend that had the TOAST indexes open when the invalidation arrived kept indisready = false for the new index, and did not insert its chunks there. Once the old index is dropped, reading such a value fails with "missing chunk number 0 for toast value N in pg_toast_X". The chunks remain in the TOAST table, only the index references were gone, so a rebuild of the TOAST index would fix this issue. This issue is fixed by re-reading the pg_index row for TOAST indexes, filling in their relcache fields. This is the same as for an index on a user table. Previouly, IsSystemRelation() was used, meaning the pg_index data was not re-read for a TOAST relation or a relation with a pinned OID (created by initdb). This check is meant for indexes whose values never change, so IsCatalogRelation() is fine, implying that only indexes created by initdb should be skipped (REINDEX CONCURRENTLY does not work on catalogs). This code is as old as 8ec943856a4, and was only used for CREATE INDEX CONCURRENTLY. 5dc92b844e68, that has introduced REINDEX CONCURRENTLY, has made possible to reach the problem with TOAST indexes due to these getting concurrently built, validated and then swapped. A test is added, able to reproduce the issue. It forces an insert before a swap, with a second session that maintains the TOAST indexes open while the new index becomes ready. This has been slightly simplified by me compared to what the author has sent. Oversight in 5dc92b844e68. Reported-by: Saicharanreddy Chinthareddy <saicharh@amazon.com> Author: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com> Reviewed-by: Chao Li <li.evan.chao@gmail.com> Reviewed-by: Michael Paquier <michael@paquier.xyz> Discussion: https://postgr.es/m/CALj2ACUAv=7wjOV3pRFhQP4WHME_JazuhoCr01i4_F2XA=JKog@mail.gmail.com Backpatch-through: 14 Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/27417270ab4e929aa3731e55945872206c425f75 Modified Files -------------- src/backend/access/common/toast_internals.c | 3 ++ src/backend/utils/cache/relcache.c | 13 ++--- src/test/modules/injection_points/Makefile | 1 + .../expected/reindex_concurrently_toast.out | 46 ++++++++++++++++++ src/test/modules/injection_points/meson.build | 1 + .../specs/reindex_concurrently_toast.spec | 55 ++++++++++++++++++++++ 6 files changed, 113 insertions(+), 6 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Fix stale pg_index flags in the relcache for TOAST indexes @ 2026-10-28 05:24 Michael Paquier <michael@paquier.xyz> 0 siblings, 0 replies; 7+ messages in thread From: Michael Paquier @ 2026-10-28 05:24 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix stale pg_index flags in the relcache for TOAST indexes RelationReloadIndexInfo() re-reads the mutable pg_index fields (indisready, indisvalid, indislive, etc.) only for indexes that are not system relations. The TOAST index of a user table lives in pg_toast and counts as one, but REINDEX CONCURRENTLY changes these fields on it like on any other index. A backend that had the TOAST indexes open when the invalidation arrived kept indisready = false for the new index, and did not insert its chunks there. Once the old index is dropped, reading such a value fails with "missing chunk number 0 for toast value N in pg_toast_X". The chunks remain in the TOAST table, only the index references were gone, so a rebuild of the TOAST index would fix this issue. This issue is fixed by re-reading the pg_index row for TOAST indexes, filling in their relcache fields. This is the same as for an index on a user table. Previouly, IsSystemRelation() was used, meaning the pg_index data was not re-read for a TOAST relation or a relation with a pinned OID (created by initdb). This check is meant for indexes whose values never change, so IsCatalogRelation() is fine, implying that only indexes created by initdb should be skipped (REINDEX CONCURRENTLY does not work on catalogs). This code is as old as 8ec943856a4, and was only used for CREATE INDEX CONCURRENTLY. 5dc92b844e68, that has introduced REINDEX CONCURRENTLY, has made possible to reach the problem with TOAST indexes due to these getting concurrently built, validated and then swapped. A test is added, able to reproduce the issue. It forces an insert before a swap, with a second session that maintains the TOAST indexes open while the new index becomes ready. This has been slightly simplified by me compared to what the author has sent. Oversight in 5dc92b844e68. Reported-by: Saicharanreddy Chinthareddy <saicharh@amazon.com> Author: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com> Reviewed-by: Chao Li <li.evan.chao@gmail.com> Reviewed-by: Michael Paquier <michael@paquier.xyz> Discussion: https://postgr.es/m/CALj2ACUAv=7wjOV3pRFhQP4WHME_JazuhoCr01i4_F2XA=JKog@mail.gmail.com Backpatch-through: 14 Branch ------ REL_19_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/c4b2f037d8608f5418590d86e60deffa53732d7a Modified Files -------------- src/backend/access/common/toast_internals.c | 3 ++ src/backend/utils/cache/relcache.c | 13 ++--- src/test/modules/injection_points/Makefile | 1 + .../expected/reindex_concurrently_toast.out | 46 ++++++++++++++++++ src/test/modules/injection_points/meson.build | 1 + .../specs/reindex_concurrently_toast.spec | 55 ++++++++++++++++++++++ 6 files changed, 113 insertions(+), 6 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Fix stale pg_index flags in the relcache for TOAST indexes @ 2026-10-28 05:24 Michael Paquier <michael@paquier.xyz> 0 siblings, 0 replies; 7+ messages in thread From: Michael Paquier @ 2026-10-28 05:24 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix stale pg_index flags in the relcache for TOAST indexes RelationReloadIndexInfo() re-reads the mutable pg_index fields (indisready, indisvalid, indislive, etc.) only for indexes that are not system relations. The TOAST index of a user table lives in pg_toast and counts as one, but REINDEX CONCURRENTLY changes these fields on it like on any other index. A backend that had the TOAST indexes open when the invalidation arrived kept indisready = false for the new index, and did not insert its chunks there. Once the old index is dropped, reading such a value fails with "missing chunk number 0 for toast value N in pg_toast_X". The chunks remain in the TOAST table, only the index references were gone, so a rebuild of the TOAST index would fix this issue. This issue is fixed by re-reading the pg_index row for TOAST indexes, filling in their relcache fields. This is the same as for an index on a user table. Previouly, IsSystemRelation() was used, meaning the pg_index data was not re-read for a TOAST relation or a relation with a pinned OID (created by initdb). This check is meant for indexes whose values never change, so IsCatalogRelation() is fine, implying that only indexes created by initdb should be skipped (REINDEX CONCURRENTLY does not work on catalogs). This code is as old as 8ec943856a4, and was only used for CREATE INDEX CONCURRENTLY. 5dc92b844e68, that has introduced REINDEX CONCURRENTLY, has made possible to reach the problem with TOAST indexes due to these getting concurrently built, validated and then swapped. A test is added, able to reproduce the issue. It forces an insert before a swap, with a second session that maintains the TOAST indexes open while the new index becomes ready. This has been slightly simplified by me compared to what the author has sent. Oversight in 5dc92b844e68. Reported-by: Saicharanreddy Chinthareddy <saicharh@amazon.com> Author: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com> Reviewed-by: Chao Li <li.evan.chao@gmail.com> Reviewed-by: Michael Paquier <michael@paquier.xyz> Discussion: https://postgr.es/m/CALj2ACUAv=7wjOV3pRFhQP4WHME_JazuhoCr01i4_F2XA=JKog@mail.gmail.com Backpatch-through: 14 Branch ------ REL_18_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/e4807a0f3f0373227de516edbdc6d8d350920c4c Modified Files -------------- src/backend/access/common/toast_internals.c | 3 ++ src/backend/utils/cache/relcache.c | 13 ++--- src/test/modules/injection_points/Makefile | 1 + .../expected/reindex_concurrently_toast.out | 46 ++++++++++++++++++ src/test/modules/injection_points/meson.build | 1 + .../specs/reindex_concurrently_toast.spec | 55 ++++++++++++++++++++++ 6 files changed, 113 insertions(+), 6 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Fix stale pg_index flags in the relcache for TOAST indexes @ 2026-10-28 05:24 Michael Paquier <michael@paquier.xyz> 0 siblings, 0 replies; 7+ messages in thread From: Michael Paquier @ 2026-10-28 05:24 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix stale pg_index flags in the relcache for TOAST indexes RelationReloadIndexInfo() re-reads the mutable pg_index fields (indisready, indisvalid, indislive, etc.) only for indexes that are not system relations. The TOAST index of a user table lives in pg_toast and counts as one, but REINDEX CONCURRENTLY changes these fields on it like on any other index. A backend that had the TOAST indexes open when the invalidation arrived kept indisready = false for the new index, and did not insert its chunks there. Once the old index is dropped, reading such a value fails with "missing chunk number 0 for toast value N in pg_toast_X". The chunks remain in the TOAST table, only the index references were gone, so a rebuild of the TOAST index would fix this issue. This issue is fixed by re-reading the pg_index row for TOAST indexes, filling in their relcache fields. This is the same as for an index on a user table. Previouly, IsSystemRelation() was used, meaning the pg_index data was not re-read for a TOAST relation or a relation with a pinned OID (created by initdb). This check is meant for indexes whose values never change, so IsCatalogRelation() is fine, implying that only indexes created by initdb should be skipped (REINDEX CONCURRENTLY does not work on catalogs). This code is as old as 8ec943856a4, and was only used for CREATE INDEX CONCURRENTLY. 5dc92b844e68, that has introduced REINDEX CONCURRENTLY, has made possible to reach the problem with TOAST indexes due to these getting concurrently built, validated and then swapped. A test is added, able to reproduce the issue. It forces an insert before a swap, with a second session that maintains the TOAST indexes open while the new index becomes ready. This has been slightly simplified by me compared to what the author has sent. Oversight in 5dc92b844e68. Reported-by: Saicharanreddy Chinthareddy <saicharh@amazon.com> Author: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com> Reviewed-by: Chao Li <li.evan.chao@gmail.com> Reviewed-by: Michael Paquier <michael@paquier.xyz> Discussion: https://postgr.es/m/CALj2ACUAv=7wjOV3pRFhQP4WHME_JazuhoCr01i4_F2XA=JKog@mail.gmail.com Backpatch-through: 14 Branch ------ REL_17_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/b3852eec68aec0078460e5409db3f78f2f200ebf Modified Files -------------- src/backend/access/common/toast_internals.c | 3 ++ src/backend/utils/cache/relcache.c | 13 ++--- src/test/modules/injection_points/Makefile | 1 + .../expected/reindex_concurrently_toast.out | 46 ++++++++++++++++++ src/test/modules/injection_points/meson.build | 1 + .../specs/reindex_concurrently_toast.spec | 55 ++++++++++++++++++++++ 6 files changed, 113 insertions(+), 6 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Fix stale pg_index flags in the relcache for TOAST indexes @ 2026-10-28 05:24 Michael Paquier <michael@paquier.xyz> 0 siblings, 0 replies; 7+ messages in thread From: Michael Paquier @ 2026-10-28 05:24 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix stale pg_index flags in the relcache for TOAST indexes RelationReloadIndexInfo() re-reads the mutable pg_index fields (indisready, indisvalid, indislive, etc.) only for indexes that are not system relations. The TOAST index of a user table lives in pg_toast and counts as one, but REINDEX CONCURRENTLY changes these fields on it like on any other index. A backend that had the TOAST indexes open when the invalidation arrived kept indisready = false for the new index, and did not insert its chunks there. Once the old index is dropped, reading such a value fails with "missing chunk number 0 for toast value N in pg_toast_X". The chunks remain in the TOAST table, only the index references were gone, so a rebuild of the TOAST index would fix this issue. This issue is fixed by re-reading the pg_index row for TOAST indexes, filling in their relcache fields. This is the same as for an index on a user table. Previouly, IsSystemRelation() was used, meaning the pg_index data was not re-read for a TOAST relation or a relation with a pinned OID (created by initdb). This check is meant for indexes whose values never change, so IsCatalogRelation() is fine, implying that only indexes created by initdb should be skipped (REINDEX CONCURRENTLY does not work on catalogs). This code is as old as 8ec943856a4, and was only used for CREATE INDEX CONCURRENTLY. 5dc92b844e68, that has introduced REINDEX CONCURRENTLY, has made possible to reach the problem with TOAST indexes due to these getting concurrently built, validated and then swapped. A test is added, able to reproduce the issue. It forces an insert before a swap, with a second session that maintains the TOAST indexes open while the new index becomes ready. This has been slightly simplified by me compared to what the author has sent. Oversight in 5dc92b844e68. Reported-by: Saicharanreddy Chinthareddy <saicharh@amazon.com> Author: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com> Reviewed-by: Chao Li <li.evan.chao@gmail.com> Reviewed-by: Michael Paquier <michael@paquier.xyz> Discussion: https://postgr.es/m/CALj2ACUAv=7wjOV3pRFhQP4WHME_JazuhoCr01i4_F2XA=JKog@mail.gmail.com Backpatch-through: 14 Branch ------ REL_16_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/17c5a0659fcbfa8f831cc7a887ea3b457349401d Modified Files -------------- src/backend/utils/cache/relcache.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Fix stale pg_index flags in the relcache for TOAST indexes @ 2026-10-28 05:24 Michael Paquier <michael@paquier.xyz> 0 siblings, 0 replies; 7+ messages in thread From: Michael Paquier @ 2026-10-28 05:24 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix stale pg_index flags in the relcache for TOAST indexes RelationReloadIndexInfo() re-reads the mutable pg_index fields (indisready, indisvalid, indislive, etc.) only for indexes that are not system relations. The TOAST index of a user table lives in pg_toast and counts as one, but REINDEX CONCURRENTLY changes these fields on it like on any other index. A backend that had the TOAST indexes open when the invalidation arrived kept indisready = false for the new index, and did not insert its chunks there. Once the old index is dropped, reading such a value fails with "missing chunk number 0 for toast value N in pg_toast_X". The chunks remain in the TOAST table, only the index references were gone, so a rebuild of the TOAST index would fix this issue. This issue is fixed by re-reading the pg_index row for TOAST indexes, filling in their relcache fields. This is the same as for an index on a user table. Previouly, IsSystemRelation() was used, meaning the pg_index data was not re-read for a TOAST relation or a relation with a pinned OID (created by initdb). This check is meant for indexes whose values never change, so IsCatalogRelation() is fine, implying that only indexes created by initdb should be skipped (REINDEX CONCURRENTLY does not work on catalogs). This code is as old as 8ec943856a4, and was only used for CREATE INDEX CONCURRENTLY. 5dc92b844e68, that has introduced REINDEX CONCURRENTLY, has made possible to reach the problem with TOAST indexes due to these getting concurrently built, validated and then swapped. A test is added, able to reproduce the issue. It forces an insert before a swap, with a second session that maintains the TOAST indexes open while the new index becomes ready. This has been slightly simplified by me compared to what the author has sent. Oversight in 5dc92b844e68. Reported-by: Saicharanreddy Chinthareddy <saicharh@amazon.com> Author: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com> Reviewed-by: Chao Li <li.evan.chao@gmail.com> Reviewed-by: Michael Paquier <michael@paquier.xyz> Discussion: https://postgr.es/m/CALj2ACUAv=7wjOV3pRFhQP4WHME_JazuhoCr01i4_F2XA=JKog@mail.gmail.com Backpatch-through: 14 Branch ------ REL_15_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/cb51daa27d875e5aaad5792112a251280527416f Modified Files -------------- src/backend/utils/cache/relcache.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Fix stale pg_index flags in the relcache for TOAST indexes @ 2026-10-28 05:24 Michael Paquier <michael@paquier.xyz> 0 siblings, 0 replies; 7+ messages in thread From: Michael Paquier @ 2026-10-28 05:24 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix stale pg_index flags in the relcache for TOAST indexes RelationReloadIndexInfo() re-reads the mutable pg_index fields (indisready, indisvalid, indislive, etc.) only for indexes that are not system relations. The TOAST index of a user table lives in pg_toast and counts as one, but REINDEX CONCURRENTLY changes these fields on it like on any other index. A backend that had the TOAST indexes open when the invalidation arrived kept indisready = false for the new index, and did not insert its chunks there. Once the old index is dropped, reading such a value fails with "missing chunk number 0 for toast value N in pg_toast_X". The chunks remain in the TOAST table, only the index references were gone, so a rebuild of the TOAST index would fix this issue. This issue is fixed by re-reading the pg_index row for TOAST indexes, filling in their relcache fields. This is the same as for an index on a user table. Previouly, IsSystemRelation() was used, meaning the pg_index data was not re-read for a TOAST relation or a relation with a pinned OID (created by initdb). This check is meant for indexes whose values never change, so IsCatalogRelation() is fine, implying that only indexes created by initdb should be skipped (REINDEX CONCURRENTLY does not work on catalogs). This code is as old as 8ec943856a4, and was only used for CREATE INDEX CONCURRENTLY. 5dc92b844e68, that has introduced REINDEX CONCURRENTLY, has made possible to reach the problem with TOAST indexes due to these getting concurrently built, validated and then swapped. A test is added, able to reproduce the issue. It forces an insert before a swap, with a second session that maintains the TOAST indexes open while the new index becomes ready. This has been slightly simplified by me compared to what the author has sent. Oversight in 5dc92b844e68. Reported-by: Saicharanreddy Chinthareddy <saicharh@amazon.com> Author: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com> Reviewed-by: Chao Li <li.evan.chao@gmail.com> Reviewed-by: Michael Paquier <michael@paquier.xyz> Discussion: https://postgr.es/m/CALj2ACUAv=7wjOV3pRFhQP4WHME_JazuhoCr01i4_F2XA=JKog@mail.gmail.com Backpatch-through: 14 Branch ------ REL_14_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/9a56e080f164332698ce640966ba6281acd68373 Modified Files -------------- src/backend/utils/cache/relcache.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
end of thread, other threads:[~2026-10-28 05:24 UTC | newest] Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2026-10-28 05:24 pgsql: Fix stale pg_index flags in the relcache for TOAST indexes Michael Paquier <michael@paquier.xyz> 2026-10-28 05:24 pgsql: Fix stale pg_index flags in the relcache for TOAST indexes Michael Paquier <michael@paquier.xyz> 2026-10-28 05:24 pgsql: Fix stale pg_index flags in the relcache for TOAST indexes Michael Paquier <michael@paquier.xyz> 2026-10-28 05:24 pgsql: Fix stale pg_index flags in the relcache for TOAST indexes Michael Paquier <michael@paquier.xyz> 2026-10-28 05:24 pgsql: Fix stale pg_index flags in the relcache for TOAST indexes Michael Paquier <michael@paquier.xyz> 2026-10-28 05:24 pgsql: Fix stale pg_index flags in the relcache for TOAST indexes Michael Paquier <michael@paquier.xyz> 2026-10-28 05:24 pgsql: Fix stale pg_index flags in the relcache for TOAST indexes Michael Paquier <michael@paquier.xyz>
This inbox is served by DDX for PostgreSQL; see mirroring instructions for how to clone and mirror all data and code used for this inbox