# Heroku

How to back up Heroku managed PostgreSQL databases via SimpleBackups.

Heroku Postgres is a managed PostgreSQL service available as an add-on to Heroku applications. Connecting it to SimpleBackups lets you store independent backup copies in your own storage with customizable retention schedules. This guide walks you through copying your connection URI and setting up the backup.

## Connecting your database

### Step 1: Copy your connection string

1. Log in to your Heroku console.
2. Navigate to the [Datastores list](https://data.heroku.com/).
3. Click on the database you want to back up.

![Heroku data stores list showing available databases](https://simplebackups.com/docs/docs-assets/media-helpkit-co/e26e83a9d78e23cba1bf.png)

4. Click the **Settings** tab, then click **View Credentials**.

![Heroku database settings tab with View Credentials button](https://simplebackups.com/docs/docs-assets/media-helpkit-co/44f6c17b7c5919167e9c.png)

5. Copy the **URI**.

![Heroku database credentials screen showing the URI field](https://simplebackups.com/docs/docs-assets/media-helpkit-co/e6b0e4fd91d4bf06d4a3.png)

### Step 2: Create a database backup in SimpleBackups

1. Navigate to **Backups** and click **Create Backup**, then select **Database Backup**.

![SimpleBackups create backup screen](https://simplebackups.com/docs/docs-assets/media-helpkit-co/07f1255c5414e1b7dd96.png)

2. Choose **Serverless** as the backup server type.
3. Select **PostgreSQL** as the database type.
4. Click **Paste connection string** and fill in the complete connection string for your Heroku Postgres database, making sure the password is included.

![SimpleBackups database connection form with PostgreSQL connection string](https://simplebackups.com/docs/docs-assets/media-helpkit-co/eeecd77c4ee90d66fd6e.png)

5. Click **Validate Connection**.
6. Set a schedule and configure retention policies and storage.

![SimpleBackups backup schedule configuration screen](https://simplebackups.com/docs/docs-assets/media-helpkit-co/05ace01b84c8eca8baaf.png)

7. Review your configuration and save. SimpleBackups will start backing up your database according to your schedule.

## Restoring a backup

To restore a backup, navigate to your backup page and open the **Logs** tab. Click the detail icon on the backup you want to restore from, then open the **Restore** tab. Generate a download link and copy it.

![Heroku backup logs tab](https://simplebackups.com/docs/docs-assets/media-helpkit-co/2f3640525c709c04f225.png)

![Heroku backup detail view](https://simplebackups.com/docs/docs-assets/media-helpkit-co/55b7832022cc9c1bc92a.png)

![Heroku restore tab with download link](https://simplebackups.com/docs/docs-assets/media-helpkit-co/e2d434aca694f92ed612.png)

Run the following command to download and decompress your backup (replace the URL with your signed download link):

```bash
wget -O - "<signed-download-url>" | gunzip -c > backup.pgsql
```

Then restore using `pg_restore`, replacing `<your-database-uri>` with your full database connection string:

```bash
pg_restore -d "<your-database-uri>" ./backup.pgsql
```

**Tip:**
Use the latest version of `pg_restore` to avoid compatibility issues during restore.
