PostgreSQL Tutorial

  • Home
  • Stored Procedures
  • Triggers
  • Views
  • Interfaces
    • PostgreSQL PHP
    • PostgreSQL Python
    • PostgreSQL JDBC
  • Functions
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 a 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

Managing Table Structure

  • 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

PostgreSQL Views

  • Managing PostgreSQL Views
  • Creating Updatable Views
  • PostgreSQL Materialized Views
  • The WITH CHECK OPTION Views
  • PostgreSQL Recursive View

PostgreSQL Triggers

  • Introduction to Trigger
  • Creating A Trigger
  • Managing PostgreSQL Triggers

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

  • How To Change The Password of a PostgreSQL User
  • PostgreSQL AGE Function
  • PostgreSQL DATE_PART Function
  • PostgreSQL List Users
  • PostgreSQL NOW Function
  • PostgreSQL DATE_TRUNC Function
  • PostgreSQL TO_DATE Function: Convert String to Date
  • A Look at PostgreSQL User-defined Data Types
  • PostgreSQL Copy Database Made Easy
  • How to Get Table, Database, Indexes, Tablespace, and Value Size in PostgreSQL

More Tutorials

  • PostgreSQL Cheat Sheet
  • PostgreSQL Administration
  • PostgreSQL PHP
  • PostgreSQL Python
  • PostgreSQL JDBC
  • PostgreSQL Resources

Site Info

  • Home
  • About Us
  • Contact Us
  • Privacy Policy

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