pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Row exists in a table that violates Foreign key constraint
2+ messages / 2 participants
[nested] [flat]

* Row exists in a table that violates Foreign key constraint
@ 2018-08-17 15:40  Nandakumar M <m.nanda92@gmail.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Nandakumar M @ 2018-08-17 15:40 UTC (permalink / raw)
  To: pgsql-bugs

Hi,

I have a table with a FK constraint to another table. There exists one row
on the referring table with no corresponding row on the referred table. I
tried validating the constraint but that did not produce any errors. This
is on a older version of Postgres (9.2.4)

Please find attached the query outputs showing the issue.

On checking postgres bugs mailing list found that the issue I am facing is
exactly the same as the one mentioned below.

https://www.postgresql.org/message-id/200704191356.l3JDufEo052753%40wwwmaster.postgresql.org

I have not done any VACUUM FULL on the table as suggested on this thread
though. It would be great if someone can confirm if this is an identified
issue and also let me know how to fix the inconsistency.

If any other information is needed for further analysis I can share the
same.

Regards,
Nanda

Attachments:

pg_fk_bug.txt (text/plain, 3.4K) download servicedesk=# servicedesk=# select version(); version ------------------------------------------------------------- PostgreSQL 9.2.4, compiled by Visual C++ build 1600, 64-bit (1 row) Time: 0.541 ms servicedesk=# \d+ usernotifications; Table "public.usernotifications" Column | Type | Modifiers | Storage | Stats target | Description -----------------------+---------+------------------------+---------+--------------+------------- dynamicnotificationid | bigint | not null | plain | | userid | bigint | not null | plain | | isread | boolean | not null default false | plain | | Indexes: "usernotifications_pk" PRIMARY KEY, btree (dynamicnotificationid, userid) "usernotifications_dynamicnotificationid_idx" UNIQUE, btree (dynamicnotificationid) "usernotifications_fk1_idx" btree (dynamicnotificationid) "usernotifications_fk2_idx" btree (userid) Foreign-key constraints: "usernotifications_fk1" FOREIGN KEY (dynamicnotificationid) REFERENCES dynamicnotifications(dynamicnotificationid) ON DELETE CASCADE "usernotifications_fk2" FOREIGN KEY (userid) REFERENCES sduser(userid) ON DELETE CASCADE Has OIDs: no servicedesk=# \d+ dynamicnotifications Table "public.dynamicnotifications" Column | Type | Modifiers | Storage | Stats target | Description -----------------------+--------+-----------+----------+--------------+------------- dynamicnotificationid | bigint | not null | plain | | module | citext | not null | extended | | moduleid | bigint | not null | plain | | notify_type | citext | not null | extended | | notify_time | bigint | not null | plain | | ownerid | bigint | | plain | | Indexes: "dynamicnotifications_pk" PRIMARY KEY, btree (dynamicnotificationid) "dynamicnotifications_dynamicnotificationid_idx" UNIQUE, btree (dynamicnotificationid) "dynamicnotifications_ownerid_idx" btree (ownerid) Check constraints: "dynamicnotifications_module_c" CHECK (length(module::text) <= 200) "dynamicnotifications_notify_type_c" CHECK (length(notify_type::text) <= 200) Referenced by: TABLE "usernotifications" CONSTRAINT "usernotifications_fk1" FOREIGN KEY (dynamicnotificationid) REFERENCES dynamicnotifications(dynamicnotificationid) ON DELETE CASCADE Has OIDs: no servicedesk=# servicedesk=# servicedesk=# alter table usernotifications validate constraint usernotifications_fk1; ALTER TABLE Time: 1.135 ms servicedesk=# select ctid,xmin,xmax, * from dynamicnotifications where dynamicnotificationid = 1054486; ctid | xmin | xmax | dynamicnotificationid | module | moduleid | notify_type | notify_time | ownerid ------+------+------+-----------------------+--------+----------+-------------+-------------+--------- (0 rows) Time: 0.897 ms servicedesk=# select ctid,xmin,xmax, * from usernotifications where dynamicnotificationid = 1054486; ctid | xmin | xmax | dynamicnotificationid | userid | isread -----------+--------+------+-----------------------+--------+-------- (6701,98) | 868387 | 0 | 1054486 | 4 | f (1 row) Time: 0.606 ms servicedesk=#
^ permalink raw reply [nested|flat] 2+ messages in thread

* Re: Row exists in a table that violates Foreign key constraint
@ 2018-08-17 17:48  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Nandakumar M <m.nanda92@gmail.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2018-08-17 17:48 UTC (permalink / raw)
  To: Nandakumar M <m.nanda92@gmail.com>; +Cc: pgsql-bugs

Nandakumar M <m.nanda92@gmail.com> writes:
> I have a table with a FK constraint to another table. There exists one row
> on the referring table with no corresponding row on the referred table. I
> tried validating the constraint but that did not produce any errors. This
> is on a older version of Postgres (9.2.4)

9.2.x is out of support; moreover, the last release in that series was
9.2.24, so you are missing a large number of bug fixes, including some
known data-corruption hazards.

If you can replicate this problem on an up-to-date Postgres release,
we'd be quite interested, but nobody is likely to spend any effort
looking into problems in 9.2.4.

			regards, tom lane




^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2018-08-17 17:48 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-08-17 15:40 Row exists in a table that violates Foreign key constraint Nandakumar M <m.nanda92@gmail.com>
2018-08-17 17:48 ` Tom Lane <tgl@sss.pgh.pa.us>

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