How to scale a cluster

vmk8s

Replication in PostgreSQL is the process of creating copies of the stored data. This provides redundancy, which means the application can provide self-healing capabilities in case one replica fails. In this context, each replica is equivalent to one juju unit.

This guide will show you how to establish and change the amount of Juju units used to replicate your data.

Deploy PostgreSQL with n replicas

To deploy PostgreSQL with multiple replicas, specify the number of desired units with the -n option.

juju deploy postgresql --channel 16/stable -n <number_of_replicas>
juju deploy postgresql-k8s --channel 16/stable -n <number_of_replicas> --trust

Scale replicas on an existing application

The amount of replicas (Juju units) can also be modified after deployment.

To scale up the cluster, use juju add-unit:

juju add-unit postgresql --num-units <amount_of_units_to_add>

To scale down the cluster, use juju remove-unit:

juju remove-unit postgresql/<unit_id_to_remove>

In Kubernetes, scaling operations are performed using juju scale-application and specifying the total amount of units you want to have in the cluster:

juju scale-application postgresql-k8s <total number of units>

See also: PostgreSQL units