Subject: Unique key constraint Issue

From: shashidhar Reddy <[email-masked]>
Date: Mon, 25 Nov 2024 12:00:55 +0530

Hello,

We have postgresql servers with PostgreSQL 13.10   on Ubuntu release 22.04.

The issue is a unique key constraint with two columns one is character
another is integer. At some point the unique key did not work as I see
duplicate values with these two columns combination and it happened on
multiple servers on multiple databases on same table with same unique key.
I tried db dump and restore but the key is failing to create when restore
with duplicate value errors.

---

From: ajit wangkhem <[email-masked]>
Date: Mon, 25 Nov 2024 13:21:41 +0530

Output should be consistent across servers below query o/p

SELECT conname, pg_get_constraintdef(oid)
FROM pg_constraint
WHERE conrelid = 'your table name'::regclass AND contype = 'u';
(different datatype combine in UK is not an issue). This issue may not
happen in asynchronous, log shipping or streaming replication. In logical
replication it may create problem.

---

From: shashidhar Reddy <[email-masked]>
Date: Mon, 25 Nov 2024 14:14:37 +0530

Hi Ajit,

Thank you for your reply!

The result of the query is same across all servers and yes streaming
replication does not have any issue but the question is how did duplicate
values entered when there unique key in place.