Backup and Restore Postgresql Database

Part one:

create database:

$ su postgres

bash-3.2$ createdb db_name;

bash-3.2$ dropdb db_name;

Or you can go into database:

$ psql -d db_name;

db_name=# create database new_db_name;

db_name=# drop database new_db_name;



To backup a Postgresql Database:

$ pg_dump -U db_user_name database_name -f backup_file_name.sql

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

$ pg_dump -U htang tripal_dev -n chado -f ~/DBBackups/tripal_dev__chado_only_20110901.sql

To restore a backup file use the follwing command:

$ psql -f backup_file_path_and_name DATABASE_name;

  or you can

$ psql -d database_name < backup_file_path_and_name;

http://developer.postgresql.org/pgdocs/postgres/app-pgdump.html

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...