Re: Unique key constraint Issue

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: shashidhar Reddy <shashidharreddy001(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Unique key constraint Issue
Date: 2024-11-25 16:02:38
Message-ID: 1348980.1732550558@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

shashidhar Reddy <shashidharreddy001(at)gmail(dot)com> writes:
> 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.

If the table has existed for some time (like, across updates of the
underlying operating system) then your problem likely traces to
changes in the OS' sorting rules for character strings:

https://wiki.postgresql.org/wiki/Locale_data_changes

Such a change causes the unique key's index to be out of sort order
and thus effectively corrupt from PG's viewpoint: searches may or
may not find an entry that is there. Once that happens it's pretty
easy for duplicate entries to get added.

The fix is to REINDEX affected indexes. But if you already have
duplicate entries in the table, you'll need to correct them before
REINDEX will succeed.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Christophe Pettus 2024-11-25 19:59:13 Re: License question
Previous Message Adrian Klaver 2024-11-25 16:00:04 Re: Unique key constraint Issue