Skip to content
    geeksforgeeks
    • Interview Prep
      • DSA
      • Interview Corner
      • Aptitude & Reasoning
      • Practice Coding Problems
      • All Courses
    • Tutorials
      • Python
      • Java
      • ML & Data Science
      • Programming Languages
      • Web Development
      • CS Subjects
      • DevOps
      • Software and Tools
      • School Learning
    • Tracks
      • Languages
        • Python
        • C
        • C++
        • Java
        • Advanced Java
        • SQL
        • JavaScript
        • C#
      • Interview Preparation
        • GfG 160
        • GfG 360
        • System Design
        • Core Subjects
        • Interview Questions
        • Interview Puzzles
        • Aptitude and Reasoning
        • Product Management
        • Computer Organisation and Architecture
      • Data Science
        • Python
        • Data Analytics
        • Complete Data Science
        • Gen AI
        • Agentic AI
      • Dev Skills
        • Full-Stack Web Dev
        • DevOps
        • Software Testing
        • CyberSecurity
        • NextJS
        • Git
      • Tools
        • Computer Fundamentals
        • AI Tools
        • MS Excel & Google Sheets
        • MS Word & Google Docs
      • Maths
        • Maths For Computer Science
        • Engineering Mathematics
        • School Maths
    • DSA
    • Practice Problems
    • C
    • C++
    • Java
    • Python
    • JavaScript
    • Data Science
    • Machine Learning
    • Courses
    • Linux
    • DevOps
    • SQL
    • Web Development
    • System Design
    • Aptitude
    Open In App

    PostgreSQL - Loading a Database

    Last Updated : 20 Sep, 2021
    Comments
    Improve
    Suggest changes
    18 Likes
    Like
    Report
    See More

    In this article we will look into the process of loading a PostgreSQL database into the PostgreSQL database server. 
    Before moving forward we just need to make sure of two things: 

    • PostgreSQL database server is installed on your system. 
    • A sample database. 

    For the purpose of this article, we will be using a sample database which is DVD rental database. 
    You can download the sample dvdrental database from here.  

    The Sample Database:

    So, the DVD rental database that we will be using ahead in the article represents a DVD rental store. The objects in the database includes: 

    • 15 tables 
    • 1 trigger 
    • 8 functions 
    • 1 domain 
    • 7 views 
    • 13 sequences 

    ER Model of the sample Database:  

    Tables in the Sample Database: 
    There are 15 tables in our sample database which are listed below: 

    1. actor – stores actors data including first name and last name. 
    2. film – stores films data such as title, release year, length, rating, etc 
    3. film_actor – stores the relationships between films and actors. 
    4. category – stores film’s categories data. 
    5. film_category- stores the relationships between films and categories. 
    6. store – contains the store data including manager staff and address. 
    7. inventory – stores inventory data. 
    8. rental – stores rental data. 
    9. payment – stores customer’s payments. 
    10. staff – stores staff data. 
    11. customer – stores customers data. 
    12. address – stores address data for staff and customers 
    13. city – stores the city names. 
    14. country – stores the country names. 

    So now we know everything about our sample DVD rental database, let us move on to loading the same database to the PostgreSQL database server. The steps to which are listed below:  

    • Step 1: Create a DVD rental Database, by opening the SQL shell. Once you open up the shell, you will need to add the necessary credentials for your database, which would somewhat look like below: 
    Server [localhost]:
    Database [postgres]:
    Port [5432]:
    Username [postgres]:
    Password for user postgres:

    Now using the CREATE DATABASE statement create a new database as follows: 

    CREATE DATABASE dvdrental;
    • Step 2: Load the database file by creating a folder at your desired location(say, c:\users\sample_database\dvdrental.tar). Now open up command prompt and Navigate to the bin folder of the PostgreSQL installation folder as below: 

    Use the pg_restore tool to load data into the dvdrental database that we had just created as using the command: 

    pg_restore -U postgres -d dvdrental C:\users\sample_datbase\dvdrental.tar

    It would somewhat look like below: 

    Now enter your database user Password and your sample database will be loaded.  

    Verify Database Load:

    Now if you need to verify if the sample database is loaded, use the below command to get into the database in SQL shell:  

    \c

    Now to list all the tables in the database, use the below command: 

    \dt

    The result should look like below:  


     

    Create Quiz

    R

    rajukumar19
    Improve

    R

    rajukumar19
    Improve
    Article Tags :
    • PostgreSQL
    • postgreSQL-administration
    • postgreSQL-managing-database

    Explore

      Basics

      What is PostgreSQL - Introduction

      2 min read

      Install PostgreSQL on Windows

      2 min read

      Install PostgreSQL on Mac

      3 min read

      Database Operations

      PostgreSQL - Create Database

      5 min read

      PostgreSQL - Loading a Database

      3 min read

      PostgreSQL ALTER DATABASE

      3 min read

      PostgreSQL - Rename Database

      4 min read

      PostgreSQL - Show Databases

      3 min read

      Data Types

      PostgreSQL - Data Types

      5 min read

      PostgreSQL - Boolean Data Type

      4 min read

      PostgreSQL - CHAR Data Type

      5 min read

      PostgreSQL - VARCHAR Data Type

      3 min read

      PostgreSQL - NUMERIC Data Type

      5 min read

      PostgreSQL - Date Data Type

      4 min read

      PostgreSQL - TIME Data Type

      4 min read

      PostgreSQL - JSON Data Type

      4 min read

      PostgreSQL - CREATE DOMAIN

      3 min read

      Querying Tables

      PostgreSQL - SELECT

      3 min read

      PostgreSQL - ORDER BY clause

      2 min read

      PostgreSQL - WHERE clause

      6 min read

      PostgreSQL FETCH Clause

      4 min read

      PostgreSQL - IN operator

      4 min read

      PostgreSQL - HAVING clause

      4 min read

      PostgreSQL - GROUP BY clause

      4 min read

      PostgreSQL - LIKE operator

      5 min read

      PostgreSQL - BETWEEN Operator

      3 min read

      Table Operations

      PostgreSQL - CREATE TABLE

      5 min read

      PostgreSQL - SELECT INTO

      4 min read

      PostgreSQL - CREATE SEQUENCE

      4 min read

      PostgreSQL - ALTER TABLE

      6 min read

      PostgreSQL - ADD COLUMN

      4 min read

      PostgreSQL - DROP COLUMN

      2 min read

      PostgreSQL - Rename Table

      2 min read

      PostgreSQL - DROP TABLE

      5 min read

      PostgreSQL - TRUNCATE TABLE

      4 min read

      PostgreSQL - Copy a Table

      3 min read

      PostgreSQL - Comparing Tables

      3 min read

      PostgreSQL - Show Tables

      4 min read

      Modifying Data

      PostgreSQL - INSERT

      4 min read

      PostgreSQL - Insert Multiple Values in Various Rows

      3 min read

      PostgreSQL UPDATE Statement

      5 min read

      PostgreSQL - DELETE

      4 min read

      PostgreSQL - Upsert

      4 min read

      Conditionals

      PostgreSQL - CASE

      3 min read

      PostgreSQL COALESCE

      5 min read

      PostgreSQL - NULLIF() Function

      4 min read

      PostgreSQL - CAST

      3 min read

      Control Flow

      PostgreSQL - IF Statement

      5 min read

      PostgreSQL - CASE Statement

      4 min read

      PostgreSQL - Loop Statement

      3 min read

      PostgreSQL - While Loops

      4 min read

      PostgreSQL - Exit Statement

      3 min read

      PostgreSQL - Continue

      3 min read

      Transactions & Constraints

      PostgreSQL - Transactions

      4 min read

      PostgreSQL - COMMIT

      4 min read

      PostgreSQL - Primary Key

      4 min read

      PostgreSQL - Foreign Key

      5 min read

      PostgreSQL - CHECK Constraint

      2 min read

      PostgreSQL - UNIQUE Constraint

      3 min read

      PostgreSQL - NOT NULL Constraint

      3 min read

      JOINS & Schemas

      PostgreSQL - Joins

      5 min read

      PostgreSQL - LEFT JOIN

      5 min read

      PostgreSQL - INNER JOIN

      2 min read

      PostgreSQL - FULL OUTER JOIN

      4 min read

      PostgreSQL - SELF JOIN

      4 min read

      PostgreSQL - Schema

      5 min read

      PostgreSQL - CREATE SCHEMA

      5 min read

      PostgreSQL - DROP SCHEMA

      4 min read

      PostgreSQL - ALTER SCHEMA

      3 min read
    top_of_element && top_of_screen < bottom_of_element) || (bottom_of_screen > articleRecommendedTop && top_of_screen < articleRecommendedBottom) || (top_of_screen > articleRecommendedBottom)) { if (!isfollowingApiCall) { isfollowingApiCall = true; setTimeout(function(){ if (loginData && loginData.isLoggedIn) { if (loginData.userName !== $('#followAuthor').val()) { is_following(); } else { $('.profileCard-profile-picture').css('background-color', '#E7E7E7'); } } else { $('.follow-btn').removeClass('hideIt'); } }, 3000); } } }); } $(".accordion-header").click(function() { var arrowIcon = $(this).find('.bottom-arrow-icon'); arrowIcon.toggleClass('rotate180'); }); }); window.isReportArticle = false; function report_article(){ if (!loginData || !loginData.isLoggedIn) { const loginModalButton = $('.login-modal-btn') if (loginModalButton.length) { loginModalButton.click(); } return; } if(!window.isReportArticle){ //to add loader $('.report-loader').addClass('spinner'); jQuery('#report_modal_content').load(gfgSiteUrl+'wp-content/themes/iconic-one/report-modal.php', { PRACTICE_API_URL: practiceAPIURL, PRACTICE_URL:practiceURL },function(responseTxt, statusTxt, xhr){ if(statusTxt == "error"){ alert("Error: " + xhr.status + ": " + xhr.statusText); } }); }else{ window.scrollTo({ top: 0, behavior: 'smooth' }); $("#report_modal_content").show(); } } function closeShareModal() { const shareOption = document.querySelector('[data-gfg-action="share-article"]'); shareOption.classList.remove("hover_share_menu"); let shareModal = document.querySelector(".hover__share-modal-container"); shareModal && shareModal.remove(); } function openShareModal() { closeShareModal(); // Remove existing modal if any let shareModal = document.querySelector(".three_dot_dropdown_share"); shareModal.appendChild(Object.assign(document.createElement("div"), { className: "hover__share-modal-container" })); document.querySelector(".hover__share-modal-container").append( Object.assign(document.createElement('div'), { className: "share__modal" }), ); document.querySelector(".share__modal").append(Object.assign(document.createElement('h1'), { className: "share__modal-heading" }, { textContent: "Share to" })); const socialOptions = ["LinkedIn", "WhatsApp","Twitter", "Copy Link"]; socialOptions.forEach((socialOption) => { const socialContainer = Object.assign(document.createElement('div'), { className: "social__container" }); const icon = Object.assign(document.createElement("div"), { className: `share__icon share__${socialOption.split(" ").join("")}-icon` }); const socialText = Object.assign(document.createElement("span"), { className: "share__option-text" }, { textContent: `${socialOption}` }); const shareLink = (socialOption === "Copy Link") ? Object.assign(document.createElement('div'), { role: "button", className: "link-container CopyLink" }) : Object.assign(document.createElement('a'), { className: "link-container" }); if (socialOption === "LinkedIn") { shareLink.setAttribute('href', `https://www.linkedin.com/sharing/share-offsite/?url=${window.location.href}`); shareLink.setAttribute('target', '_blank'); } if (socialOption === "WhatsApp") { shareLink.setAttribute('href', `https://api.whatsapp.com/send?text=${window.location.href}`); shareLink.setAttribute('target', "_blank"); } if (socialOption === "Twitter") { shareLink.setAttribute('href', `https://twitter.com/intent/tweet?url=${window.location.href}`); shareLink.setAttribute('target', "_blank"); } shareLink.append(icon, socialText); socialContainer.append(shareLink); document.querySelector(".share__modal").appendChild(socialContainer); //adding copy url functionality if(socialOption === "Copy Link") { shareLink.addEventListener("click", function() { var tempInput = document.createElement("input"); tempInput.value = window.location.href; document.body.appendChild(tempInput); tempInput.select(); tempInput.setSelectionRange(0, 99999); // For mobile devices document.execCommand('copy'); document.body.removeChild(tempInput); this.querySelector(".share__option-text").textContent = "Copied" }) } }); // document.querySelector(".hover__share-modal-container").addEventListener("mouseover", () => document.querySelector('[data-gfg-action="share-article"]').classList.add("hover_share_menu")); } function toggleLikeElementVisibility(selector, show) { document.querySelector(`.${selector}`).style.display = show ? "block" : "none"; } function closeKebabMenu(){ document.getElementById("myDropdown").classList.toggle("show"); }
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Campus Training Program
  • Explore
  • POTD
  • Job-A-Thon
  • Blogs
  • Nation Skill Up
  • Tutorials
  • Programming Languages
  • DSA
  • Web Technology
  • AI, ML & Data Science
  • DevOps
  • CS Core Subjects
  • Interview Preparation
  • Software and Tools
  • Courses
  • ML and Data Science
  • DSA and Placements
  • Web Development
  • Programming Languages
  • DevOps & Cloud
  • GATE
  • Trending Technologies
  • Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
  • Preparation Corner
  • Interview Corner
  • Aptitude
  • Puzzles
  • GfG 160
  • System Design
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences