DEV Community

Hamza Mushtaque
Hamza Mushtaque

Posted on

PostgreSQL Basics: How to load PostgreSQL database

In this blog we will be learning how to load any PostgreSQL database
into PostgreSQL database server.

We will be keeping our blogs short and easy to read for making them simple. Hence, we will be targeting one thing at a time in our blog series.

I am assuming, you have PostgreSQL installed on your system.

First, we will launch our psql tool, using following command

>psql
Enter fullscreen mode Exit fullscreen mode

After that, Enter required credentials.

Server [localhost]:
Database [postgres]:
Port [5432]:
Username [postgres]:
Password for user postgres:
Enter fullscreen mode Exit fullscreen mode

then create data base using following statement

postgres=# CREATE DATABASE database_name;
CREATE DATABASE
Enter fullscreen mode Exit fullscreen mode

then exit psql tool by typing exit.

then, navigate to bin folder of your Postgres installation.

after that write following command to load your data into the data you created(assuming we created database named database_name).

pg_restore -U postgres -d database_name C:\sampledb\database_file.tar
Enter fullscreen mode Exit fullscreen mode

here -U postgres identifies postgres user, it would be different if you are using different user.

now, enter password for your user.

Password:
Enter fullscreen mode Exit fullscreen mode

Hurray!!!
We are done!!

Top comments (0)