
- PostgreSQL - Home
- PostgreSQL - Overview
- PostgreSQL - Environment Setup
- PostgreSQL - Syntax
- PostgreSQL - Data Types
- PostgreSQL - Operators
- PostgreSQL - Expressions
- PostgreSQL Database
- PostgreSQL - Create Database
- PostgreSQL - ALTER DATABASE
- PostgreSQL - Drop Database
- PostgreSQL - Loading Database
- PostgreSQL - Rename Database
- PostgreSQL - Select Database
- PostgreSQL - Show Database
- PostgreSQL Query Operations
- PostgreSQL - SELECT
- PostgreSQL - CREATE
- PostgreSQL - INSERT
- PostgreSQL - UPDATE
- PostgreSQL - DELETE
- PostgreSQL - ALTER TABLE Command
- PostgreSQL - WHERE Clause
- PostgreSQL - ORDER BY Clause
- PostgreSQL - GROUP BY
- PostgreSQL - HAVING Clause
- PostgreSQL - DISTINCT Keyword
- PostgreSQL - LIMIT Clause
- PostgreSQL - LIKE Clause
- PostgreSQL - WITH Clause
- PostgreSQL - AND & OR Clauses
- PostgreSQL - DROP TABLE
- PostgreSQL - Upsert
- TRUNCATE TABLE Command
- PostgreSQL JOINS & Schemas
- PostgreSQL Schemas
- PostgreSQL Joins
- PostgreSQL Data Integrity & Transaction
- PostgreSQL - Constraints
- PostgreSQL - Transactions
- PostgreSQL - Commit
- PostgreSQL - Rollback
- PostgreSQL - Views
- PostgreSQL Functions
- PostgreSQL - ALIAS Syntax
- PostgreSQL - Functions
- PostgreSQL - Useful Function
- PostgreSQL - MAX() Function
- PostgreSQL - MIN() Function
- PostgreSQL - SUM() Function
- PostgreSQL - COUNT() Function
- PostgreSQL - Array Function
- PostgreSQL - String Function
- PostgreSQL - Numeric Function
- PostgreSQL Operators
- PostgreSQL - UNION Operator
- PostgreSQL - INTERSECT Operator
- PostgreSQL - EXCEPT Operator
- PostgreSQL - ANY Operator
- PostgreSQL - ALL Operator
- PostgreSQL - EXISTS Operator
- PostgreSQL Interface
- PostgreSQL - C / C++
- PostgreSQL - Java
- PostgreSQL - PHP
- PostgreSQL - Perl
- PostgreSQL - Python
- Advanced PostgreSQL
- PostgreSQL - NULL Values
- PostgreSQL - Triggers
- PostgreSQL - Indexes
- PostgreSQL - Locks
- PostgreSQL - Sub Queries
- PostgreSQL - Auto Increment
- PostgreSQL - Privileges
- PostgreSQL - Date/Time Functions & Operators
- PostgreSQL - Errors & Messages
- PostgreSQL - Assert
PostgreSQL - LOAD DATABASE
In PostgreSQL, loading a database is used to restore the data from the backup or external sources. In this tutorial, we will learn the different methods to load a database.
Different ways to load database in PostgreSQL
Following is the list of methods to load the database using different methods. −
Using restore
Suppose you have a backup in custom format like .dump or .backup, then use the pg_restore command.
Syntax
Following is the syntax of loading a database using the restore command −
pg_restore -U postgres -d target_database backup_file.dump
Here,
- -U postgres specifies the PostgreSQL user.
- -d target_database is the database where data will be restored.
- backup_file.dump is the backup file.
Using psql
To back up the database in plain SQL format, use the psql command to restore it.
psql -U postgres -d target_database -f backup_file.sql
Here,
- -f backup_file.sql specifies the SQL file to execute.
Importing Data from CSV files
If you want to load the database with external sources, use the COPY command.
COPY table_name FROM '/path/to/file.csv' DELIMITER ',' CSV HEADER;
Here,
- /path/to/file.csv − This is file location.
- DELIMITER ',' specifies that values are comma-separated.
- CSV HEADER indicates that the first row contains column names.
Using pgAdmin
pgAdmin is a free opens−source tool that helps users to manage PostgreSQL and other relational databases. Below are some steps that help you to load the database −
Step 1 : Open the pgAdmin and connect with PostgreSQL server.
Step 2 : Then select the target database.
Step 3 : Go to Tools −> restore.
Step 4 : Next, choose the file for backup and configure the restore setting.
Step 5 : Finally, click the restore to load the database.
Therefore, all of these methods are effective ways to load data into a database using PostgreSQL.