Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pmyiH-0007eD-HJ for pgsql-bugs@arkaria.postgresql.org; Thu, 13 Apr 2023 15:18:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pmyiF-0006kz-U8 for pgsql-bugs@arkaria.postgresql.org; Thu, 13 Apr 2023 15:18:15 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pmyiF-0006kq-Lr for pgsql-bugs@lists.postgresql.org; Thu, 13 Apr 2023 15:18:15 +0000 Received: from wout5-smtp.messagingengine.com ([64.147.123.21]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pmyiC-00061Q-Tl for pgsql-bugs@lists.postgresql.org; Thu, 13 Apr 2023 15:18:14 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 18C2D3200940; Thu, 13 Apr 2023 11:18:11 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Thu, 13 Apr 2023 11:18:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:reply-to:sender :subject:subject:to:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1681399090; x=1681485490; bh=m aw0mLCwFTxSElFeZvms9o3G4s2L0xuyyrQEialAwC8=; b=fCRXz/8qcFF6RLqt7 LUM02oVdU4ThwuSU9FGjPlYaZXTHjCTAnd7zGbtsWwBZ8jeP+0ElX2cwMazthKVI if008ipmQRXEQNt3zlnCYrGaIQPzr92PO81+tjV9BS0mgr43/bJfR4SlpNmHLNYb HjjlnOD8B1mG9SWzg41SLAd8uyLDCyxLy4PuJhPOx04sZ7DAQBdq3b1E4B+FIMT1 zo3Joj2qD0oqEoZW7LVhGNX9bFnOXjEyRu4hUXEt28Q7vJH7xyE86DCftPSflJ8V xnXx39By6MJgDMfRh4lIuj8iGFkRJFw7/S/Q8J8klUt22PM4BM/29abSu20byliO m7dGA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdekkedgkeejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkgggtugfgjgesthekre dttddtjeenucfhrhhomheptehlvhgrrhhoucfjvghrrhgvrhgruceorghlvhhhvghrrhgv segrlhhvhhdrnhhoqdhiphdrohhrgheqnecuggftrfgrthhtvghrnhepfeduleekteeigf egledtvddvvddtledugfefhfdtieevteeftdeuueehudeuvdelnecuffhomhgrihhnpegv nhhtvghrphhrihhsvggusgdrtghomhdpphhoshhtghhrvghsqhhlrdhorhhgnecuvehluh hsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprghlvhhhvghrrhgv segrlhhvhhdrnhhoqdhiphdrohhrgh X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 13 Apr 2023 11:18:10 -0400 (EDT) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 53DE8A1; Thu, 13 Apr 2023 17:18:08 +0200 (CEST) Date: Thu, 13 Apr 2023 17:18:08 +0200 From: Alvaro Herrera To: comanicibogdy@yahoo.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17892: Bug primary key Message-ID: <20230413151808.dlrbdvedxkmtflp2@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <17892-ac3a507a8e97a453@postgresql.org> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2023-Apr-12, PG Bug reporting form wrote: > The following bug has been logged on the website: > > Bug reference: 17892 > Logged by: Comanici Bogdan > Email address: comanicibogdy@yahoo.com > PostgreSQL version: 13.9 > Operating system: Debian 11 > Description: > > We have a database with over 3 milions apps in it > Something happend we just found duplicates with same id, but we have > constraints : PRIMARY KEY on id > > How it's happened? > ID(PRIMARY KEY) SLUG(UNIQUE KEY) > 29181513 nottiled 0 Home-and-Hobby Recreation mirwanda-center false 0 false false false true false 2019-07-15 > 11:53:38.000 2023-04-10 > 21:44:34.000 0.0 0.0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 NotTiled 0 0.00 1.8.6 Freeware 0.0 2022-09-19 adsense true 0 2 false > 29181513 nottiled 0 Home-and-Hobby Recreation mirwanda-center false 0 false false false true false 2019-07-15 > 11:53:38.000 2023-03-25 > 14:32:55.000 0.0 0.0 0 26 0 1 0 26 0 0 5 0 0 0 5 0 0 NotTiled 22020096 0.00 1.7.0a Freeware 0.0 2021-09-03 adsense true 20230410 2 false > > We tried manually to insert a new row with same value, get error for unique > key slug It sounds like both are different row versions of the same row, given that they have the same ID and SLUG. To me it sounds like the second row shown here existed, then an UPDATE came along and created the other one (changing for example the second timestamp column from '2023-03-25 14:32:55.000' to '2023-04-10 21:44:34.000', among other things); and then the first one should have been deleted but wasn't. This could have happened, for example, if VACUUM later processed the table, removed a few dead entries at the end of the table, but while it was waiting to truncate the last few pages empty of any live tuple, a crash came along; then, after recovery, pages which should have been truncated away, came back to life. You say you have more cases of the same thing; maybe check the "ctid" values for the duplicates; if you can see a bunch of them nearby, in a page close to the physical end of the table, that bug may explain the issue. You have a column which in the second copy of the row has the value 20230410, which appears to match another timestamp column in the other copy of the row. That's a curious coincidence; I wonder if that column indicate "recheck this app by this time" or something like that. Not that it matters ... -- Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/ "This is what I like so much about PostgreSQL. Most of the surprises are of the "oh wow! That's cool" Not the "oh shit!" kind. :)" Scott Marlowe, http://archives.postgresql.org/pgsql-admin/2008-10/msg00152.php