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 1nTsJQ-0002AV-TU for pgsql-novice@arkaria.postgresql.org; Mon, 14 Mar 2022 21:33:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nTsJP-0004cx-Km for pgsql-novice@arkaria.postgresql.org; Mon, 14 Mar 2022 21:33:07 +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 1nTsJP-0004co-Cn for pgsql-novice@lists.postgresql.org; Mon, 14 Mar 2022 21:33:07 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nTsJN-0005Dg-3d for pgsql-novice@lists.postgresql.org; Mon, 14 Mar 2022 21:33:06 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 22ELX2un225371; Mon, 14 Mar 2022 17:33:02 -0400 From: Tom Lane To: flik cc: pgsql-novice@lists.postgresql.org Subject: Re: Fixing Integrity check errors In-reply-to: <9bde7204-1b4c-8702-4593-5afd0607c5d2@gmail.com> References: <9bde7204-1b4c-8702-4593-5afd0607c5d2@gmail.com> Comments: In-reply-to flik message dated "Mon, 14 Mar 2022 21:14:55 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <225369.1647293582.1@sss.pgh.pa.us> Date: Mon, 14 Mar 2022 17:33:02 -0400 Message-ID: <225370.1647293582@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk flik writes: > What would be the best way to solve integrity errors (unique > constraints) caused by a badly done dump/restore? My best guess as > ignorant ass, it's simply to dump the current data (only), start a new > project, apply the migrations and loading back data. > Given that the schema is exactly the same, would this work? If so, how > can I do it with postgres? > I already tried to pg_dump --data-only but I keep getting weird errors. --data-only is really the source of your problem, probably. If you do a normal (full) pg_dump and restore into an empty database, then pg_dump should see to loading your data and installing constraints in the correct order. With --data-only it can't make as many guarantees. Usually, however, that only comes up with foreign key constraints. If you're seeing unique-constraint failures then there might be something else going on, such as * you forgot to make sure the tables are empty before adding data * or there's something corrupt about the indexes regards, tom lane