Fly.ioTutorial
Using Heroku Postgres From A Fly App
Summary
A Fly application can use Heroku Postgres without migrating the application itself, with Heroku hosting an add-on-only app that provides the database. The setup provisions a Hobby Dev Heroku Postgres database, retrieves its URI credentials, and passes DATABASE_URL to the Fly deployment as a secret. A Node REST API using Sequelize parses that URI with pg-connection-string, then supplies the database, user, password, and host while enabling SSL and setting rejectUnauthorized to false for Heroku’s certificate-chain issue. After fly deploy, the app connects externally to Postgres, but the Hobby plan limits it to 20 connections unless upgraded. The article presents Heroku’s US and Europe data-center choices as a way to keep the database relatively close while Fly places the application near users, and warns that credentials rotate periodically without notification.
Context
Applications do not need to migrate from Heroku to Fly to use Heroku-hosted databases. Heroku can provide Postgres through an app with no application code, and the article presents this as a database option for a native Fly application.
Approach / What changed
Provision a Hobby Dev Heroku Postgres add-on, copy its URI from the database credentials, and store it as the Fly app’s DATABASE_URL secret. A Node and Sequelize application parses the URI with pg-connection-string and configures PostgreSQL with SSL enabled and rejectUnauthorized set to false.
Takeaways
Heroku’s Hobby Dev Postgres plan provides a 1GB database capable of holding up to 10,000 rows in the example.
External access to Heroku Postgres requires SSL; the Sequelize configuration also disables rejection of self-signed certificates in Heroku’s server certificate chain.
Heroku rotates database credentials periodically and does not warn applications when they change; the database is also limited to 20 connections unless the plan is upgraded.
Source and freshness
- Source
- fly.io
- Published
- Added to Yomu
- Last updated
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.