Published on

How to backup and restore Postgres database

Authors is a Serverless Postgres platform which takes care of all the things associated with maintaining the database.

You just need to create a new database and use it.

And you're billed for the usage. That's it.

You don't have to worry about provisioning it, scaling it, etc.

They also have a generous free plan.

Backing up and restoring the database might be a frequent action. Let's see how to do that with

Backup database using pg_dump

We'll be using pg_dump to perform a backup operation.

Make sure that you're using the same version of Postgres locally and also in platform

Get the connection string from your dashboard

pg_dump "postgresql://<username>:<password><database_name>?sslmode=require" -F c -b -v -f <backup_file_name>.dump

Restore database using pg_restore

We'll be using pg_restore which we'll be able to restore the database using the dump that we've created using pg_dump and it comes preinstalled when you install the Postgres server locally.

Just run the following command:

pg_restore -d "postgresql://<username>:<password><database_name>?sslmode=require" <backup_file_name>.dump

d or --dbname 👉 database name (and also connection string as well)

That's pretty much it.

Happy backing up!