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 1tG7qQ-0014Dm-2k for pgsql-general@arkaria.postgresql.org; Wed, 27 Nov 2024 02:31:58 +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 1tG7qO-00B5Np-DQ for pgsql-general@arkaria.postgresql.org; Wed, 27 Nov 2024 02:31:56 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tG7qN-00B5Ng-VJ for pgsql-general@lists.postgresql.org; Wed, 27 Nov 2024 02:31:55 +0000 Received: from mail-lf1-x12d.google.com ([2a00:1450:4864:20::12d]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tG7qK-0044nj-VQ for pgsql-general@postgresql.org; Wed, 27 Nov 2024 02:31:54 +0000 Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-53da209492cso8019973e87.3 for ; Tue, 26 Nov 2024 18:31:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732674711; x=1733279511; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=fHs44/awHzAB2udb7VjWBhFPIVfUzlxbBDAqOcZHn3w=; b=dAISL5LgV1WDQ5wwdkqtgjf9duyI8MFp82lz+EhzmNDhMab2PcERG0TBpGj7KK7RxK J+CKmnXsqFsJU7bvgOXUyw7za4V9r+bJxiyc/NeQgYv4q2OiTHQgBwKIN4Ku7172Dj1p iQjXWcRkwnbY8QWj3B+BIRkMQcO7vo6Kl3BhS7hWLa6GU3ZHusUfQpiO9au1uJcK9Vrk pyHuCTGvkCUiOTCWSw/uZ3xqyu3Hxl3icodYUMy/ekRhuMQWLVswWa6gKFIB2CX12eyH 208p9cIr4n5Ey7n/rz6zUq65dT0pSAMU/LMsc8rmcUyDzI85iaB2pibLHH4X50nBy5i/ Q0jA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732674711; x=1733279511; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=fHs44/awHzAB2udb7VjWBhFPIVfUzlxbBDAqOcZHn3w=; b=ebFC2f+X+uWhy4yaA2sKIY1DKybTHH3I6YIj2XDKoFAAq8nXqNUe51BtGrYsQfT09T 49trg6QEXWfEe6ycjz4sTQJJu2eVQSSRhKn26VXiffvDYR3RN4WhTy0NbcItAECo+Ep9 FzNeIKXrIkBlnjCxQmpZuH4Fkiq3TtgRXVysJb5RNY2bWwzQ5ehIIFDz6rf5wqq/ziay kk9OOZpDpMzc5D/O/Bu8nMJr1zArTtBb3s1wX7ez91sh6MQmT683VARV/CYsRioJMdUP c4Megua4WaswZfbg/2qw2S7L+zfwOVmfsto8+ONbVjsjSrdBo5zHssRsWNjnORcIHrYi t02w== X-Gm-Message-State: AOJu0YxNRZvmaGXP12WNmCqUXdD/OAt4xNa9OkdkZF5XNfgnZyTAISjk +ZY0V+r8EkH7Zw0HX6yUmGhwp6vMPYolQ0aftNgwsiEQo905KtobGl91RuT2Sn0d8+xJSFvzAX4 N2bYoQJ3SFYYOzGDyEIJUK0lpVFLwNw== X-Gm-Gg: ASbGnctmBUpqIRPAaqzRuIcepqVLGO55TRzyaVs9vl7WsPKHWas+HILNEFwZHwCc0XB O/oVgj6ZCUUNwR0ZLHYIyOLhDVtK6bbcR X-Google-Smtp-Source: AGHT+IH1FxIFu/W5qZOeML31ZNWWZNoG2Ze41RY9RskYjYkoYr8oPoN91nSy9c2bEglrifjYpPd3MC8kkYBGsSZ3gB8= X-Received: by 2002:a05:6512:2395:b0:53d:effe:592d with SMTP id 2adb3069b0e04-53df00d94b6mr510433e87.26.1732674710876; Tue, 26 Nov 2024 18:31:50 -0800 (PST) MIME-Version: 1.0 References: <1348980.1732550558@sss.pgh.pa.us> In-Reply-To: <1348980.1732550558@sss.pgh.pa.us> From: shashidhar Reddy Date: Wed, 27 Nov 2024 08:01:39 +0530 Message-ID: Subject: Re: Unique key constraint Issue To: Tom Lane Cc: pgsql-general Content-Type: multipart/alternative; boundary="000000000000a73ab90627dbc4ca" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000a73ab90627dbc4ca Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Thank you Tom! The issue is with OS upgrade we could able replicate it. On Mon, 25 Nov, 2024, 9:32=E2=80=AFpm Tom Lane, wrote: > 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 > --000000000000a73ab90627dbc4ca Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Thank you Tom!

The issue is with OS upgrade we could able replicate it.

=
On Mon, 25= Nov, 2024, 9:32=E2=80=AFpm Tom Lane, <tgl@sss.pgh.pa.us> wrote:
shashidharreddy001@gmail.com> write= s:
> 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/Loca= le_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.=C2=A0 Once that happens it's prett= y
easy for duplicate entries to get added.

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

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 regards, tom lane
--000000000000a73ab90627dbc4ca--