Create and restore PostgreSQL backups


To back up only the database, create a dump file using the pg_dump tool.

$ pg_dump -U postgres DATABASE_NAME > backup.sql

This operation could take some time depending on the database size.



Once you have the backup file, you can restore it with a command like the one below:

$ psql -U postgres DATABASE_NAME < backup.sql

If you want to restore the database and the database schema does not exist, it is necessary to first follow the steps described below. As a side note, the value for the BITNAMI_USER_PASSWORD placeholder is included in the application credentials or, if the credentials were defined by the user, it is the same as the application password.

$ psql -U postgres
drop database DATABASE_NAME;
create database DATABASE_NAME;
create user USER_NAME;
alter role USER_NAME with password 'BITNAMI_USER_PASSWORD';
grant all privileges on database DATABASE_NAME to USER_NAME;
alter database DATABASE_NAME owner to USER_NAME;
$ psql -U postgres DATABASE_NAME < backup.sql
Last modification September 11, 2018