how to change the postgres leader region?

I created my database in the wrong region. To fix that I created new volumes in the desired region, scaled up so that they were replicas, and then deleted the volumes in the original region. However, a new leader was never assigned. I scaled down to 0 and back up, but they’re still replicas. Is there a way to change regions?

The commands I ran were approximately:

fly volumes create pg_data -a app-db --size 10 --region ewr
fly scale count 4 -a app-db
flyctl status -a app-db
fly volumes list pg_data -a app-db
fly volumes delete <>
fly scale count 0 -a app-db
fly scale count 2 -a app-db

There’s an environment variable you’ll need to change on the database.

To change that:

  1. Create an empty directory
  2. Run fly config save -a app-db
  3. Change the PRIMARY_REGION value in the generated fly.toml
  4. Run fly image show -a app-db, find the tag (like 14)
  5. Run fly deploy -i flyio/postgres:14
3 Likes