We offer complimentary hands-on migration assistance for Heroku migrations on a case-by-case basis. Reach out to learn more.
ff-seq.sh tool from our logical replication strategy that can provide a true zero-downtime exit strategy from Heroku. Get in touch if this is a requirement for you.
Setup, copy, and replication
-
Create a PlanetScale Postgres database.
- Choose a size with similar CPU and RAM as what you run in Heroku. Don’t stress as resizing in PlanetScale is an online operation.
- Ensure you have at least twice the storage space as Heroku reports using. (Postgres disk usage can vary wildly and Bucardo is not very space-efficient. It is not uncommon for a database to use 50% more or less space on PlanetScale than on Heroku. Automatic vacuuming will return disk usage to its true size over time.) Either choose a PlanetScale Metal size with enough space or visit the Storage tab of the Cluster Configuration page to proactively adjust how much space is available on your network-attached storage volumes.
- Launch an EC2 instance where you’ll run Bucardo. It must run Linux and have network connectivity to both Heroku and PlanetScale. We recommend something at least medium-sized e.g. t3a.medium.
-
Install and configure Bucardo there:
-
Export two environment variables there:
HEROKU: URL-formatted Heroku Postgres connection information for the source database.PLANETSCALE: Space-delimited PlanetScale Postgres connection information for thepostgresrole (as shown on the Connect page for your database) for the target database.
-
Ensure via
heroku pg:locksthere are noVACUUMqueries with(to prevent wraparound)running as these will block the creation of triggers in the next step which could in turn block the execution of your application’s queries. (If you’re following this guide but aren’t actually on Heroku, useSELECT * FROM pg_stat_activity WHERE query LIKE '% (to prevent wraparound)';instead.) -
Configure and start Bucardo:
Monitor progress
Use thestat-bucardo-repl.sh tool to monitor the overall state of your migration:
count(*) aggregation or by specifically SELECTing data you know to have just written) before moving on.
Count rows to gauge how caught-up the asynchronous replication is (where example is one of your table names):
Switch traffic
Because Bucardo is replicating both table and sequence data, it’s critical to stop write traffic at the source completely.heroku maintenance:on can stop all traffic but if you want to continue to allow read traffic, you can either arrange for that at the application level or enforce it at the database level thus:
REVOKE statement above and need to abort before switching traffic and return to service on Heroku, revert as follows:
Cleanup
-
Remove the Bucardo sync and metadata:
- Optionally, terminate the EC2 instance that was hosting Bucardo.
- When the migration is complete and validated, delete the source Heroku Postgres database.
See also
- Bucardo pgbench example
- Bucardo setup gist
- Smartcar zero-downtime migration
- PostgreSQL replication with Bucardo 5.4.1
- Bootstrap Bucardo multimaster
- Migrating Postgres from Heroku to RDS
- Zero-downtime PostgreSQL migrations with Bucardo and Terraform
- Bucardo Terraform archive
- Replication of tables without primary keys
- Bucardo setup gist

