How to backup/restore Rails db with PostgreSQL?

You have multiple ways to backup/restore Rails database with Postgres:

In simple use the following commands to backup and restore the database for PostgreSQL:

pg_dump c -v -U postgres -h localhost -f .psql -W

Here -W is used to force to ask password.

For restore use the following command:

pg_restore -c -C -U postgres -h localhost .psql -W

Here -C -c will drop the database if it exists already and then recreate it new.

Leave a Reply