You may not have seen this, but we launched a free volume tier a few weeks ago. Which means, free Postgres for side projects.
Our Postgres installations make it easy to move volume sizes. Here’s what you’d run assuming you have a single Postgres instance running and want to scale the volume down to 1GB:
Add a new 1GB volume to your Postgres app: fly volumes create pg_data --size 1 --region <your-pg-region> -a <pgname>
Run fly status -a <pgname>, note which instance is the leader and how many instances are running
Add one more instance: fly scale count 2 -a <pgname> (add a second instance)
Wait a few minutes, then run fly status to make sure the new instance is in secondary state
fly volumes list to get the old volume ID
fly volumes delete <old-volume-id>
fly scale count 1 -a <pgname>: scale back to one instance
This works because all our Postgres apps are clusters, even if they’re only running one instance. When you scale up, it creates a replica. When you remove the old volume, it stops the primary, the new replica takes over, and you’re back down to one happy Postgres.
Be careful: under no circumstances should leave one instance of postgres running with 2+ volumes. If that VM crashes, it might come up on an empty disk. You should always have the exact number of volumes as fly scale count <x> is set to.
@kurt is there room here for a new CLI keyword to allow volume size-up or size-down, automating your instructions above, with the requisite waits, checks, etc.
fly pg vol expand/contract --from=x --to=y or something…
No it doesn’t. You do have to add a volume before you add VM instances. This is fine, what you don’t want is to have 2 volumes and one instance running for long periods of time.