Wednesday, November 30, 2016

How To Backup PostgreSQL Databases

Backups are an essential component in any kind of data storage plan. Fortunately, PostgreSQL gives you the utilities necessary to effectively backup your important information.

PostgreSQL includes a utility called "pg_dump" that can be used to dump a database into a file for backup purposes.

pg_dump 'database' > 'file_backup'

You can include user, host and port in the previous command if you need it:

pg_dump -U 'user_name' -h 'host' -p 'port' 'database' > 'file_backup'

To restore the backup created by pg_dump, you can redirect the file into psql standard input:

psql 'empty_database' < 'file_backup'

No comments:

Post a Comment