Last updated June 17, 2026
This article covers migrating to Essential and classic Postgres plans (Standard, Premium, Private, and Shield), and doesn’t apply to Heroku Postgres Advanced (Limited GA) databases.
In this guide, we walk you through the process of migrating your Postgres database from AWS RDS to Heroku Postgres with a dump and restore strategy. This guide uses Amazon S3 to store the database dump file. Before starting the migration, make sure you completed the steps from Preparing Your Migration to Heroku Postgres.
Check Your Database Size
To determine the size of your Postgres database, connect to your RDS instance and use the list databases \l+ command. Our example database is called app_prod_db. Connect to your RDS database and check its size:
$ psql=> \l+ app_prod_db
List of databases
Name | Owner | Encoding | Collate | Ctype | Size |
-------------+--------+----------+-------------+-------------+---------+
app_prod_db | myuser | UTF8 | en_US.UTF-8 | en_US.UTF-8 | 2219 MB |
(1 row)
Usually, the dump and restore strategy for migration is suitable if your database size is less than 100 GB.
From the AWS Console, you can also navigate to RDS, find the database instance you want to migrate, and click the Configuration tab.

In our example, the instance has 4 GB of storage, 2 vCPUs, and 1 GB of RAM. Next, click the Monitoring tab and locate the FreeStorageSpace metric.

The chart shows just over 1.6 GB of available storage space. Knowing that the instance has 4 GB allocated, we can determine that our database size is around 2.4 GB.
See Choosing the Right Heroku Postgres Plan for which Heroku Postgres plan fits your database size.
Create and Upload the Database Dump
Before starting, either set your system to read-only mode, or bring all your dependent services offline and notify end users of the current maintenance status.
If your database is attached to a Heroku app, put your app in maintenance mode and downscale any worker dynos that connect to the database.
Back Up Your Database
Before performing the migration, make sure you have a recent backup of your database. Back up your database at AWS RDS by taking a manual snapshot of your database instance, which you can restore if needed.

Dump the Database to a Local File
Using pg_dump, create a logical backup of your AWS RDS Postgres database to a local file:
$ pg_dump postgres://DB_USERNAME:DB_PASSWORD@DB_HOST:DB_PORT/DB_NAME \
-Fc -b -v \
-f /tmp/data-for-migration.sql
The time it takes to run this command varies depending on the size of your database.
Upload the File to S3
Heroku can restore Postgres logical backups that are accessible via a URL. For this migration from AWS, upload your database backup file to AWS S3, then obtain a signed URL for that file.
First, create an S3 bucket. In our example, we named our bucket postgres-for-migration.

For security, make sure to block public access to this bucket. When you restore the database from this file, you use a short-lived, signed URL to access the file.

In addition, make sure the S3 bucket uses proper encryption for storage.

After creating your S3 bucket, upload the /tmp/data-for-migration.sql backup file that you created in the Dump the Database to a Local File step.
Restore to Heroku Postgres
Create a Heroku App
If you already have your app running on Heroku, you can skip this step.
Use the Heroku CLI to log into your Heroku account.
$ heroku login
Next, create a Heroku app and provide a name for it, such as postgres-migration-from-aws.
$ heroku apps:create postgres-migration-from-aws
Creating ⬢ postgres-migration-from-aws... done
Provision a Heroku Postgres Add-on
After creating your Heroku app, provision a Heroku Postgres add-on with an appropriate plan.
Based on the database information from Check Your Database Size, we use the essential-1 Heroku Postgres plan.
$ heroku addons:create \
--app postgres-migration-from-aws \
heroku-postgresql:essential-1
Creating heroku-postgresql:essential-1 on ⬢ postgres-migration-from-aws... ~$0.013/hour (max $9/month)
Database should be available soon
postgresql-flat-20854 is being created in the background. The app will restart when complete...
Use heroku addons:info postgresql-flat-20854 to check creation progress
Use heroku addons:docs heroku-postgresql to view documentation
Heroku begins provisioning a Postgres database for your Heroku app, providing a unique add-on name. Within a few minutes, you can run the following command with the database name to see the created database.
$ heroku addons:info postgresql-flat-20854
=== postgresql-flat-20854
Plan: heroku-postgresql:essential-0
Price: ~$0.007/hour
Max Price: $5/month
Attachments: ⬢ postgres-migration-from-aws::DATABASE
Owning app: ⬢ postgres-migration-from-aws
Installed at: Tue May 19 2026 15:29:01 GMT+0000 (Coordinated Universal Time)
State: created
Get the Presigned URL for the Backup File in S3
Next, restore your pg_dump backup to your new Heroku Postgres database. To restore, you need a URL that points to your backup file. The S3 bucket you created isn’t public, but you can generate a temporary, presigned URL that points to your uploaded file.
In AWS S3, navigate to the appropriate bucket and file. Under Object actions, select Share with a presigned URL.

