Database Engineering
  • Need of Database
  • Database and Database Management System
  • What is Relational Database Model ?
  • Installing Postgresql
    • Installing PostgreSQL on Linux
    • Installing PostgreSQL on Windows
    • Installing PostgreSQL on Mac
    • Postgres in Docker
  • What happens during the initial installation ?
    • Roles, Users & Groups
    • More examples on Roles
  • Sample Databases
    • DVD Rental Database
  • Querying Data
    • SELECT Query
    • Column Aliases
    • Order By
    • SELECT DISTINCT
    • DB-TASK-001
  • Filtering Data
    • WHERE ?
    • AND Operator
    • OR Operator
    • LIMIT
    • FETCH
    • IN
    • BETWEEN
    • LIKE
    • SIMILAR TO
    • IS NULL
    • ESCAPE
    • DB-TASK-002
  • Entity Relationship Diagram
    • What is an ER Diagram ?
    • Entity
    • Identifiers
    • Relationship
    • Attributes
    • Cardinality
    • Entity Relationship Diagram Tutorial
    • DB-TASK-003
  • Joins
    • Joins
    • Joins With Employee and Departments
  • Joins on E-Commerce
Powered by GitBook
On this page
  • Source
  • Steps to import the database
  1. Sample Databases

DVD Rental Database

PreviousSample DatabasesNextSELECT Query

Last updated 6 months ago

Source

Steps to import the database

  1. Download the tar file from the given link.

  2. Create the dvdrental database. Login to the postgres db, with the user. (here for example we are using the postgres superuser.)

psql -U postgres

After entering the password correctly, you will be connected to the PostgreSQL server.

postgres=#

Second, create a new database called dvdrental using CREATE DABASE statement:

CREATE DATABASE dvdrental;

Output:

CREATE DATABASE

PostgreSQL will create a new database called dvdrental.

Third, verify the database creation using the \l command. The \l command will show all databases in the PostgreSQL server. The output shows that dvdrental on the list, meaning that you have created the dvdrental database successfully. Now disconnect from the PostgreSQL server and exit the psql using the exit command

  1. Load the dataset into the db using the pg_restore

pg_restore -U postgres -d dvdrental dvdrental.tar

n this command:

  • The -U postgres instructs pg_restore to connect the PostgreSQL server using the postgres user.

  • The -d dvdrental specifies the target database to load.

It might prompt you to enter the password for the postgres user. Enter the password for the postgres user and press the Enter (or Return key)

It’ll take about seconds to load data stored in the dvdrental.tar file into the dvdrental database.

  1. Verify the database is loaded.

Login to the postgres with database as dvdrental,

psql -U postgres -d dvdrental;

display all tables in the dvdrental database

\dt

Now you have the practice DB. Happy Learning !

https://github.com/syedjaferk/postgres_sample_database/blob/main/dvd_rental/dvdrental.tar