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: actor – stores actors data including first name and last name. film – stores films data such as title, release year, length, rating, etc film_actor – stores the relationships between films and actors. category – stores film’s categories data. film_category- stores the relationships between films and categories. store – contains the store data including manager staff and address. inventory – stores inventory data. rental – stores rental data. payment – stores customer’s payments. staff – stores staff data. customer – stores customers data. address – stores address data for staff and customers city – stores the city names. 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 Comment R rajukumar19 Follow 18 Improve R rajukumar19 Follow 18 Improve Article Tags : PostgreSQL postgreSQL-administration postgreSQL-managing-database Explore BasicsWhat is PostgreSQL - Introduction2 min readInstall PostgreSQL on Windows2 min readInstall PostgreSQL on Mac3 min readDatabase OperationsPostgreSQL - Create Database5 min readPostgreSQL - Loading a Database3 min readPostgreSQL ALTER DATABASE3 min readPostgreSQL - Rename Database4 min readPostgreSQL - Show Databases3 min readData TypesPostgreSQL - Data Types5 min readPostgreSQL - Boolean Data Type4 min readPostgreSQL - CHAR Data Type5 min readPostgreSQL - VARCHAR Data Type3 min readPostgreSQL - NUMERIC Data Type5 min readPostgreSQL - Date Data Type4 min readPostgreSQL - TIME Data Type4 min readPostgreSQL - JSON Data Type4 min readPostgreSQL - CREATE DOMAIN3 min readQuerying TablesPostgreSQL - SELECT3 min readPostgreSQL - ORDER BY clause2 min readPostgreSQL - WHERE clause6 min readPostgreSQL FETCH Clause4 min readPostgreSQL - IN operator4 min readPostgreSQL - HAVING clause4 min readPostgreSQL - GROUP BY clause4 min readPostgreSQL - LIKE operator5 min readPostgreSQL - BETWEEN Operator3 min readTable OperationsPostgreSQL - CREATE TABLE5 min readPostgreSQL - SELECT INTO4 min readPostgreSQL - CREATE SEQUENCE4 min readPostgreSQL - ALTER TABLE6 min readPostgreSQL - ADD COLUMN4 min readPostgreSQL - DROP COLUMN2 min readPostgreSQL - Rename Table2 min readPostgreSQL - DROP TABLE5 min readPostgreSQL - TRUNCATE TABLE4 min readPostgreSQL - Copy a Table3 min readPostgreSQL - Comparing Tables3 min readPostgreSQL - Show Tables4 min readModifying DataPostgreSQL - INSERT4 min readPostgreSQL - Insert Multiple Values in Various Rows3 min readPostgreSQL UPDATE Statement5 min readPostgreSQL - DELETE4 min readPostgreSQL - Upsert4 min readConditionalsPostgreSQL - CASE3 min readPostgreSQL COALESCE5 min readPostgreSQL - NULLIF() Function4 min readPostgreSQL - CAST3 min readControl FlowPostgreSQL - IF Statement5 min readPostgreSQL - CASE Statement4 min readPostgreSQL - Loop Statement3 min readPostgreSQL - While Loops4 min readPostgreSQL - Exit Statement3 min readPostgreSQL - Continue3 min readTransactions & ConstraintsPostgreSQL - Transactions4 min readPostgreSQL - COMMIT4 min readPostgreSQL - Primary Key4 min readPostgreSQL - Foreign Key5 min readPostgreSQL - CHECK Constraint2 min readPostgreSQL - UNIQUE Constraint3 min readPostgreSQL - NOT NULL Constraint3 min readJOINS & SchemasPostgreSQL - Joins5 min readPostgreSQL - LEFT JOIN5 min readPostgreSQL - INNER JOIN2 min readPostgreSQL - FULL OUTER JOIN4 min readPostgreSQL - SELF JOIN4 min readPostgreSQL - Schema5 min readPostgreSQL - CREATE SCHEMA5 min readPostgreSQL - DROP SCHEMA4 min readPostgreSQL - ALTER SCHEMA3 min read Like