Reputation: 1750
I'm working through the Postgres DVD tutorial and am running into issues importing their sample database.
Running pg_restore -U postgres -d dvdrental ~[filepath]/dvd-database.tar.gz
gives me pg_restore: [archiver] input file does not appear to be a valid archive
.
My process so far has been the following:
tar czf dvd-database.tar.gz dvdrental.zip
(I've also tried extracting the zip to a folder first with the same result, as well as dropping the .gz)pg_restore -U postgres -d dvdrental ~[filepath]/dvd-database.tar
as stated above.I'm currently using Postgres 9.5, which may be causing the issue. Looking for an answer that points out where I'm going wrong in this process or how to update an archive of a Postgres database to 9.5.
Upvotes: 23
Views: 72801
Reputation: 1
I got the same error below:
pg_restore: error: input file does not appear to be a valid archive
Because I exported but did not archive apple
database to backup.sql
with pg_dump as shown below:
pg_dump -U john apple > backup.sql
Or:
pg_dump -U john -Fp apple > backup.sql
Then, I tried to import non-archive backup.sql
to orange
database with pg_restore which must be used to import archive files:
pg_restore -U john -d orange < backup.sql
So, I did it with psql which must be used to import non-archive files, then I could solve the error. *My answer explains how to export a database and my answer explains how to import a database:
psql -U john -f backup.sql orange
Upvotes: 0
Reputation: 163
Don't know the reason but this is how it worked for me.
Im using ubuntu 20.04, pgadmin4 version 5.7, postgres version 12.8.
In the "restore" dialog box, "custome and tar", "..." in filename, click upload to upload the tar file, select the uploaded file, then selected the three options: pre-data, data and post-data. Was getting error: failed with exit code 1.
Deleted the database, again created the database (with the same name), did exactly the same way as before.
This 2nd time it succeeded. In the logs it executed the following cmd:
/usr/bin/pg_restore --host "localhost" --port "5432" --username "postgres" --no-password --dbname "mydb"
--section=pre-data --section=data --section=post-data --verbose "/var/lib/pgadmin/storage/my_email.com/restore_file.tar"
Upvotes: 0
Reputation: 2238
If you are running your postgres on Docker
then make sure to pass hostname and port,
pg_restore -U postgres -h localhost -p 5432 -d dvdrental ./Downloads/dvdrental
Here, ./Downloads/dvdrental
is extracted folder from dvdrental.zip
Upvotes: 0
Reputation: 1
It will be easier to use pgAdmin 4.
While restoring the tar file onto the database through pgAdmin you will get this error thrown at you. We usually get stuck at this point and forget to check the schema.
Ignore the error. The data has already been loaded and restored.
Upvotes: -2
Reputation: 141
My problem was that when installing postgresql, I chose a different name for the superuser (root
for example, not postgres
). And the dvdrental/restore.sql
file uses the postgres
role.
So to solve this problem you need to create another superuser named postgres
.
createuser --superuser postgres
Then create server (PosgreSQL) with role postgres
and db dvdrental
with role postgres
.
After u can succesfuly restore db from extracted folder
Upvotes: 3
Reputation: 1750
Per comments above, the solution was simple.
Extracting the dvdrental.zip file to an uncompressed .tar is not necessary as suggested in the tutorial instructions. pg_restore
will work if pointed to the directory where the database dump was extracted:
pg_restore -U <username> -d dvdrental <your/path/to/extracted/dir>/dvdrental
Upvotes: 30
Reputation: 6529
After trying for hours which worked for me is the below command. Since PgAdmin 4 it's very hard to work with.
/Library/PostgreSQL/10/bin/pg_restore -U postgres -p 5433 -d dvdrental /pg-db/dvdrental/
Just extract the zip into a folder and execute the pg_restore
command with these options in my case Mac os where /pg-db/dvdrental/
is the zip extracted directory.
Upvotes: 0