Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tFbY1-00EEb6-Do for pgsql-general@arkaria.postgresql.org; Mon, 25 Nov 2024 16:02:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tFbY0-00G8YT-4Y for pgsql-general@arkaria.postgresql.org; Mon, 25 Nov 2024 16:02:48 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tFbXz-00G8YL-Ph for pgsql-general@lists.postgresql.org; Mon, 25 Nov 2024 16:02:47 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tFbXt-003nFy-5K for pgsql-general@postgresql.org; Mon, 25 Nov 2024 16:02:47 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 4APG2cWR1348981; Mon, 25 Nov 2024 11:02:38 -0500 From: Tom Lane To: shashidhar Reddy cc: pgsql-general Subject: Re: Unique key constraint Issue In-reply-to: References: Comments: In-reply-to shashidhar Reddy message dated "Mon, 25 Nov 2024 12:00:55 +0530" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1348979.1732550558.1@sss.pgh.pa.us> Date: Mon, 25 Nov 2024 11:02:38 -0500 Message-ID: <1348980.1732550558@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk shashidhar Reddy 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