Migrating from Vultr Managed PostgreSQL to Heroku Postgres
Last updated March 28, 2025
Table of Contents
In this guide, we walk you through the process of migrating your Postgres database from Vultr Managed Databases for PostgreSQL to Heroku Postgres. This guide uses Vultr Object Storage to store the database dump file. Before starting the migration, make sure you completed the steps from Preparing Your Migration to Heroku Postgres.
Get Your Database Size
In most cases, the dump and restore strategy for migration is suitable if your database size is less than 100 GB. With a managed database from Vultr, you can estimate your database size either through the web UI or through querying the database with the psql
client. After logging into your Vultr account, navigate to the Databases
page and click on the database you want to migrate.
In the Usage Graphs
tab for your database, you see General Usage
, which shows storage and memory statistics.
In the example, storage is 3.02 GB out of 55 GB available. However, this number includes all storage for the system running on your managed instance, including system files, installations, and more. So, the actual database size is only a fraction of this number.
For a more accurate size reading, connect to your database instance and use the list databases \l+
command. Under the Overview
tab for your database, find the Connection Details
section and click Copy Connection String
.
The connection string for using the psql
client uses the format:
postgres://DB_USERNAME:DB_PASSWORD@DB_HOST:DB_PORT/DB_NAME
Our example database is called defaultdb
, so we connect our database to the psql
client with:
$ psql postgres://vultradmin:thisismypassword@vultr-prod-7aca05a6-7c5e-4595-ac68-945a22dc0dcd-vultr-prod-bf29.vultrdb.com:16751/defaultdb
After connecting, you can show the database size with the list databases \l+
command:
$ psql=> \l+
List of databases
Name | Owner | Encoding | Collate | Size |
----------------+------------+----------+-------------+--------+
Defaultdb | vultradmin | UTF8 | en_US.UTF-8 | 335 MB |
The Size
column shows our database size is 335 MB.
See Choosing the Right Heroku Postgres Plan for which Heroku Postgres plan fits your database size.
Prepare 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.
Back Up Your Database
Before performing the migration, make sure you have a recent backup of your database on Vultr. Vultr takes a daily snapshot backup of your managed Postgres database. In the Overview
tab for your database, find the Actions
section and click Restore From Backup
.
In the modal that pops up, you see available point-in-time backups that Vultr created, which you can restore to a new database cluster at Vultr in case of a migration issue.
Dump the Database to a Local File
Using pg_dump
, dump your Vultr database to a local file:
$ pg_dump postgres://DB_USERNAME:DB_PASSWORD@DB_HOST:DB_PORT/DB_NAME \
-Fc -b -v \
-f /tmp/vultr-data-for-migration.sql
The time it takes to run this command varies depending on the size of your database. You can keep an eye on the file size of /tmp/data-for-migration.sql
to verify that the long process is running.
Upload the File to Vultr Object Storage
Heroku can restore a Postgres database from a file that’s accessible via a URL. For this migration from Vultr, you can upload your data backup file to Vultr Object Storage.
On the Object Storage
main page, create a bucket. In this example, we named our bucket postgres-for-migration
.
After creating the bucket, upload the /tmp/data-for-migration.sql
file from the Dump the Database to a Local File step. Uploading to Vultr Object Storage requires using the AWS CLI. You can follow the directions to set up the CLI along with the proper configuration and credentials to access your buckets. On the main Object Storage
page, find the S3 Credentials
section for the information to use with the AWS CLI.
With your AWS profile set up to access Vultr, upload your data backup file to your Vultr Object Storage bucket:
$ aws s3 cp \
/tmp/vultr-data-for-migration.sql \
s3://postgres-for-migration/vultr-data-for-migration.sql \
--profile=vultr
$ aws s3 ls \
s3://postgres-for-migration \
--profile=vultr
2024-10-17 10:44:00 34871869 vultr-data-for-migration.sql
Perform the Restore Migration
Create a Heroku app
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-vultr
.
$ heroku apps:create psql-migration-from-vultr
Creating ⬢ psql-migration-from-vultr... done
Create the Heroku Postgres Add-on
After creating your Heroku app, add the Heroku Postgres add-on with an appropriate plan. Based on the database information from Get Your Database Size, we use the Essential-1 Postgres plan.
$ heroku addons:create \
--app psql-migration-from-vultr \
heroku-postgresql:essential-1
Creating heroku-postgresql:essential-1 on ⬢ psql-migration-from-vultr... ~$0.013/hour (max $9/month)
Database should be available soon
postgresql-defined-13934 is being created in the background. The app will restart when complete...
Use heroku addons:info postgresql-defined-13934 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 name. Within a few minutes, you can run the following command with the database name to see the created database.
$ heroku addons:info postgresql-defined-13934
=== postgresql-defined-13934
Attachments: psql-migration-from-vultr::DATABASE
Installed at: Thu Oct 17 2024 11:15:00 GMT-0700 (Mountain Standard Time)
Max Price: $9/month
Owning app: psql-migration-from-vultr
Plan: heroku-postgresql:essential-1
Price: ~$0.013/hour
State: created
Install Necessary Extensions for Heroku Postgres
Before migrating data, install any extensions you had in your Vultr Postgres instance.
First, to see what extensions are already installed on your Heroku Postgres instance, connect to your Heroku Postgres instance with pg:psql
:
$ heroku pg:psql --app psql-migration-from-vultr
--> Connecting to postgresql-defined-13934
psql (16.4 (Ubuntu 16.4-1.pgdg20.04+1), server 16.2)
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off)
Type "help" for help.
psql=> \dx
List of installed extensions
Name | Version | Schema | Description
--------------------+---------+------------+-------------------------------
pg_stat_statements | 1.10 | public | track planning and executio...
plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language
(2 rows)
Install any extensions you had at Vultr that aren’t already in Heroku Postgres. For our example, we need the tablefunc
extension.
$ psql=> CREATE EXTENSION IF NOT EXISTS tablefunc;
CREATE EXTENSION
psql=> \dx
List of installed extensions
Name | Version | Schema | Description
--------------------+---------+------------+-------------------------------
pg_stat_statements | 1.10 | public | track planning and execution…
plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language
tablefunc | 1.0 | public | functions that manipulate…
(3 rows)
See Extensions, PostGIS, and Full Text Search Dictionaries on Heroku Postgres for supported extensions and how to install them.
Get the Signed URL For the File in Vultr Object Storage
Next, restore all the data from your pg_dump
backup to your new Heroku Postgres database. For this, you need a URL that points to your backup file. Similar to your upload of the file, you’ll use the aws
CLI.
$ aws s3 presign \
s3://postgresql-for-migration/vultr-data-for-migration.sql \
--expires-in 600 \
--profile=vultr
In the operation, s3 presign
takes the S3 URI for the file we want to access. We also set --expires-in
to 600 seconds, or 10 minutes for us to access and use this file for Heroku’s database restoration process.
In our example, the signed URL for our database dump file is:
https://ewr1.vultrobjects.com/postgres-for-migration/vultr-data-for-migration.sql?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=P2E4IUE037MG2HBIBHGZ%2F20241017%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20241017T174614Z&X-Amz-Expires=600&X-Amz-SignedHeaders=host&X-Amz-Signature=63e91914dc1de6f691ff8d17ae4040bcd932b33f7929112736af8a6140c111c3
Restore on Heroku
Now that you have the presigned URL, use the Heroku pg:backups:restore
command to restore your Heroku Postgres database from your Vultr Cloud Object Storage. The command looks like:
$ heroku pg:backups:restore 'VULTR-PRESIGNED-URL-IN-QUOTES' \
--app psql-migration-from-vultr \
--confirm psql-migration-from-vultr
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 [VULTR-PRESIGNED-URL] to postgresql-defined-13934... done
Restoring... done
Keep in mind with this command:
- When you paste in your Vultr Object Storage-signed URL, make sure to contain it within quotes.
- Provide the
--app
argument to tell Heroku which application and corresponding database you want to operate on. - This command is destructive, requiring you to confirm it. If you don’t provide the
--confirm
argument, you’re asked to confirm the action before continuing.
Migrate Any Custom Settings
Just as you saved your Vultr 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 psql-migration-from-vultr \
-c "\copy (select * from pg_settings) to '/tmp/settings_heroku.csv' with (format csv, header true);"
Compare your Heroku Postgres settings with your Vultr Postgres settings. Find any configurations from your Vultr Postgres 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, validating proper behavior and performance.
Connecting Existing Applications and Services
After verifying that the database migration was successful, point your existing applications 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 credentials and connection information for your new database. Run the heroku config:get
command to fetch the variable:
$ heroku config:get DATABASE_URL --app psql-migration-from-vultr
postgres://ubakjtsu83gfqg:pc89708e066d76abaa88f11e8b5323dd6342e75a3f82abdbef6ed5774833e536e@cbhk6rs82poqi7.cluster-czrs8kj4isg7.us-east-1.rds.amazonaws.com:5432/d3vb4v6d29acr4
You can also find your credentials with the heroku:pg:credentials
command.
The Postgres URI follows this format, so that you can parse the individual pieces:
postgres://DB_USERNAME:DB_PASSWORD@DB_HOST:DB_PORT/DB_NAME
Update Dependent Systems and Test
Update your existing systems to point to Heroku Postgres with this information. Test each system to make sure the connection is successful.
Wrap-up
Now that your applications 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 Vultr database, you can delete it completely. Navigate to the Settings
tab for your database and click Destroy Database Instance
.
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.