pg_restore: [archiver] input file is too short error in postgres
Asked Answered
A

4

16

I am trying to dump the database in my local system by using the command :

pg_restore --host=localhost --port=5432 --dbname=dev_db --no-owner --no-privileges db_dump_new.backup

but I am getting the error :

pg_restore: [archiver] input file is too short (read 0, expected 5)

What am I doing wrong?

Ashantiashbaugh answered 7/4, 2016 at 7:37 Comment(1)
My initial guess would be that the problem was with the pg_dump rather than the pg_restore. How big is the db_dump_new.backup file?Sloganeer
M
16

If you're using docker and redirecting the dump file from your local machine, don't forget -i. This won't work:

docker exec <container> pg_restore -U "$USER" < ./localfile.dump;

Be sure that the docker container can see standard in with the -i option! This should work:

docker exec -i <container> pg_restore -U "$USER" < ./localfile.dump;
Mancilla answered 8/1, 2020 at 19:26 Comment(0)
O
4

I encountered the same error. In my case I had simply neglected to specify the backup file at the end of the command.

Osorio answered 22/6, 2016 at 8:6 Comment(1)
ended up with very same error because lost `` of multiline bash script....Gambetta
C
1

In my case I used docker

$ docker exec a5f7b094c523 pg_restore -d my_new_db < "./2256.dump"
pg_restore: [archiver] input file is too short (read 0, expected 5)

And the issue was that "./2256.dump" is not a binary file but a plain sql text dump.

To check that just do

$ head ~/2256.dump                                                                                                    
--
-- PostgreSQL database dump
--

-- Dumped from database version 10.8 (Ubuntu 10.8-0ubuntu0.18.04.1)
-- Dumped by pg_dump version 10.8 (Ubuntu 10.8-0ubuntu0.18.04.1)

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;

And to import sql dump fo

$ pv ~/2256.dump |docker-compose -f docker-compose.dev.yml -f docker-compose.override.yml -T db psql "fight-round3" 
Claudineclaudio answered 30/7, 2019 at 11:37 Comment(1)
I'm getting the same error, but my dump file is binary. Any clues there?Mancilla
E
0

Use this command, it will work perfectly to restore the db file using sql file in Postgres 13 in pgadmin 4

C:\Program Files\PostgreSQL\13\bin>psql -U user_name db_name< D:\dbfile\sql_file.sql
Encapsulate answered 6/10, 2021 at 13:34 Comment(1)
This will only work when backup is in plain text, and that's not OP case.Zymase

© 2022 - 2024 — McMap. All rights reserved.