| From: | vignesh C <vignesh21(at)gmail(dot)com> |
|---|---|
| To: | Mihail Nikalayeu <mihailnikalayeu(at)gmail(dot)com> |
| Cc: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, onderkalaci(at)gmail(dot)com |
| Subject: | Re: Apply worker can pick an invalid index for REPLICA IDENTITY FULL lookups |
| Date: | 2026-08-25 16:04:33 |
| Message-ID: | CALDaNm2-QFWRb2vOJ6uS_WB06er_BF7Ow2PowG8KZoS6tfR1yw@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On Sun, 23 Aug 2026 at 01:26, Mihail Nikalayeu
<mihailnikalayeu(at)gmail(dot)com> wrote:
>
> Hello,
>
> When the remote relation has REPLICA IDENTITY FULL and the local one
> has no primary key or replica identity, the apply worker looks for any
> index it can search by.
> FindUsableIndexForReplicaIdentityFull() walks RelationGetIndexList()
> and takes the first index of a suitable shape without checking if it
> is valid.
> That list omits only indexes that are not indislive, so the leftover
> from a failed CREATE INDEX CONCURRENTLY is eligible -- and such an
> index need not contain every row.
>
> A failed CIC validation leaves an index that scans cleanly but lacks
> exactly the rows validation would have added. Consequently, updates
> and deletes for those rows are dropped as update_missing conflicts and
> the subscriber quietly diverges.
>
> A failed build leaves an index that is empty down to the metapage,
> which parks the subscription in a permanent error:
> ERROR: could not read blocks 0..0 in file "base/5/16433": read only 0
> of 8192 bytes
>
> The fix and a reproducer are in the attachments.
>
> Affects 16 and up, from 89e46da5e51.
Thanks for the patch, the patch does not apply on PG17 version, you
might have to provide a separate patch for PG17 & below version:
patch -p1 < v1-0001-Don-t-choose-an-invalid-index-for-REPLICA-IDENTIT.patch
patching file 'src/backend/replication/logical/relation.c'
1 out of 1 hunks failed--saving rejects to
'src/backend/replication/logical/relation.c.rej'
patching file 'src/test/subscription/t/032_subscribe_use_index.pl'
Regards,
Vignesh
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Alberto Piai | 2026-08-25 16:13:05 | Re: Adding a stored generated column without long-lived locks |
| Previous Message | Ashutosh Bapat | 2026-08-25 15:57:01 | Re: Disallow outer-level and WHERE-clause aggregates in GRAPH_TABLE |