Database backup/restore in Postgres

To take Postgres database backup you can use below command.

Backup:  $ pg_dump -U {user-name} {source_db} -f {dumpfilename.sql}

For restore procedure use below:

Restore: $ psql -U {user-name} -d {desintation_db}-f {dumpfilename.sql}

To backup all databases use below command:

pg_dumpall > all.sql

To backup a specific postgres table
$ pg_dump --table tablename -U username databasename -f tablebackupfule.sql


To restore postgres database use below command

$ psql -U username -d databasename -f mydb.sql

To restore all databases

psql -f alldb.sql

To restore specific table:

psql -f tablebackupfile.sql databasename

Thanks

No comments:

Post a Comment