Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error on restore a dockerized PostgreSQL database

I have a dockerized Postgres db. I have successfully executed

docker exec -t your-db-container pg_dumpall -c -U postgres > dump_`date +%d-%m-%Y"_"%H_%M_%S`.sql

and generated .sql file. But when I'm trying to restore with the following script:

cat my_dump.sql | docker exec -i your-db-container psql --username="myusername" mydb

I get:

ERROR: syntax error at or near "pg_dumpall"

LINE 1: pg_dumpall: error: could not connect to database "template1"...

What am I missing?

like image 254
Franco Mitoire Avatar asked Nov 20 '25 23:11

Franco Mitoire


1 Answers

The dump file contains an error message from the backup procedure instead of containing a database dump.

docker exec combines the standard output and the standard error. Its output cannot be trusted for a backup file.

Aside from solving the root problem that pg_dumpall in the container cannot connect to template1, you want a more sophisticated dump procedure that cannot create this situation where a shell error message ends up where SQL statements should be.

like image 102
Daniel Vérité Avatar answered Nov 22 '25 11:11

Daniel Vérité



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!