sara
sara

Reputation: 51

How to extract zip file to tar in postgresql

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

Answers (5)

harryghgim
harryghgim

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.

  1. create docker volume
$ docker create volume dvdrental
  1. run docker container
$ 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.

  1. copy 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.

  1. Create database
$ 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.

  1. pg_restore to populate data
$ 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

  • database name: dvdrental
  • user: postgres
  • password: postgres
  • port: 5433

Remember that your external port is 5433, as you have set above.

Upvotes: 0

Mosd
Mosd

Reputation: 1682

Another option:

  1. Download the dvdrental.zip to a directory

  2. from terminal go that directory

  3. then type:

    unzip dvdrental.zip

dvdrental.tar should now appear.

Upvotes: 2

dotNet Decoder
dotNet Decoder

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

JCastillo
JCastillo

Reputation: 336

So, I came across the same problem. The way i fixed it was to download:

  1. "The Unarchiver"
  2. Go to downloads and select your .zip file, open with: "the unachiver.app" (you should now see a .tar file)
  3. Go to your terminal and run this command: pg_restore -U postgres -d dvdrental /Users/username/Downloads/dvdrental.tar
  4. Change username to your username. you might have to change the path depending on where your now .tar file is.
  5. You should now see all the tables

Upvotes: 8

PJCHENder
PJCHENder

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

Related Questions