Re: pg_restore option --clean

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Guillaume Lelarge <guillaume(at)lelarge(dot)info>
Cc: Fabrice Chapuis <fabrice636861(at)gmail(dot)com>, 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-21 15:31:57
Message-ID: 81491.1708529517@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin pgsql-hackers

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

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Nikhil Shetty 2024-02-21 18:17:30 Modify Bootstrap user ID
Previous Message Guillaume Lelarge 2024-02-21 14:35:14 Re: pg_restore option --clean

Browse pgsql-hackers by date

  From Date Subject
Next Message Vladimir Sitnikov 2024-02-21 15:34:49 Re: When extended query protocol ends?
Previous Message David E. Wheeler 2024-02-21 15:14:02 Re: Patch: Add parse_type Function