Re: Rows violating Foreign key constraint exists

2019-12-09 Thread Nandakumar M
Hi, Sorry about the delay in getting back with the results. > > On Fri, Nov 29, 2019 at 7:23 AM Tom Lane 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 acti

Re: Rows violating Foreign key constraint exists

2019-11-29 Thread Peter Geoghegan
On Fri, Nov 29, 2019 at 7:23 AM Tom Lane 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 ne

Re: Rows violating Foreign key constraint exists

2019-11-29 Thread Tom Lane
Nandakumar M writes: >> It could be that somebody disabled the triggers, but that would have to >> be a superuser. And I hope that people randomly disabling system triggers >> on tables don't have superuser access to your database. > It is unlikely that this happened. So I am assuming corruption

Re: Rows violating Foreign key constraint exists

2019-11-29 Thread Nandakumar M
Hi, > 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 CO

Re: Rows violating Foreign key constraint exists

2019-11-29 Thread Nandakumar M
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 in

Re: Rows violating Foreign key constraint exists

2019-11-28 Thread Nandakumar M
Hi, > It could be that somebody disabled the triggers, but that would have to > be a superuser. And I hope that people randomly disabling system triggers > on tables don't have superuser access to your database. It is unlikely that this happened. So I am assuming corruption. But I am able to que

Re: Rows violating Foreign key constraint exists

2019-11-28 Thread Adrian Klaver
On 11/28/19 5:25 AM, Nandakumar M wrote: Hi, I am using PG version 10.5. Saw a table where we have foreign key defined but few thousand rows violate the foreign key constraint. Have you verified that the FK is not in the parent table and is just not some index error/corruption? It might

Re: Rows violating Foreign key constraint exists

2019-11-28 Thread Laurenz Albe
On Thu, 2019-11-28 at 18:55 +0530, Nandakumar M wrote: > I am using PG version 10.5. > > Saw a table where we have foreign key defined but few thousand rows > violate the foreign key constraint. > > I understand that one possibility of this happening is if we had > manually disabled the triggers

Rows violating Foreign key constraint exists

2019-11-28 Thread Nandakumar M
Hi, I am using PG version 10.5. Saw a table where we have foreign key defined but few thousand rows violate the foreign key constraint. I understand that one possibility of this happening is if we had manually disabled the triggers that do FK integrity checks and re enabled them afterwards. Is t