Configure the presigned URL with a reasonable expiration time, such as 5-15 minutes, depending on your backup size.

After creating your presigned URL, it’s copied to your clipboard. The URL contains a token and signature as query parameters. It looks similar to this example:
https://postgres-for-migration.s3.us-west-2.amazonaws.com/data-for-migration.sql?response-content-disposition=inline&X-Amz-Security-Token=IQoJb3…&X-Amz-Signature=a76dfd4edee80c063…
The presigned URL grants temporary access to your database dump. Use a short expiration time appropriate for your restore duration, and delete the dump file from S3 after migration completes.
Restore Backup on Heroku
Now that you have the presigned URL, use the Heroku pg:backups:restore command to restore your backup into your new Heroku Postgres database.
Use the heroku pg:backups:restore command and provide the presigned S3 URL for your backup in quotes, and the add-on name to restore your database to:
$ heroku pg:backups:restore 'S3-PRESIGNED-URL-IN-QUOTES' postgresql-flat-20854 \
--app postgres-migration-from-aws \
--confirm postgres-migration-from-aws
Use Ctrl-C at any time to stop monitoring progress; the backup will continue restoring.
Use heroku pg:backups to check progress.
Stop a running restore with heroku pg:backups:cancel.
Starting restore of [S3-PRESIGNED-URL] to postgresql-flat-20854... done
Restoring... done
Keep in mind with this command:
- When you paste in your S3 presigned URL, make sure to contain it within quotes.
- Provide the
--appargument to tell Heroku which app and corresponding database you want to operate on. - This command is destructive, requiring you to confirm it. If you don’t provide the
--confirmargument, you’re asked to confirm the action before continuing. - The restore process automatically reassigns ownership of all schemas and tables to the default Heroku credential. The command doesn’t import roles from the source RDS database because the default Heroku database role doesn’t have permission to create Postgres roles.
- Make sure that all the extensions used in your RDS database are supported on Heroku Postgres.
Migrate Any Custom Settings
Just as you saved your AWS RDS Postgres configurations to a file called /tmp/settings_postgres.csv, you can do the same for your Heroku Postgres configuration with the command:
$ heroku pg:psql --app postgres-migration-from-aws \
-c "\copy (select * from pg_settings) to '/tmp/settings_heroku.csv' with (format csv, header true);"
Compare your Heroku Postgres settings with your AWS RDS settings. Find any configurations from your AWS RDS setup and reapply them to your Heroku Postgres instance.
Testing and Verifying a Successful Migration
We recommend testing to verify that data has migrated over successfully. Testing can include:
- Comparing table counts between the two databases.
- Comparing row counts for every table between the two databases.
- Comparing query results between the two databases.
- Running various acceptance tests on your new database to validate proper behavior and performance.
- Running the
heroku pg:backups:infocommand to review the logs of your backup restore.
Connecting Existing Apps and Services
After verifying that the database migration was successful, point your existing apps and services to the new database.
Get Heroku Postgres Credentials
When you create the Heroku Postgres add-on, Heroku automatically configures a new environment variable called DATABASE_URL, which contains the connection string for the new database. Run the heroku config:get command to fetch the value of the config var:
$ heroku config:get DATABASE_URL --app postgres-migration-from-aws
postgres://udg4tqbun4a42s:pc7e6f0f4591ba607ec21c8cf08a6bc1707c3a17931b369c43cc4aee8d330b696@cbhk6rs82poqi7.cluster-czrs8kj4isg7.us-east-1.rds.amazonaws.com:5432/d4vh47m5qj4e5g
You can also find your credentials with the heroku:pg:credentials command.
The Postgres connection string follows this format, so that you can parse the individual pieces:
postgres://DB_USERNAME:DB_PASSWORD@DB_HOST:DB_PORT/DB_NAME
Alternatively, you can obtain the connection string of your database through the dashboard.
Update Dependent Systems and Test
Update your existing systems to point to the Heroku Postgres database using its connection string. Test each system to make sure the connection is successful.
Now, you can also temporarily stop your AWS RDS instance.

Wrap-up
Now that your apps and services are pointing to Heroku Postgres and running as expected, you can close the maintenance window and restore full availability to your end users.
When you’re confident that the migration is successful and you no longer need your AWS RDS database, you can delete it completely.
With your migration complete, you can now enjoy the flexibility and low-cost convenience of Heroku Postgres. See our Heroku Postgres documentation for more information on using your database.