I haven’t tried this yet because I don’t want to break production, but I wonder if anyone has done this:
HA will give you one primary and n replicas:
ID STATE ROLE REGION CHECKS IMAGE CREATED UPDATED
e78423d1a33148 started replica iad 3 total, 3 passing flyio/postgres-flex:15.3 (v0.0.46) 2024-01-03T15:35:20Z 2024-01-03T15:35:32Z
e2866756a37148 started replica iad 3 total, 3 passing flyio/postgres-flex:15.3 (v0.0.46) 2024-01-03T15:45:44Z 2024-01-03T15:45:54Z
d891116b6505e8 started primary ewr 3 total, 3 passing flyio/postgres-flex:15.3 (v0.0.46)
Now, let’s say I have an app running in ewr and I would like to deploy another one in iad. would this database setup work?
production:
primary:
database: my_primary_database
port: 5432
hostname: top1.nearest.of.<postgres cluster app name>.internal
username: postgres
password: <%= ENV['ROOT_PASSWORD'] %>
primary_replica:
database: my_primary_database
username: root_readonly
hostname: top1.nearest.of.<postgres cluster app name>.internal
password: <%= ENV['ROOT_READONLY_PASSWORD'] %>
port: <%= ENV["PRIMARY_REGION"] == ENV["FLY_REGION"] ? 5432 : 5433 %>
replica: true
I’m trying to think about all the scenarios and I think this would work without having to use fly-ruby (which seems abandoned?) and hijack the connection.
POST/PATCH/PUT would fall into the writer role and defaults to the primary database, regardless of their region and apps deploying in iad would read from the replica in iad. instances in ewrwould read/write from the primary
does that make sense, or am I missing something?