Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1is8vt-0007kq-PD for pgsql-general@arkaria.postgresql.org; Thu, 16 Jan 2020 17:27:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1is8vq-0003Tu-Kf for pgsql-general@arkaria.postgresql.org; Thu, 16 Jan 2020 17:27:46 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1is8vo-0003JH-Tk for pgsql-general@lists.postgresql.org; Thu, 16 Jan 2020 17:27:46 +0000 Received: from [66.111.4.28] (helo=out4-smtp.messagingengine.com) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1is8vj-0006kD-5R for pgsql-general@lists.postgresql.org; Thu, 16 Jan 2020 17:27:44 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 363BA22165; Thu, 16 Jan 2020 12:27:27 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Thu, 16 Jan 2020 12:27:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm2; bh=w weVyRAMRAyKdkETZIFowr5tHte+EsMj8/XNfp0F2Sw=; b=v4oJIcUYFIklrPzR2 3gnJwhoj9QXoK0EbHkGvc6eR0olHf7WqPDwMgJ8CyHtVzKz9kIlDhMOQjgNGqEip vk4Qpachkc+eTVO6IpujYYQHjQ6wiB/HlLYHB79X9kDWSznRaQcadLxS1mYrrKXk m6jeZOfI4mZergIllIMbaiwLDnlVDoiYj2vJThfTe711DIFs7XEDuuZUwPJzPdur yqKCUApYkfMmcYD4oBKCvtMA+jzfQ8SyDjjGHtMvn7u6Q6vAC29jLD8RWi6L98PP DvK7QtOMrdLp3i2DOeHnbt4Xyzsaz3Gx0fw+GfwrablyPvAVixMnB6p+zwSItVC9 gmNhw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=wweVyRAMRAyKdkETZIFowr5tHte+EsMj8/XNfp0F2 Sw=; b=ZWvACplMLKoNU5JwN6SxclSBx+ycMc3xtZn4k8Q7mEKngmlKXd1N/vwJW 9eFuSOJPPbtetEj1Dy9eDYhZ44OBJVcEyqt8TJWrQhZWq2bGnIVf63E2f1vdEC6w Iw+vH5PDFee+uCPOGFQFoq56n+WYGPWGIuW6wutcz2t5DUplcUdW+PhTS5DVC8C+ 7ImyuKnfVZg2oCPhYiV1m8wmRP6GdNnjpRgPp0IL+N9LMijK9MBAunMyu3k3SMPD p82V2YVtoTBPfjgAmcRQabhFqBU9lV2irMbRW9BN+aC1VoFui5qAAmPoFKACWaMj Fnkh3gchH39UKEOrwDy2eQ5t1XefQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrtdehgdelkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefuvfhfhffkffgfgggjtgfgsehtkeertddtfeejnecuhfhrohhmpeetughrihgr nhcumfhlrghvvghruceorggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomh eqnecuffhomhgrihhnpehpohhsthhgrhgvshhqlhdrohhrghenucfkphepjedurddvuddv rdduvdelrdduleefnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrughrihgrnhdrkhhlrg hvvghrsegrkhhlrghvvghrrdgtohhmnecuvehluhhsthgvrhfuihiivgeptd X-ME-Proxy: Received: from [192.168.1.10] (unknown [71.212.129.193]) by mail.messagingengine.com (Postfix) with ESMTPA id 8002F8005A; Thu, 16 Jan 2020 12:27:26 -0500 (EST) Subject: Re: Inexplicable duplicate rows with unique constraint To: Richard van der Hoff , pgsql-general@lists.postgresql.org References: <288488b7-d3b6-905b-3706-43f7a3c7bc52@matrix.org> <1605.1579194518@sss.pgh.pa.us> From: Adrian Klaver Message-ID: Date: Thu, 16 Jan 2020 09:27:25 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.3.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 66.111.4.28 (deferred) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 1/16/20 9:24 AM, Richard van der Hoff wrote: > > On 16/01/2020 17:12, Magnus Hagander wrote: >> On Thu, Jan 16, 2020 at 6:08 PM Tom Lane wrote: >>> >>> Richard van der Hoff writes: >>>> I'm trying to track down the cause of some duplicate rows in a table >>>> which I would expect to be impossible due to a unique constraint. I'm >>>> hoping that somebody here will be able to suggest something I might >>>> have >>>> missed. >>> >>> Since these are text columns, one possibility you should be looking into >>> is that the indexes have become corrupt due to a change in the operating >>> system's sorting rules for the underlying locale.  I don't recall >>> details >>> at the moment, but I do remember that a recent glibc update changed the >>> sorting rules for some popular locale settings.  If an installation had >>> applied such an update underneath an existing database, you'd have a >>> situation where existing entries in an index are not in-order according >>> to the new behavior of the text comparison operators, leading to havoc >>> because btree searching relies on the entries being correctly sorted. >> >> See https://wiki.postgresql.org/wiki/Locale_data_changes for hints on >> which linux distros updated when. >> > Right, thanks to all who have suggested this. > > It seems like a plausible explanation but it's worth noting that all the > indexed data here is (despite being in text columns), plain ascii. I'm > surprised that a change in collation rules would change the sorting of > such strings, and hence that it could lead to this problem. Am I naive? In psql who does: \l the_database_name show? > > To answer Adrian's question: the lengths of the values in the indexed > columns are identical between the duplicated rows. > > -- Adrian Klaver adrian.klaver@aklaver.com