PostgreSQL Tutorial

  • Home
  • Administration
  • Views
  • Triggers
  • Stored Procedures
  • Interfaces
    • PostgreSQL PHP
    • PostgreSQL Python
    • PostgreSQL JDBC
Home / PostgreSQL Tutorial / Load PostgreSQL Sample Database

Load PostgreSQL Sample Database

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 postgresuser to login to the PostgreSQL database server. The data stored in the dvdrental.tar will be loaded into the dvdrentaldatabase.

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.

pgAdmin creating a new database dvdrental

Third, enter the information for the database as shown in the following screenshot and click the OK button.

pgAdmin dvdrental database info

You’ve create the database whose name is dvdrental.

Fourth, right mouse click on the dvdrental and choose the Restore… menu item.

pgAdmin Restore

Fifth, provide the path to database file e.g., c:\temp\dvdrental.tar and click the Restore button

pgAdmin db file for restoring

Finally, wait for few seconds and click the Done button when the pgAdmin completes restoring the database.

pgAdmin Restore result

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:

dvdrental database

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!

Previous Tutorial: PostgreSQL Sample Database
Next Tutorial: Connect to PostgreSQL Database

PostgreSQL Quick Start

  • What is PostgreSQL?
  • Install PostgreSQL
  • Connect to Database
  • Download PostgreSQL Sample Database
  • Load Sample Database
  • Explore Server and Database Objects

PostgreSQL Fundamentals

  • PostgreSQL Select
  • PostgreSQL Order By
  • PostgreSQL Select Distinct
  • PostgreSQL Where
  • PostgreSQL LIMIT
  • PostgreSQL IN
  • PostgreSQL Between
  • PostgreSQL Like
  • PostgreSQL Inner Join
  • PostgreSQL Left Join
  • PostgreSQL Full Outer Join
  • PostgreSQL Cross Join
  • PostgreSQL Natural Join
  • PostgreSQL Group By
  • PostgreSQL Having
  • PostgreSQL Union
  • PostgreSQL Intersect
  • PostgreSQL Except
  • PostgreSQL Subquery
  • PostgreSQL Insert
  • PostgreSQL Update
  • PostgreSQL Delete
  • PostgreSQL Data Types
  • PostgreSQL Create Table
  • PostgreSQL Alter Table
  • PostgreSQL Drop Table
  • PostgreSQL Truncate Table
  • PostgreSQL CHECK Constraint
  • PostgreSQL Not-Null Constraint
  • PostgreSQL Foreign Key
  • PostgreSQL Primary Key
  • PostgreSQL UNIQUE Constraint

About PostgreSQL Tutorial

PostgreSQLTutorial.com is a website dedicated to developers and database administrators who are working on PostgreSQL database management system.

We constantly publish useful PostgreSQL tutorials to keep you up-to-date with the latest PostgreSQL features and technologies. All PostgreSQL tutorials are simple, easy-to-follow and practical.

Recent PostgreSQL Tutorials

  • PostgreSQL Recursive View
  • Learn PostgreSQL Recursive Query By Example
  • Creating Updatable Views Using the WITH CHECK OPTION Clause
  • PostgreSQL Upsert Using INSERT ON CONFLICT statement
  • How to Generate a Random Number in A Range
  • Using PostgreSQL ADD COLUMN to Add One or More Columns To a Table
  • PostgreSQL Character Types: CHAR, VARCHAR, and TEXT
  • Using PostgreSQL SERIAL To Create Auto-increment Column
  • PostgreSQL Boolean Data Type with Practical Examples
  • Understanding PostgreSQL Timestamp Data Types

More Tutorials

  • PostgreSQL PHP
  • PostgreSQL Python
  • PostgreSQL JDBC
  • PostgreSQL Functions
  • PostgreSQL Resources

Site Info

  • Home
  • About Us
  • Contact Us
  • Privacy Policy

Copyright © 2016 by PostgreSQL Tutorial Website. All Rights Reserved.