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

Then:

# 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;

Restoring:

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

That’s all.

Advertisements

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

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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