Backup and Restore Postgresql Database

create database:
[sourcecode language="bash"]
#create database from bash shell
su - postgres
bash-3.2$ createdb db_name;
bash-3.2$ dropdb db_name;
[/sourcecode]


Or you can go into database:
[sourcecode language="bash"]
#frm psql
#Connect as postgres to the postgres database
psql -d postgres postgres;
postgres=# create database new_db_name;
postgres=# drop database new_db_name;
[/sourcecode]


To backup a Postgresql Database:
[sourcecode language="bash"]
#bash shell
pg_dump -U db_user_name database_name -f backup_file_name.sql
[/sourcecode]


This command is to backup the database_name to file backup_file_name.sql.
To backup a specific schema of the database, use -n parameter
[sourcecode language="bash"]
#bash shell
pg_dump -U htang tripal_dev -n chado -f ~/DBBackups/tripal_dev__chado_only_20110901.sql
[/sourcecode]


To restore a backup from file use the follwing command:
[sourcecode language="bash"]
#bash shell
psql -f backup_file_path_and_name DATABASE_name;
#or you can
psql -d database_name < backup_file_path_and_name;
[/sourcecode]

No comments:

Post a Comment

Datatable static image not found on the server

When you use ```datatables.min.css``` and ```datatables.min.js``` locally, instead of datatables CDN, you may have encountered that ```sort...