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 1is8sM-0007bt-E8 for pgsql-general@arkaria.postgresql.org; Thu, 16 Jan 2020 17:24:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1is8sL-000266-16 for pgsql-general@arkaria.postgresql.org; Thu, 16 Jan 2020 17:24:09 +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 1is8sK-00024R-ND for pgsql-general@lists.postgresql.org; Thu, 16 Jan 2020 17:24:08 +0000 Received: from polemos.matrix.org ([94.237.46.156]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1is8sG-0006i6-51 for pgsql-general@lists.postgresql.org; Thu, 16 Jan 2020 17:24:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=matrix.org; s=polemos; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:MIME-Version :Date:Message-ID:From:References:To:Subject:Sender:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=tnnkab2cjFd3LPofmqPbinS3QlxT0W+JEXTgU8jDbDU=; b=YV4+TDRK3SXe9K2aTzLj4pP81L kIUHlW1vpWHHJ8nOPpxopZgSMylktjXtFAL8bk8g+Vw0iliSYU5s6SDtfmmmA4/7OjureDoDayP+C HVhavfkEVmb2ZDzYC42tFUtkNJz/1Iw0Ze0JUVcvddXbiH6Xd7E/lSOc2ZwUQbKCsiR9pLCeWKV0n Oh/156tI+QQZPHuxeHJDnlxJeOnx7Ap2udeRnrnF8JadNLD0QKw7h5qkQdMxkbuVUZ4h/iwaNZLIf k/xKQiZzdJRIFkbUWsnhGd+fuCfzM0lpDfoGgAWJQLhdM8QcbEnum5vl+AxsKYMAF0gsXWiC1k/HC qgTplKr61iHcNfWJxac/INYffTciOUnDBau29yxVFI8LGdOe9HHbH70R4pPaSE1bFgbNtH3yG+/Si KEoY1fue8dXx/lhd7BeCDCjQiB3bDc7Uvq4m3WuJURrN0f0OZfmse0BkY68hXwfyV5aqJ8z3IvKil TK9K9MO0AmF5jkbrsxd5WNcoZUyYLDlbLI/a8Ve5W9OUj0+woMiqZd2jXbe9lYkCI29zGiA+XpLuU mfs6MDmekTIV+fO6QB18M60vOzdy557zmJl1Egw70yLduWbYpFTQqLdGo4VZC+fd+wgjzKLQgHdYd PUFiKBQW9KsAUzqBK9Uo+ICnbfiaa23BGi3BoX5F8=; Received: from [2001:8b0:ba7a:e98f:2d18:c4bf:423e:ed6f] by polemos.matrix.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1is8sF-0008Je-5c for pgsql-general@lists.postgresql.org; Thu, 16 Jan 2020 17:24:03 +0000 Subject: Re: Inexplicable duplicate rows with unique constraint To: pgsql-general@lists.postgresql.org References: <288488b7-d3b6-905b-3706-43f7a3c7bc52@matrix.org> <1605.1579194518@sss.pgh.pa.us> From: Richard van der Hoff Message-ID: Date: Thu, 16 Jan 2020 17:24:02 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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? To answer Adrian's question: the lengths of the values in the indexed columns are identical between the duplicated rows.