Re: `pg_restore --if-exists` clarification

From: Gulyás Attila <toraritte(at)gmail(dot)com>
To: "pgsql-docs(at)lists(dot)postgresql(dot)org" <pgsql-docs(at)lists(dot)postgresql(dot)org>
Subject: Re: `pg_restore --if-exists` clarification
Date: 2023-09-29 14:30:47
Message-ID: CADnELpjS93HK4SG6xp6KuwUib2aTbVzy6CSsK1vDifJzM3xrLg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

I would love to see Tom's version in the docs! It is only slightly longer
than the current one, but absolutely clear of the purpose of both, and the
behaviour when used in tandem.

Appreciatively,
Attila

On Thu, Sep 28, 2023 at 1:03 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> "David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> writes:
> >>> .. But pragmatically it doesn't matter, so why not
> >>> reclassify this as a "warning" or a "notice"?
>
> > Because pg_restore is just a client and it is repeating back what the
> > server tells it. And for the server it is an error to drop an object
> that
> > doesn’t exist.
> > psql and pg_restore, as clients, can choose to ignore the errors they
> see,
> > regardless of what kind of error it is, but they don’t take on the added
> > burden of trying to reclassify errors into something else.
>
> If you actually try this, you'll get output like
>
> ...
> pg_restore: error: could not execute query: ERROR: schema "fkpart6" does
> not exist
> Command was: DROP SCHEMA fkpart6;
> pg_restore: error: could not execute query: ERROR: schema "fkpart5" does
> not exist
> Command was: DROP SCHEMA fkpart5;
> pg_restore: error: could not execute query: ERROR: schema "fkpart4" does
> not exist
> Command was: DROP SCHEMA fkpart4;
> pg_restore: error: could not execute query: ERROR: schema "fkpart3" does
> not exist
> Command was: DROP SCHEMA fkpart3;
> ...
> pg_restore: warning: errors ignored on restore: 1488
>
> so the only real problem is that there are (typically) enough of these
> to obscure any errors that might be of greater significance. Still,
> genuine restore errors would come out after the blizzard of failed
> DROPs, so I don't think there's a big problem in practice.
>
> If we actually wanted to change any behavior here, I think what would
> be most profitable to discuss is making --if-exists the default.
> Not sure if we want to go there, but if we'd had the DROP IF EXISTS
> option all along I bet it would have been done that way.
>
> In any case, it's fair to complain about the documentation.
> How about
>
> --clean
>
> Before restoring database objects, issue commands to DROP all the
> objects that will be restored. This option is useful for overwriting
> an existing database. If any of the objects do not exist in the
> destination database, ignorable error messages will be reported,
> unless --if-exists is also specified.
>
> --if-exists
>
> Use DROP ... IF EXISTS commands to drop objects in --clean mode.
> This suppresses "does not exist" errors that might otherwise be
> reported. This option is not valid unless --clean is also specified.
>
> regards, tom lane
>

In response to

Responses

Browse pgsql-docs by date

  From Date Subject
Next Message PG Doc comments form 2023-09-29 16:11:51 Not clear spelling about transaction
Previous Message Tom Lane 2023-09-28 17:03:46 Re: `pg_restore --if-exists` clarification