Re: Rows violating Foreign key constraint exists

From: Nandakumar M <m(dot)nanda92(at)gmail(dot)com>
To: Peter Geoghegan <pg(at)bowt(dot)ie>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Rows violating Foreign key constraint exists
Date: 2019-12-09 10:17:27
Message-ID: CANcFUu60dD8NujoW7kcw3hx7MihuwgxQyEocQSWJ5mdXybHohw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

Sorry about the delay in getting back with the results.

>
> On Fri, Nov 29, 2019 at 7:23 AM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> > The most likely "corruption" explanation is something wrong with the
> > indexes on the referenced and/or referencing column, causing rows to
> > not be found when referential actions should have found them. Random
> > querying of the tables wouldn't necessarily expose that --- you'd need
> > to be sure that your queries use the questionable indexes, and maybe
> > even search for some of the specific rows that seem mis-indexed.

This indeed is the problem. Select query with criteria on FK column
did not return any rows. However, after I disabled indexscan, bitmap
indexscan and tried the same query this time sequential scan was
performed by PG and it returned 80 rows.

> Or try using contrib/amcheck, which is available in Postgres 10.
> Perhaps try the query here, modified to verify all B-Tree indexes (not
> just those indexes in the pg_catalog schema):
>
> https://www.postgresql.org/docs/10/amcheck.html
>
> --

I tried amcheck query on all indexes in the database and it did not
raise any errors.

How do I identify such corruption exists in the database? Will
enabling page checksum be of help here?

Thanks.

Regards,
Nanda

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Dor Ben Dov 2019-12-09 10:24:05 PostgreSQL HA FO question
Previous Message Adrian Klaver 2019-12-08 21:23:20 Re: canno save editted data