PostgreSQL Tutorial

  • Home
  • Stored Procedures
  • Advanced
    • Indexes
    • Views
    • Triggers
    • Administration
  • Interfaces
    • PostgreSQL PHP
    • PostgreSQL Python
    • PostgreSQL JDBC
  • Functions
    • Aggregate Functions
    • Date / Time Functions
    • String Functions
    • Math Functions
    • Window 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 on 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 the account’s information to log in to the PostgreSQL database server. You can use the default value provided by psql by pressing Enter keyboard. However, for the password, you need to enter the one that you provided during PostgreSQL installation.

1
2
3
4
5
Server [localhost]:
Database [postgres]:
Port [5432]:
Username [postgres]:
Password for user postgres:

Third, enter the following CREATE DATABASE statement to create a new dvdrental database.

1
CREATE DATABASE dvdrental;

PostgreSQL will create a new database named dvdrental.

Load the DVD rental database using psql tool

First, unzip and copy the DVD rental database file to a folder e.g., c:\dvdrental\dvdrental.tar

Next, launch the Command Prompt program by using the keyboard shortcut Windows + R, type cmd, and press Enter:

The Command prompt will look like this:

Then, navigate the bin folder of the PostgreSQL installation folder:

1
C:\>cd C:\Program Files\PostgreSQL\11\bin

After that, use the pg_restore tool to load data into the dvdrental database:

PostgreSQL Load Sample Database

1
pg_restore -U postgres -d dvdrental C:\dvdrental\dvdrental.tar

In this command:

  • The -U postgres specifies the postgresuser to login to the PostgreSQL database server.
  • The -d dvdrental specifies the target database to load.

Finally, enter the password for the postgres user and press enter

1
Password:

It takes seconds to load data stored in the dvdrental.tar file into the dvdrentaldatabase.

Load the DVD Rental database using the pgAdmin

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 and connect to the PostgreSQL server.

Next, right-click on the dvdrental database and choose Restore… menu item as shown in the following picture:

PostgreSQL Load Sample Database - pgAdmin

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

After that, wait for a few seconds to let the restoration process completes.

Finally, open the dvdrental database from object browser panel, you will see the tables in the public schema and other database objects as shown in the following picture:

PostgreSQL Load Sample Database - pgAdmin step 3

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!

  • Was this tutorial helpful ?
  • YesNo
Previous Tutorial: PostgreSQL Sample Database
Next Tutorial: PostgreSQL Server and Database Objects

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

  • SELECT
  • ORDER BY
  • SELECT DISTINCT
  • WHERE
  • LIMIT
  • FETCH
  • IN
  • BETWEEN
  • LIKE
  • IS NULL
  • ALIAS
  • Joins
  • INNER JOIN
  • LEFT JOIN
  • SELF-JOIN
  • FULL OUTER JOIN
  • Cross Join
  • Natural Join
  • GROUP BY
  • HAVING
  • UNION
  • INTERSECT
  • EXCEPT
  • GROUPING SETS
  • CUBE
  • ROLLUP
  • Subquery
  • ANY
  • ALL
  • EXISTS
  • INSERT
  • UPDATE
  • UPDATE Join
  • Upsert
  • DELETE

Managing Databases

  • Create Database
  • Alter Database
  • Rename Database
  • Drop Database
  • Copy a Database
  • Get Database Object Sizes

Managing Tables

  • PostgreSQL Data Types
  • Create Table
  • Select Into
  • Create Table As
  • SERIAL
  • Sequences
  • Identity Column
  • Alter Table
  • Rename Table
  • Add Column
  • Drop Column
  • Change Column’s Data Type
  • Rename Column
  • Drop Table
  • Temporary Table
  • Truncate Table

Database Constraints

  • Primary Key
  • Foreign Key
  • CHECK Constraint
  • UNIQUE Constraint
  • NOT NULL Constraint

PostgreSQL Data Types

  • Boolean
  • CHAR, VARCHAR, and TEXT
  • NUMERIC
  • Integer
  • SERIAL
  • DATE
  • TIMESTAMP
  • Interval
  • TIME
  • UUID
  • JSON
  • HSTORE
  • Array
  • User-defined Data Types

Managing Database Schemas

  • Schema
  • Create Schema
  • Alter Schema
  • Drop Schema

Conditional Expressions & Operators

  • CASE
  • COALESCE
  • NULLIF
  • CAST

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 DROP TRIGGER
  • PostgreSQL NTILE Function
  • PostgreSQL PERCENT_RANK Function
  • PostgreSQL CUME_DIST Function
  • PostgreSQL Sequences
  • PostgreSQL LAG Function
  • PostgreSQL LEAD Function
  • PostgreSQL NTH_VALUE Function
  • PostgreSQL LAST_VALUE Function
  • PostgreSQL FIRST_VALUE Function

Site Info

  • Home
  • PostgreSQL Cheat Sheet
  • Resources
  • About Us
  • Contact Us
  • Privacy Policy

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

⤒