Simple Backup / Restore DataBase in postgresql

TO make a database backup in postgreslq server you use pg_dump and psql commands.

First, locate the database:

# psql -l --username postgres --password


# pg_dump --username postgres name_db --file /dir/dir/backup.sql

To restore the database:

First create database with its respective name and roles:

# psql postgres
# postgres=# CREATE DATABASE name_db ENCODING 'UTF-8';
# postgres=# CREATE ROLE root LOGIN;


# psql name_db < /dir/dir/backup.sql

That’s all.


One thought on “Simple Backup / Restore DataBase in postgresql”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s