Reputation: 51
I want to Download DVD Rental Sample Database from http://www.postgresqltutorial.com/postgresql-sample-database/ The database file is in zipformat ( dvdrental.zip) so I need to extract it to dvdrental.tar I have no .tar program in my computer. How can I extract the zip file to dvdrental.tar ?
Upvotes: 4
Views: 9112
Reputation: 1570
For future readers who want to practice with docker psql, here's how I did it.
For overall guide to make psql container, see postgresql docker hub.
Source of sample database: Postgresql tutorial page.
$ docker create volume dvdrental
$ docker run --name dvdrental -e POSTGRES_PASSWORD=postgres --restart=always -v dvdrental:/var/lib/postgresql/data/ -p 5433:5432 -d postgres:13
I intentionally binded external port(5433) to internal port(5432), since I'm already using another database instance with 5432 port. If you don't have any postgresql db instance, feel free to change external one to 5432
.
dvdrental.tar
inside the running container$ docker cp ~/Downloads/dvdrental.tar dvdrental:/dvdrental.tar
Syntax for copy is docker cp <file_name> <container_name>:/<file_name>
. Same is true with directory.
I thank Mosd for dropping hints on generating tar file from zip extension.
$ docker exec -it dvdrental psql -U postgres
psql (13.3 (Debian 13.3-1.pgdg100+1))
Type "help" for help.
postgres=# CREATE DATABASE dvdrental;
CREATE DATABASE
postgres=# exit
I got hint from Postgresql tutorial for creating database in this process.
$ docker exec -it dvdrental pg_restore -U postgres -d dvdrental /dvdrental.tar
Your dvdrental database is now populated.
You can make connection with tools such as dbeaver with
Remember that your external port is 5433, as you have set above.
Upvotes: 0
Reputation: 1682
Another option:
Download the dvdrental.zip to a directory
from terminal go that directory
then type:
unzip dvdrental.zip
dvdrental.tar should now appear.
Upvotes: 2
Reputation: 531
If you are trying to restore the dvdrental database use psql. After unarchive the zip file run the below command. Example if you have unarchived to ./downloads folder then
psql -h localhost -U postgres < ./Downloads/dvdrental/restore.sql
Upvotes: 1
Reputation: 336
So, I came across the same problem. The way i fixed it was to download:
pg_restore -U postgres -d dvdrental /Users/username/Downloads/dvdrental.tar
username
to your username. you might have to change the path depending on where your now .tar file is. Upvotes: 8
Reputation: 6010
If you use the default Mac unzip program. The dvdrental.tar
file will disappear after the unzip finish. Try another unzip app, such as "The Unarchiver". It will leave the dvdrental.tar
file in your folder.
Upvotes: 5