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 1sL8lg-00Ddza-12 for pgsql-general@arkaria.postgresql.org; Sat, 22 Jun 2024 21:59:32 +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 1sL8le-00GatY-1Q for pgsql-general@arkaria.postgresql.org; Sat, 22 Jun 2024 21:59:30 +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 1sL8ld-00GatQ-MF for pgsql-general@lists.postgresql.org; Sat, 22 Jun 2024 21:59:30 +0000 Received: from fout2-smtp.messagingengine.com ([103.168.172.145]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sL8lX-0032qI-MZ for pgsql-general@lists.postgresql.org; Sat, 22 Jun 2024 21:59:29 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.nyi.internal (Postfix) with ESMTP id 20A3513800D0; Sat, 22 Jun 2024 17:59:22 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Sat, 22 Jun 2024 17:59:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm1; t=1719093562; x=1719179962; bh=mBKfD2zttMoJKVyihCx1bodF0boQf9aJb7sgGoJQ2Ss=; b= wIeK9FLk11WgEcbmGxKc0i7+jjc8LpsjXY6UO0kwywIt8FW/fZVyZf02D7jcJ2fR 3w0SKyLpR7Nv5oDTBvQiSB//xBZNF1IGBs6jhejIgcJwiVQWK8nFGpFNOM80aDY3 VG1EBsYz8GtTeycgfzIx5qTRy3ZbjzNAG4QgD9UFymB9mqlMAKE6gSybeAw2WrdY 1rQt4ND2DwIm6BbrvnXbJ13xVbjJaVAU8qrHhI78wYIpZjDH/L7A05GgJvxekfOl 1nZm9fcJB+UPupFL1fAKYYFIRL3xDSQDMXq+1b7vG9D7iCcSslnL12srV8hyi+A1 TwpV9fxlxvppSTLX+G6EiA== 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:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1719093562; x= 1719179962; bh=mBKfD2zttMoJKVyihCx1bodF0boQf9aJb7sgGoJQ2Ss=; b=L WPBU6OAgoGKS8NfEJvLP7T4e2NSNhHg+PyIPqlTWv/9ZCz2qgLDJB5lA8EuFdVOr yFvPwCjYe/JlnImoTS8MEoqH1kQPSqs5AxcYLXruQGE6Yv3WFgsg8IsLKDepdn3V A2DRfi2VlU2sFkDnsxc0TLKcQWp0xXfIVuiBuJ6ycoAlDV/DMrTXiyQqzhqn5Bk7 tc3Y56VyaRd8bY8SoZacdeWbjFzP5TfH0YG9pLX21yp3Lf1STuHc64KKzH8jgu+c AKZS7EZ1GHZmS/2thJF0kO8CKGHG9Ihf+D9ecAtNJNzPZgVAQDTQeVHHOzmcYRr3 so8Y3cFCdoDdLJKSr0whg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrfeefjedgtdefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffvfhfhjggtgfesthekredttddvjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucggtffrrghtthgvrhhnpeffleegieefgfevudehtdfhkeeutdffjeevgeffgeej vedthefgudeiteefheejheenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhm X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 22 Jun 2024 17:59:21 -0400 (EDT) Message-ID: <2fa6e6cb-a220-4de0-b08f-6ac4cca667af@aklaver.com> Date: Sat, 22 Jun 2024 14:59:21 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: pg_dump restores as expected on some machines and reports duplicate keys on others To: Shaheed Haque , pgsql-general list References: Content-Language: en-US From: Adrian Klaver In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 6/22/24 10:01, Shaheed Haque wrote: > Hi, > > I am using Postgres 14 on AWS RDS and am seeing the output of pg_dump be > restored as expected by pg_restore on some database instances, and fail > with reports of duplicate keys on other database instances: > > * My deployments are always a pair, one "logic VM" for Django etc and > one "RDS instance". The psql client runs on the logic VM. The > Postgres version is the same in all cases; psql reports: > > o psql (14.12 (Ubuntu 14.12-0ubuntu0.22.04.1), server 14.9) > > * The pg_restore is done using the same script in both cases. > * In the failing cases, there are always the same 26 errors (listed in > detail below), but in summary, 3 distinct "child" tables complain of > a duplicate id=1, id=2 and id=3 respectively. > * These "child" tables are FK-related via some intermediate table to a > top level table. They form a polymorphic set. There are other > similar child tables which do not appear to be affected: > o polymorphicmodel > + companybankdetail > # companybankdetailde > # companybankdetailgb  <<< 1 duplicate, id=2 > # companybankdetailus > + companypostaldetail > # companypostaldetailde > # companypostaldetailgb  <<< 1 duplicate, id=1 > # companypostaldetailus > + companytaxdetail > # companytaxdetailde > # companytaxdetailgb  <<< 1 duplicate, id=3 > # companytaxdetailus > + ... > + several other hierarchies, all error free > + ... > * I've looked at the dumped NNNN.dat files but they contain no duplicates. > * The one difference I can think of between deployment pairs which > work ok, and those which fail is that the logic VM (i.e. where the > psql client script runs) is the use of a standard AWS ubuntu image > for the OK case, versus a custom AWS image for the failing case. > o The custom image is a saved snapshot of one created using the > standard image. > > Why should the use of one type of VM image versus another cause > pg_restore to hallucinate the duplicate records? > 1) Show the complete pg_restore script. 2) The first issue is related to trying to create a database that already exists. Does that database have data in it? -- Adrian Klaver adrian.klaver@aklaver.com