Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

issue with pg_restore s exit code when warnings are there

commands:

bin/pg_dump -b -o -Fc -Z 0 -p 5333 -U user template1 -f db.dump
bin/pg_restore -c  -h localhost -p 5333 -U user -d template1 db.dump 

steps followed:

  1. add new tables to DB and took dump

  2. delete the newly added tables

  3. try restore with dump file

  4. restore exited with code 1 but still tables are restore successfully.

error in pg_restore:
pg_restore: [archiver (db)] could not execute query: err-1: table "test1" does not exist
Command was: DROP TABLE public.test1;
WARNING: errors ignored on restore: 2

Is this the expected behavior for dump/restore feature with tables add/delete steps?

like image 531
Ras Ram Avatar asked Jan 20 '26 04:01

Ras Ram


1 Answers

Yes, you are instructing pg_restore to drop objects before creating them, but those objects don't exist anymore. The docs explain this for the -c option:

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.

like image 89
Jeremy Avatar answered Jan 21 '26 23:01

Jeremy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!