This seems to work for moving from old Fly Postgres to Postgres Flex
Make a new DB with a different name
fly pg create --name {app}-db --enable-backups
Scale memory
fly m list # to get machine id
fly machine update --vm-memory 512 {machine_id}
Get old DATABASE_URL
from a running app
fly ssh console --app {app that uses the db}
env | grep DATABASE_URL
Use the import tool to import the existing database to the new DB instance
fly postgres import {DB_URL from above} -a {app}-db
I wasn’t able to directly attach, and detach didn’t work, so I found that you can attach it to the app, but with a different secret name initially.
fly postgres attach {app}-db -a {app} --variable-name DATABASE_URL_2
Override to the new DATABASE_URL
fly secrets set -a {app} DATABASE_URL={NEW DATABASE_URL}
If that updates, check the app still works, and stop the old DB instance
fly m list -a {old DB app name}
fly m stop {machine_id}
If everything still works now, the old DB instance could be deleted, but I’m going to sleep on it first!
You can also now remove the temporary secret that the DB was attached with:
fly secrets unset -a {app} DATABASE_URL_2
And now the database is running with the flex image!