Summary: in this tutorial, we will show you how to load the PostgreSQL sample database into the PostgreSQL database server.
Before going forward with this tutorial, you must have:
- PostgreSQL database server installed in your system. If you don’t have, you can follow the step-by-step installing PostgreSQL tutorial.
- The DVD rental database available.
Creating a new DVD rental database
You need to create a new database in the PostgreSQL database server before loading database schema and data into the database.
First, launch the psql tool.
Second, enter account’s information to login to the PostgreSQL database server.
Third, enter the following statement to create a new dvdrental database.
1 | CREATE DATABASE dvdrental; |
PostgreSQL will create a new database named dvdrental
.
Load the DVD rental database
First, copy the DVD rental database file to a folder e.g., c:\temp\dvdrental.tar
Second, navigate the BIN folder of the PostgreSQL installation folder:
1 | C:\>cd C:\Program Files\PostgreSQL\9.5\bin |
Third, use the pg_restore tool to load data into the dvdrental database:
1 | >pg_restore -U postgres -d dvdrental C:\temp\dvdrental.tar |
-U postgres
specifies the postgres
user to login to the PostgreSQL database server. The data stored in the dvdrental.tar
will be loaded into the dvdrental
database.
Load the DVD Rental database using pgAdmin tool
You can use the pgAdmin tool to restore the sample database from the downloaded database file using the following steps:
First, launch the pgAdmin tool, connect to the PostgreSQL server.
Second, right mouse click on the Databases and click the new Database.. menu item to create a new database.
Third, enter the information for the database as shown in the following screenshot and click the OK button.
You’ve create the database whose name is dvdrental.
Fourth, right mouse click on the dvdrental and choose the Restore… menu item.
Fifth, provide the path to database file e.g., c:\temp\dvdrental.tar and click the Restore button
Finally, wait for few seconds and click the Done button when the pgAdmin completes restoring the database.
Verify the loaded sample database
Open the dvdrental
database from object browser panel, you will see the tables in the schema and other database objects as the following picture:
We have shown you how to load the dvdrental
sample database into the PostgreSQL database server for learning and practicing PostgreSQL.
Let’s start learning PostgreSQL and have fun!