# What is the correct process to change the postgres leader region?

**URL:** <https://community.fly.io/t/what-is-the-correct-process-to-change-the-postgres-leader-region/4831>\
**Category:** General\
**Created:** [April 22, 2022, 5:59am UTC](https://community.fly.io/t/what-is-the-correct-process-to-change-the-postgres-leader-region/4831 "2022-04-22T05:59:16Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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 27, 2022, 6:00pm UTC](https://community.fly.io/t/what-is-the-correct-process-to-change-the-postgres-leader-region/4831/2 "2022-04-27T18:00:28Z")

</div>

Hey there,

So it’s a bit of a process, but i’ll walk you through it.

**Step 1: Adjust your apps primary region.**

Pull down your `fly.toml` file if you haven’t already.

```auto
fly config save --app <app-name>

```

Modify the `PRIMARY_REGION` value inside of your fly.toml file

```auto
[env]
 PRIMARY_REGION = "lax"

```

Deploy your app.

**WARNING: Your app will not accept writes until your issue the failover in Step 2. The HAProxy routes connections to the primary and leverages the PRIMARY REGION env var. This also requires an immediate deploy, which means it will deploy the new image to all members at the same time. This will result in a brief period of downtime. I would recommend testing this process on a staging environment if this app is critical.**

```auto
# Run this inside the same directory as your fly.toml
fly deploy . --image flyio/postgres:<major-version> --strategy=immediate

```

If you don’t the image you’re running, you can view it by running:  
`fly image show`

So for example, if you’re Tag indicates `14.2`, the image reference should look like `flyio/postgres:14`.

**Step 2: Orchestrating a failover**

Verify your version:

```auto
fly image show

Registry = registry-1.docker.io
Repository = flyio/postgres
Tag = 14.2
Version = v0.0.21
Digest = sha256:4e4a7bfef439b5e02fa3803c4b8225b57c297fa114f995855d5d7807828d9008

```

If you’re running `PG13/14` with `Version v0.0.13+`

```auto
fly ssh console --app <app-name>

pg-failover

```

If you’re running `PG12` or an earlier Version:

```auto
fly ssh console --app <app-name>

bash
# Export Stolon specific env vars.
export $(cat /data/.env | xargs) 

# Identify the master keeper id
stolonctl status  

# Fail the master keeper to trigger the failover.
stolonctl failkeeper <master-keeper-id>

# Verify the state of the world.
stolonctl status # Verify that the master has indeed changed.

```

Let me know if you have any questions on anything.

---

_[View the full topic](https://community.fly.io/t/what-is-the-correct-process-to-change-the-postgres-leader-region/4831)._
