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 1mfiyF-0006NC-1e for pgsql-general@arkaria.postgresql.org; Wed, 27 Oct 2021 13:27:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mfiyD-0005nY-Uo for pgsql-general@arkaria.postgresql.org; Wed, 27 Oct 2021 13:27:57 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mfiyD-0005nP-Ko for pgsql-general@lists.postgresql.org; Wed, 27 Oct 2021 13:27:57 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mfiyB-0003Dj-1g for pgsql-general@postgresql.org; Wed, 27 Oct 2021 13:27:57 +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 19RDRpId237199; Wed, 27 Oct 2021 09:27:51 -0400 From: Tom Lane To: Tore Halvorsen cc: Postgres General Subject: Re: pg_dump and pg_restore and foreign keys In-reply-to: References: Comments: In-reply-to Tore Halvorsen message dated "Wed, 27 Oct 2021 13:27:26 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <237197.1635341271.1@sss.pgh.pa.us> Date: Wed, 27 Oct 2021 09:27:51 -0400 Message-ID: <237198.1635341271@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Tore Halvorsen writes: > I'm trying to restore a database where adding foreign key constraints takes > most of the time. Does there exist a simple way to make either pg_dump or > pg_restore handle them as "not valid", and defer the validation. No. It's kind of a neat idea perhaps, but it's not there. You could * use parallel pg_restore to alleviate the pain, or * use pg_restore's -l and -L switches to strip out the FKs altogether, and then re-add them manually afterwards. Or there's always * hack the pg_dump source code to include NOT VALID. While a real feature patch that made this optional would be a bit complicated, doing it unconditionally should be a one-line change. regards, tom lane