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 1sL8Us-00Dcut-3B for pgsql-general@arkaria.postgresql.org; Sat, 22 Jun 2024 21:42:10 +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 1sL8Up-00GJAO-UW for pgsql-general@arkaria.postgresql.org; Sat, 22 Jun 2024 21:42:08 +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 1sL8Up-00GJAG-FB for pgsql-general@lists.postgresql.org; Sat, 22 Jun 2024 21:42:07 +0000 Received: from mail-oa1-x31.google.com ([2001:4860:4864:20::31]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sL8Un-0032cQ-JB for pgsql-general@postgresql.org; Sat, 22 Jun 2024 21:42:07 +0000 Received: by mail-oa1-x31.google.com with SMTP id 586e51a60fabf-254a7fe21aeso1911262fac.0 for ; Sat, 22 Jun 2024 14:42:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719092522; x=1719697322; darn=postgresql.org; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=yuywDkoH15iSMk+gX3Hl1+e/QoEGCz1QfnKRywHqkqk=; b=ctXjRSnUq6UjSBCFoX3DKkFb/16nDbWWK38CHJ7qqAMCK44g/IIQxlJshbOqYHPQiR +R4Mlz4LmoCxk4jc8QkO6Vqt/R8v1vndRLiKaDJhKxWeulDZtGrblB7qm1e3eR6VE/kJ jxfqiwrRoa3JpItrsJtTK0j6HjErFzLQBZvKWZEqmauDQYaCgzRKmENgc7ypDrzu/ObI IAyrHgOFbAdHsSoGlAQq0q9MnF/puBjMFLRRGRWCFQp1fid180Xd9m5Q4GbWT0MaypgF M4ukV+ByUgO/8R7ea+gCrmYrnOB4N2z6lmXw1ynQy57JK36BNU4BSltodAmd4Zj+jT2m JoQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719092522; x=1719697322; h=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=yuywDkoH15iSMk+gX3Hl1+e/QoEGCz1QfnKRywHqkqk=; b=u4kdznHpfK8qK7ZrtjJi+M67uM6DI96wJIWdn8M+8K4Wgt2qVv1koD5F4F7avIJngn OxUgsk4XLcXtVz3LJcFfzCaET5DXqsD2ACyNY0kS5kmuvq+nELBcc7j3tumEy1qaRBGF mvda37ArOdiiRvsqNL7Y6aqPqso1P1PAllKURn6wpCMxcce/fxSXTiC2NO7m8LWhe1Jy Yb7Gel1TBXZOaIeKYjAU4CjhBYdQSTmu53BedX28dMJnTPtYp2fpu9DPv/9l9B3gVMmH z4ZvNjGY2FkPEOz+sFXrQkKau6TrqjwHx6WnxIQeqVzM4Fu1p6rGd+dLS+10cxPuYBrn rG0Q== X-Gm-Message-State: AOJu0Yzei8KUlzPgrJRARw82q2eAZK2jH1UOJI5XRQ/EClxuJ/5fqOFR rk/JHpWWIrclMAqMe960cwz28xW8aiB5WzUdkbvcslGkn+ZziRcvFGOgkj0c9H/psqBIlPgT/qO e5aejsz9u6T+NOZ4z6jje5GhhFhktFA== X-Google-Smtp-Source: AGHT+IGnQTxEYWDTpattHhl0wDd3bDOxWQml5IqSpVISHHAxLJJBOk+CrgLRnJ7JmJFlqMha19Z3maB+Xk9oUbeXcFI= X-Received: by 2002:a05:6870:7d01:b0:24f:d9e5:b208 with SMTP id 586e51a60fabf-25cf9359fd2mr982475fac.6.1719092522156; Sat, 22 Jun 2024 14:42:02 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Ron Johnson Date: Sat, 22 Jun 2024 17:41:51 -0400 Message-ID: Subject: Re: pg_dump restores as expected on some machines and reports duplicate keys on others To: pgsql-general Content-Type: multipart/alternative; boundary="0000000000001e894c061b816b8e" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000001e894c061b816b8e Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sat, Jun 22, 2024 at 1:02=E2=80=AFPM 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: > > > - 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=3D1, id=3D2 and id=3D3 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: > - polymorphicmodel > - companybankdetail > - companybankdetailde > - companybankdetailgb <<< 1 duplicate, id=3D2 > - companybankdetailus > - companypostaldetail > - companypostaldetailde > - companypostaldetailgb <<< 1 duplicate, id=3D1 > - companypostaldetailus > - companytaxdetail > - companytaxdetailde > - companytaxdetailgb <<< 1 duplicate, id=3D3 > - 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 psq= l > 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. > - 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_restor= e > to hallucinate the duplicate records? > > Encls: 26 errors as mentioned... > > =3D=3D=3D=3D=3D=3D=3D=3D > pg_restore: while PROCESSING TOC: > pg_restore: from TOC entry 5635; 1262 53894 DATABASE foo postgres > pg_restore: error: could not execute query: ERROR: database "foo" alread= y > exists > Command was: CREATE DATABASE foo WITH TEMPLATE =3D template0 ENCODING =3D > 'UTF8' LOCALE =3D 'en_US.UTF-8'; > Check *all* of the client and server encodings. 99.99% of the time, that's the problem when the same dump file fails to restore on different servers. --0000000000001e894c061b816b8e Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Sat, Jun 22, 2024 at 1:02=E2=80=AFPM S= haheed Haque <shaheedhaque@gma= il.com> wrote:
Hi,

I am using Postgres 14 on AWS RDS and am seeing the output of pg_d= ump be restored as expected by pg_restore on some database instances, and f= ail with reports of duplicate keys on other database instances:
<= ul>
  • My deployments are always a pair, one "logic VM" for Djang= o etc and one "RDS instance". The psql client runs on the logic V= M. The Postgres version is the same in all cases; psql reports:
    • 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 ar= e always the same 26 errors (listed in detail below), but in summary, 3 dis= tinct "child" tables complain of a duplicate id=3D1, id=3D2 and i= d=3D3 respectively.=C2=A0
    • These "child" tables are FK-rel= ated via some intermediate table to a top level table. They form a polymorp= hic set. There are other similar child tables which do not appear to be aff= ected:
      • polymorphicmodel
        • companybankdetail
          • <= li>companybankdetailde
          • companybankdetailgb=C2=A0 <<< 1 dup= licate, id=3D2
          • companybankdetailus
        • companypost= aldetail
          • companypostaldetailde
          • companypostaldetailgb=C2= =A0 <<< 1 duplicate, id=3D1
          • companypostaldetailus
          • =
        • companytaxdetail
          • companytaxdetailde
          • companytax= detailgb=C2=A0 <<< 1 duplicate, id=3D3
          • companytaxdetai= lus
        • ...
        • 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 betwe= en deployment pairs which work ok, and those which fail is that the logic V= M (i.e. where the psql client script runs) is the use of a standard AWS ubu= ntu image for the OK case, versus a custom AWS image for the failing case.<= /li>
      • The custom image is a saved snapshot of one created using the s= tandard image.
    Why should the use of one type of VM = image versus another cause pg_restore to hallucinate the duplicate records?=

    Encls: 26 errors as mentioned...
    =3D=3D=3D=3D=3D=3D=3D=3D
    pg_restore: while PROCESSING TOC:
    pg_restore: from TOC entry 5635; 1262 53894 DATABASE foo postgre= s
    pg_restore: error: could not execute query: ERROR: =C2=A0database "= ;foo" already exists
    Command was: CREATE DATABASE foo WITH TEMPLATE =3D template0 ENCODING = =3D 'UTF8' LOCALE =3D 'en_US.UTF-8';
    =

    Check all=C2=A0of the client = and server encodings.

    99.99% of the time, that'= ;s the problem when the same dump file fails to restore on different server= s.
    --0000000000001e894c061b816b8e--