Charmed PostgreSQL K8s

  • By Canonical Data Platform
Channel Revision Published Runs on
latest/stable 20 20 Sep 2022
Ubuntu 20.04
14/stable 73 18 Apr 2023
Ubuntu 22.04
14/candidate 73 18 Apr 2023
14/beta 73 18 Apr 2023
14/edge 92 Yesterday
juju deploy postgresql-k8s --channel 14/stable
Show information


How to deploy and manage units

Basic Usage

To deploy a single unit of PostgreSQL using its default configuration

juju deploy postgresql-k8s --channel 14/stable

It is customary to use PostgreSQL with replication. Hence usually more than one unit (preferably an odd number to prohibit a “split-brain” scenario) is deployed. To deploy PostgreSQL with multiple replicas, specify the number of desired units with the -n option.

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

To retrieve primary replica one can use the action get-primary on any of the units running postgresql-k8s

juju run-action postgresql-k8s/leader get-primary --wait

Similarly, the primary replica is displayed as a status message in juju status, however one should note that this hook gets called on regular time intervals and the primary may be outdated if the status hook has not been called recently.

Further we highly suggest configuring the status hook to run frequently. In addition to reporting the primary, secondaries, and other statuses, the status hook performs self healing in the case of a network cut. To change the frequency of the update status hook do:

juju model-config update-status-hook-interval=<time(s/m/h)>

Note that this hook executes a read query to PostgreSQL. On a production level server this should be configured to occur at a frequency that doesn’t overload the server with read requests. Similarly the hook should not be configured at too quick of a frequency as this can delay other hooks from running. You can read more about status hooks here.


Both scaling-up and scaling-down operations are performed using juju scale-application:

juju scale-application postgresql-k8s <desired_num_of_units>

Warning: scaling-down to zero units will destroy your data!

Help us improve this documentation

Most of this documentation can be collaboratively discussed and changed on the respective topic in the doc category of the Charmhub forum. See the documentation guidelines if you’d like to contribute.

Last updated a month ago. Help improve this document in the forum.