Re: `pg_restore --if-exists` clarification

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: `pg_restore --if-exists` clarification
Дата
Msg-id 998115.1695920626@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: `pg_restore --if-exists` clarification  ("David G. Johnston" <david.g.johnston@gmail.com>)
Ответы Re: `pg_restore --if-exists` clarification  (Gulyás Attila <toraritte@gmail.com>)
Список pgsql-docs
"David G. Johnston" <david.g.johnston@gmail.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



В списке pgsql-docs по дате отправления:

Предыдущее
От: "David G. Johnston"
Дата:
Сообщение: Re: `pg_restore --if-exists` clarification
Следующее
От: Gulyás Attila
Дата:
Сообщение: Re: `pg_restore --if-exists` clarification