How to deploy in stereo mode (two-node HA)

vm

This guide shows how to deploy Charmed PostgreSQL in stereo mode: two postgresql units for the database, plus a separate postgresql-watcher application that supplies a third Raft vote. This gives you high availability with only two database copies.

For background on why the third vote is needed, see Stereo mode.

Prerequisites

Deploy the database

Deploy postgresql with two units:

juju deploy postgresql --channel 16/edge -n 2

Deploy the watcher

Deploy the standalone postgresql-watcher charm as a separate application, here named pg-watcher:

juju deploy postgresql-watcher pg-watcher --channel 16/edge

Integrate the watcher with PostgreSQL

Relate the two applications over the watcher endpoints:

juju integrate postgresql:watcher-offer pg-watcher:watcher

Verify the deployment

Wait until all units settle to active/idle, then run juju status. You should see two active postgresql units (one marked Primary) and an active pg-watcher, each on its own machine and — on a cloud with multiple availability zones — in a distinct availability zone:

Model    Controller  Cloud/Region     Version  SLA          Timestamp
mymodel  gce         google/us-east1  3.6.23   unsupported  09:42:31+02:00

App         Version  Status  Scale  Charm               Channel   Rev  Exposed  Message
pg-watcher  16.14    active      1  postgresql-watcher  16/edge    25  no
postgresql  16.14    active      2  postgresql          16/edge  1150  no

Unit           Workload  Agent  Machine  Public address  Ports     Message
pg-watcher/0*  active    idle   2        34.138.167.85             Raft connected, monitoring 2 PostgreSQL endpoints
postgresql/0*  active    idle   0        34.148.44.51    5432/tcp  Primary
postgresql/1   active    idle   1        34.23.202.220   5432/tcp

Machine  State    Address        Inst id        Base          AZ          Message
0        started  34.148.44.51   juju-e7c0db-0  ubuntu@24.04  us-east1-d  RUNNING
1        started  34.23.202.220  juju-e7c0db-1  ubuntu@24.04  us-east1-c  RUNNING
2        started  34.138.167.85  juju-e7c0db-2  ubuntu@24.04  us-east1-b  RUNNING

The AZ column confirms the two postgresql units and the watcher each sit in a different availability zone, as the production profile requires.

The cluster now has three Raft voters — two postgresql units plus the watcher — so it can elect a new primary automatically if one database unit is lost.