Fly.io Core Workflow B: Postgres, Volumes & Networking
Overview
Set up Fly Postgres, persistent Fly Volumes, and private networking between apps. Fly Postgres runs as a regular Fly app with automated replication. Volumes provide persistent NVMe storage attached to specific machines.
Instructions
Step 1: Create Fly Postgres
fly postgres create --name my-db --region iad --vm-size shared-cpu-1x --volume-size 10
fly postgres attach my-db -a my-app
fly postgres connect -a my-db
fly proxy 5432 -a my-db
Step 2: Create Persistent Volumes
fly volumes create data --size 10 --region iad -a my-app
fly volumes list -a my-app
[mounts]
source = "data"
destination = "/data"
fly deploy
fly ssh console -C "df -h /data"
Step 3: Private Networking (6PN)
DATABASE_URL=postgres://postgres:password@my-db.internal:5432/my_db
const dbUrl = `postgres://postgres:${process.env.DB_PASSWORD}@my-db.internal:5432/mydb`;
const apiUrl = `http://my-api.internal:3000/health`;
Step 4: Postgres Backups and Failover
fly postgres barman list-backups -a my-db
fly postgres barman backup -a my-db
fly postgres barman check -a my-db
fly postgres failover -a my-db
Error Handling
| Error | Cause | Solution |
|---|
volume not found | Volume in different region | Create volume in same region as machine |
connection refused on .internal | App not running | Check fly status -a target-app |
database does not exist | Not yet created | Run CREATE DATABASE mydb; via fly postgres connect |
disk full | Volume full | Extend: fly volumes extend vol_xxx --size 20 |
Resources
Next Steps
For common errors, see flyio-common-errors.