Re: pg_restore option --clean

From: Fabrice Chapuis <fabrice636861(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Guillaume Lelarge <guillaume(at)lelarge(dot)info>, M Sarwar <sarwarmd02(at)outlook(dot)com>, "pgsql-admin(at)lists(dot)postgresql(dot)org" <pgsql-admin(at)lists(dot)postgresql(dot)org>
Subject: Re: pg_restore option --clean
Date: 2024-02-22 08:05:22
Message-ID: CAA5-nLC+Yg3=PRjX2x_WQggvbe3cwhvFE7OseMH2Y=h3OJsqvw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin pgsql-hackers

Effectivly, Tom, we are in the second case, we are carrying out a partial
restore, certain tables remain in place and are not replaced, currently I
have to do manually a DROP... CASCADE and recreate the dependencies
between the objects which are imported and those which are in place.No
choice to continue with this approach.

Regarde, Fabrice

On Wed, Feb 21, 2024 at 4:31 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> Guillaume Lelarge <guillaume(at)lelarge(dot)info> 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
>

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Fabrice Chapuis 2024-02-22 08:32:31 \set to create shortcut
Previous Message Laurenz Albe 2024-02-22 06:52:15 Re: Wraparound

Browse pgsql-hackers by date

  From Date Subject
Next Message Andy Fan 2024-02-22 08:11:12 Re: Reduce useless changes before reassembly during logical replication
Previous Message Bertrand Drouvot 2024-02-22 08:00:24 Re: Injection points: some tools to wait and wake