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 1iLOKP-0002xH-An for pgsql-bugs@arkaria.postgresql.org; Fri, 18 Oct 2019 09:13:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iLOKM-0005PT-Tx for pgsql-bugs@arkaria.postgresql.org; Fri, 18 Oct 2019 09:13:42 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iLOKM-0005Ov-H0 for pgsql-bugs@lists.postgresql.org; Fri, 18 Oct 2019 09:13:42 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iLOKK-0001a0-3n for pgsql-bugs@lists.postgresql.org; Fri, 18 Oct 2019 09:13:41 +0000 Received: from pro.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x9I9DadF017853; Fri, 18 Oct 2019 05:13:36 -0400 From: Tom Lane To: =?utf-8?Q?Ivan_Panti=C4=87?= cc: "=?utf-8?Q?pgsql-bugs=40lists.postgresql.org?=" Subject: Re: pg_restore creates duplicate records when used with --role parameter In-reply-to: References: Comments: In-reply-to =?utf-8?Q?Ivan_Panti=C4=87?= message dated "Wed, 16 Oct 2019 18:01:58 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <28387.1571390016.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 18 Oct 2019 11:13:36 +0200 Message-ID: <28388.1571390016@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk =3D?utf-8?Q?Ivan_Panti=3DC4=3D87?=3D writes: > I've created a backup using pg_restore like this: > x sudo -u postgres pg_dump source_db --format=3Dcustom' > /tmp/source_db= .db > I then copied the backup file to the destination server and tried to res= tore it like this: > sudo -u postgres psql destination_db -c 'DROP SCHEMA public CASCADE; CRE= ATE SCHEMA public AUTHORIZATION destination_user;' > sudo -u postgres pg_restore -d destination_db --no-owner --role=3Ddestin= ation_user -n public /tmp/source_db.db > I've recieved this error: > pg_restore: [archiver (db)] Error while PROCESSING TOC: > pg_restore: [archiver (db)] Error from TOC entry 2276; 2606 42862 CONSTR= AINT price_history price_history_pkey destination_db > pg_restore: [archiver (db)] could not execute query: ERROR: could not cr= eate unique index "price_history_pkey" > DETAIL: Key (id)=3D(64) is duplicated. > Command was: ALTER TABLE ONLY public.price_history > ADD CONSTRAINT price_history_pkey PRIMARY KEY (id); FWIW, I could not duplicate this report in several tries. Usually, the expectation when restoring a dump is that you're restoring into a totally empty database. Clearing out just the public schema isn't that, so I wonder if you left behind something that could affect this table. It's not very clear what that could be though :-(. Anyway, if you can provide a self-contained reproduction case for this, we'd surely look further. regards, tom lane