Reputation: 147
I have a dump of my production db, which I can restore easily in my docker container with: docker exec -it my_db_container pg_restore --user=my_user --dbname=dbname sql/current.dump
. Everything works, data are here.
But when I re-dump my local database from the docker with docker exec -it my_db_container -U my-user -F c -b dbname > docker/db/current_stripped.dump
back to project folder, my dump file is created (with appropriate size and content) but I can not use it for restoring (docker exec -it whasq-db pg_restore --user=my-user --dbname=dbname sql/current_stripped.dump
) it again to a fresh db due to an error: pg_restore: [custom archiver] could not read from input file: end of file
however the restore command is the same (except the my_user
which is postgres in production) as used in production env.
Upvotes: 2
Views: 3221
Reputation: 1
Old thread, but I have encounter this issue also with Postgres 16 running on Docker.
The issue is running pg_dump with docker exec -t or -ti. The pseudo-TTY appends some EOL to the generated backup file and therefore pg_restore does not accept it later.
Just run your commands without -ti:
docker exec my_db_container pg_dump -Fc --user=my_user --dbname=dbname > sql/current.dump
docker exec my_db_container pg_restore -Fc --user=my_user --dbname=dbname sql/current.dump
You could find a discussion over this topic on this github issue: https://github.com/docker-library/postgres/issues/219
Upvotes: 0
Reputation: 1009
I had the same problem and solved it as follows. I switched to the -f
or --file
option instead of piping (taken from https://stackoverflow.com/a/51073680/6593069). And I created the dump file inside the container and then copied it to my host.
That would mean in your case:
docker exec -it my_db_container -U my-user -F c -b dbname -f current_stripped.dump
docker cp my_db_container:current_stripped.dump .
Upvotes: 1