# Does Postgres regional failover happen automatically?

**URL:** <https://community.fly.io/t/does-postgres-regional-failover-happen-automatically/12458>\
**Category:** General\
**Tags:** postgres, login-only\
**Created:** [April 24, 2023, 12:34pm UTC](https://community.fly.io/t/does-postgres-regional-failover-happen-automatically/12458 "2023-04-24T12:34:23Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![shugel](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/shugel/32/48662_2.png) [@shugel](https://community.fly.io/u/shugel)\
**Post date:** [April 24, 2023, 12:34pm UTC](https://community.fly.io/t/does-postgres-regional-failover-happen-automatically/12458/1 "2023-04-24T12:34:24Z")

</div>

I have a pretty standard Fly setup: HA Postgres in one region, with a read replica in an adjacent region, with app instances to match (2 primary + 1 backup). I have no other volumes.

If my primary region goes down, my secondary region remains available, but I assume it will be in read-only mode: that is, my single read replica isn’t elected as a leader (is this assumption correct?).

Is there a way to configure my cluster to automatically fail over to my backup region, e.g. by running a second read replica in the backup region, so there are at least theoretically enough members to create a HA cluster?

---

<div class="post-metadata">

**Author:** ![danwetherald](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/danwetherald/32/37600_2.png) [@danwetherald](https://community.fly.io/u/danwetherald)\
**Post date:** [April 25, 2023, 5:45am UTC](https://community.fly.io/t/does-postgres-regional-failover-happen-automatically/12458/2 "2023-04-25T05:45:27Z")

</div>

I have been trying to better understand this topic as well over here:

[https://community.fly.io/t/better-understanding-best-practices-for-ha-for-both-web-apps-and-pg-apps](https://community.fly.io/t/better-understanding-best-practices-for-ha-for-both-web-apps-and-pg-apps)

---

<div class="post-metadata">

**Author:** ![shaun](https://avatars.discourse-cdn.com/v4/letter/s/f07891/32.png) [@shaun](https://community.fly.io/u/shaun)\
**Post date:** [April 25, 2023, 1:04pm UTC](https://community.fly.io/t/does-postgres-regional-failover-happen-automatically/12458/3 "2023-04-25T13:04:41Z")

</div>

> If my primary region goes down, my secondary region remains available, but I assume it will be in read-only mode: that is, my single read replica isn’t elected as a leader (is this assumption correct?).

Yep, that is correct. Keep in mind though, if you’re running the flex implementation, you need 3 nodes running within your primary region for HA.

> Is there a way to configure my cluster to automatically fail over to my backup region, e.g. by running a second read replica in the backup region, so there are at least theoretically enough members to create a HA cluster?

We do not currently support automatic regional failovers. In the event you need to perform a regional failover on a Nomad setup, you can reference: [High Availability & Global Replication · Fly Docs](https://fly.io/docs/postgres/advanced-guides/high-availability-and-global-replication/#performing-a-regional-failover)

---

<div class="post-metadata">

**Author:** ![shugel](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/shugel/32/48662_2.png) [@shugel](https://community.fly.io/u/shugel)\
**Post date:** [April 25, 2023, 2:00pm UTC](https://community.fly.io/t/does-postgres-regional-failover-happen-automatically/12458/4 "2023-04-25T14:00:19Z")

</div>

> [@shaun](#):
>
> flex

I migrated to the V2 version of Postgres last week, so I’m not on Nomad anymore, but I’m not sure whether I’m on flex. I’m running image version `flyio/postgres:14.6 (v0.0.38)`, so maybe it is? How can I confirm this?

In any case, the [docs](https://fly.io/docs/postgres/advanced-guides/high-availability-and-global-replication/) explicitly mention 2 + nodes for HA, _not_ 3. It’s not a problem for me to scale up, but that should be mentioned – Postgres V1 created two nodes and called it HA.

> We do not currently support automatic regional failovers. In the event you need to perform a regional failover on a Nomad setup, you can reference: [High Availability & Global Replication · Fly Docs](https://fly.io/docs/postgres/advanced-guides/high-availability-and-global-replication/#performing-a-regional-failover)

Thanks for clarifying. Are there plans to support it? As I mentioned, I’m no longer on Nomad…

---

<div class="post-metadata">

**Author:** ![shaun](https://avatars.discourse-cdn.com/v4/letter/s/f07891/32.png) [@shaun](https://community.fly.io/u/shaun)\
**Post date:** [April 25, 2023, 2:20pm UTC](https://community.fly.io/t/does-postgres-regional-failover-happen-automatically/12458/5 "2023-04-25T14:20:35Z")

</div>

@shugel Yeah, i’m sorry this is confusing.

Stolon setups run the image: `flyio/postgres:*`  
Flex setups run the image: `flyio/postgres-flex:*`

> Are there plans to support it?

We don’t have any immediate plans. It’s actually a pretty hard problem and the rarity of a regional split/outage makes it a tough to prioritize. At the very least, we do want to simplify the process for users who wish to manually failover into a new region.

---

<div class="post-metadata">

**Author:** ![danwetherald](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/danwetherald/32/37600_2.png) [@danwetherald](https://community.fly.io/u/danwetherald)\
**Post date:** [April 25, 2023, 3:14pm UTC](https://community.fly.io/t/does-postgres-regional-failover-happen-automatically/12458/6 "2023-04-25T15:14:18Z")

</div>

> [@shaun](#):
>
> Stolon setups run the image: `flyio/postgres:*`  
> Flex setups run the image: `flyio/postgres-flex:*`

@shaun Can you share some documentation on the difference of these two images and the correct way to deploy each image? Also, is there somewhere we can learn more on how these work during failures (both hardware and regional failures).

---

<div class="post-metadata">

**Author:** ![shaun](https://avatars.discourse-cdn.com/v4/letter/s/f07891/32.png) [@shaun](https://community.fly.io/u/shaun)\
**Post date:** [April 25, 2023, 3:21pm UTC](https://community.fly.io/t/does-postgres-regional-failover-happen-automatically/12458/7 "2023-04-25T15:21:27Z")

</div>

The Postgres Flex implementation is the current default setup, assuming you’re running a recent `flyctl` version.

This post should provide some context:

> [@Improved Postgres Clustering with repmgr - Preview](https://community.fly.io/t/improved-postgres-clustering-with-repmgr-preview/10668):
>
> What’s this about? Over the last year, we have been seeing more and more Postgres apps go down due to unstable connections with our multi-tenant Consul service. Stolon, the open-source solution that we have been using for HA management requires an always-stable connection with our Consul. The issue is when that connection becomes unstable, PG’s start becoming unaccessible. We have been pretty disappointed with how this has impacting our users and decided it was time to try a new approach. Th…

> Also, is there somewhere we can learn more on how these work during failures (both hardware and regional failures).

How this implementation responds during hardware and regional failures is going to depend heavily on your setup.

How we handle fencing can be found here, which may or may not answer some of your questions: [postgres-flex/docs/fencing.md at master · fly-apps/postgres-flex · GitHub](https://github.com/fly-apps/postgres-flex/blob/master/docs/fencing.md)

If you have any specific scenarios in mind, let me know.

---

<div class="post-metadata">

**Author:** ![danwetherald](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/danwetherald/32/37600_2.png) [@danwetherald](https://community.fly.io/u/danwetherald)\
**Post date:** [April 25, 2023, 3:26pm UTC](https://community.fly.io/t/does-postgres-regional-failover-happen-automatically/12458/8 "2023-04-25T15:26:26Z")

</div>

Thanks @shaun - I am actually reading through that topic as we speak.

As for describing some of the scenarios, I have had a topic open here: [https://community.fly.io/t/better-understanding-best-practices-for-ha-for-both-web-apps-and-pg-apps](https://community.fly.io/t/better-understanding-best-practices-for-ha-for-both-web-apps-and-pg-apps) that explains some of the situations that I am trying to better understand as well as how to best set everything up for HA.

---

<div class="post-metadata">

**Author:** ![shaun](https://avatars.discourse-cdn.com/v4/letter/s/f07891/32.png) [@shaun](https://community.fly.io/u/shaun)\
**Post date:** [April 25, 2023, 3:55pm UTC](https://community.fly.io/t/does-postgres-regional-failover-happen-automatically/12458/9 "2023-04-25T15:55:32Z")

</div>

So I think some of your questions may be a little too broad, making them challenging to answer in a timely manor. Answering how HA works is tough when the context spans Apps, Proxy, Databases, etc. I would recommend trying to come up with some specific failure cases that you’re worried about or work to define the specific requirements that you’re working with and folks can help make some recommendations.

---

<div class="post-metadata">

**Author:** ![danwetherald](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/danwetherald/32/37600_2.png) [@danwetherald](https://community.fly.io/u/danwetherald)\
**Post date:** [April 25, 2023, 4:02pm UTC](https://community.fly.io/t/does-postgres-regional-failover-happen-automatically/12458/10 "2023-04-25T16:02:21Z")

</div>

Hmm I had a few other pretty specific questions in there, I also outlined 3 examples of failures that we would like to feel good about handling. I also have some very specific questions that are aimed at some pretty specific scenarios.

@shaun Should we move this conversation to the thread I referenced?

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/fly1/original/3X/6/e/6e8955d00cb218e186ebbe3a6ab06fefdce15290.svg) [@system](https://community.fly.io/u/system)\
**Post date:** [May 2, 2023, 4:02pm UTC](https://community.fly.io/t/does-postgres-regional-failover-happen-automatically/12458/11 "2023-05-02T16:02:57Z")

</div>

Closed on May 2, 2023, 4:02pm UTC

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
