Re: Rows violating Foreign key constraint exists - Mailing list pgsql-general

From Nandakumar M
Subject Re: Rows violating Foreign key constraint exists
Date
Msg-id CANcFUu7gHMxK=px+zwt+mnX63-2ELU0nmLbYvP=GmL0+dERKXg@mail.gmail.com
Whole thread Raw
In response to Re: Rows violating Foreign key constraint exists  (Adrian Klaver <adrian.klaver@aklaver.com>)
Responses Re: Rows violating Foreign key constraint exists  (Nandakumar M <m.nanda92@gmail.com>)
List pgsql-general
Hi,


> Have you verified that the FK is not in the parent table and is just not
> some index error/corruption?

Yes.

> >
> > Also, is there any way to make sure the FK checking trigger can never
> > be disabled (so that such a case will never arise)?
>
> Not sure that can happen as it is baked into existing code. For instance:
>
> https://www.postgresql.org/docs/11/app-pgdump.html
>
> "
> --disable-triggers
>
>      This option is relevant only when creating a data-only dump. It
> instructs pg_dump to include commands to temporarily disable triggers on
> the target tables while the data is reloaded. Use this if you have
> referential integrity checks or other triggers on the tables that you do
> not want to invoke during data reload.

Found this thread which discusses the same topic as here.
https://www.postgresql.org/message-id/20190715160926.GA17140%40alvherre.pgsql

PG already allows a new FK to be created with ADD CONSTRAINT ... NOT
VALID clause which can be validated later using ALTER TABLE ...
VALIDATE CONSTRAINT.
I guess what we are looking for here is the same but for existing FKs.

i.e Something like

`ALTER TABLE distributors ALTER CONSTRAINT distfk NOT VALID;`
`ALTER TABLE distributors VALIDATE CONSTRAINT distfk;`


Regards,
Nanda



pgsql-general by date:

Previous
From: Nandakumar M
Date:
Subject: Re: Rows violating Foreign key constraint exists
Next
From: Nandakumar M
Date:
Subject: Re: Rows violating Foreign key constraint exists