Re: `pg_restore --if-exists` clarification

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Gulyás Attila <toraritte(at)gmail(dot)com>
Cc: "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-28 16:36:34
Message-ID: CAKFQuwbM2s5Naeb4SZted17zM=r_-C8w07-Bw-SyYd1b8a4LRA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

On Thursday, September 28, 2023, Gulyás Attila <toraritte(at)gmail(dot)com> wrote:

> So `--if-exists` simply suppresses any notice / warning that would occur?
>

That switch causes the drop DDL produced by pg_restore to include if exists
clauses. The server then simply treats the DDL as a no-op if said object
being dropped cannot be found.

>
>> But "failure" is not what happens. If you read the part regarding
>> --clean, you will see that it says:
>>
>> (Unless --if-exists is used, this might generate some *harmless error
>> messages*, if any objects were not present in the destination database.) *[emphasis
>> added]*
>> with extra emphasis on the word "harmless" -- no failure is caused; the
>> restore proceeds just fine.
>> If anything were to change in this regard, it might be better to
>> reconsider what we call the message (i.e.what language pg_restore emits in
>> this scenario.) It's true, I suppose, in a literal sense that it's an
>> error in that pg_restore couldn't drop a table when instructed to, where no
>> such table exists. 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.

David J.

In response to

Responses

Browse pgsql-docs by date

  From Date Subject
Next Message Tom Lane 2023-09-28 17:03:46 Re: `pg_restore --if-exists` clarification
Previous Message Gulyás Attila 2023-09-28 16:12:20 Re: `pg_restore --if-exists` clarification