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 1rcoZo-002FTk-G0 for pgsql-admin@arkaria.postgresql.org; Wed, 21 Feb 2024 15:32:04 +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 1rcoZm-0052gH-FT for pgsql-admin@arkaria.postgresql.org; Wed, 21 Feb 2024 15:32:02 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rcoZm-0052g8-39 for pgsql-admin@lists.postgresql.org; Wed, 21 Feb 2024 15:32:02 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rcoZi-000Hkf-RK for pgsql-admin@lists.postgresql.org; Wed, 21 Feb 2024 15:32:01 +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 41LFVvfF081492; Wed, 21 Feb 2024 10:31:57 -0500 From: Tom Lane To: Guillaume Lelarge cc: Fabrice Chapuis , M Sarwar , "pgsql-admin@lists.postgresql.org" Subject: Re: pg_restore option --clean In-reply-to: References: Comments: In-reply-to Guillaume Lelarge message dated "Wed, 21 Feb 2024 15:35:14 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <81490.1708529517.1@sss.pgh.pa.us> Date: Wed, 21 Feb 2024 10:31:57 -0500 Message-ID: <81491.1708529517@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Guillaume Lelarge writes: > pg_restore won't drop objects in cascade. There's no option for that. I'd > guess the reason is that --clean only cleans the object it will restore. If > other objects depend on it, pg_restore has no way to know how to recreate > them, and you would end up with a not completely restored database. Yeah. The expectation is that --clean will issue the DROP commands in reverse dependency order, so that no step would require CASCADE. If one did, it'd imply that pg_dump failed to catalog all the dependencies in the database, which would be a bug we'd want to know about. Now, this theory does fail in at least two practical cases: * You're trying to use --clean with a selective restore. * You're trying to restore into a database that has more or different objects than the source DB did. But in both cases, blindly using CASCADE seems like a bad idea. You'd end up with a database that's missing some objects, and you won't know which ones or how to put them back. regards, tom lane