How to download and restore PostgreSQL sample database

In this article, we will see how to download and restore PostgreSQL sample database. We can restore sample database in PostgreSQL server using following methods.

1. Using psql tool on windows.
2. Using Terminal on Linux.

First we have to download PostgreSQL sample database. Go through Download PostgreSQL Sample database

Restore PostgreSQL sample database on windows by using psql utility

1. Open command prompt. Then provide password for username.

psq-l -U postgres

2. Create database dvdrental

create database dvdrental;

3. Now exit from PostgreSQL by typing \q

4. We have to navigate the bin folder of the PostgreSQL installation folder on Windows.

C:\Program Files\PostgreSQL\13\bin>

5. Use the pg_resote command to restore sample database dvdrental in PostgreSQL server as shown below.

pg_restore -U postgres -d dvdrental C:\Users\r2schools\Downloads\dvdrental\dvdrental.tar

Restore PostgreSQL sample database using Terminal on Linux

1. Download the PostgreSQL sample database using below command.

wget https://www.postgresql.r2schools.com/dvdrental

2. Create database using below command.

create database dvdrental;

3. Now, download the PostgreSQL sample database i.e. dvdrental.zip file.

wget https://www.postgresql.r2schools.com/dvdrental

4. Now, load the downloaded PostgreSQL sample database using below command.

pg_restore -U postgres -d dvdrental /home/r2schools/dvdrental.tar

So in this article, we have successfully downloaded PostgreSQL sample database and loaded it in Windows and Linux environments.