Charmed PostgreSQL VM

Channel Revision Published Runs on
latest/stable 345 09 Nov 2023
Ubuntu 22.04 Ubuntu 20.04 Ubuntu 18.04 Ubuntu 16.04
14/stable 363 21 Feb 2024
Ubuntu 22.04
14/candidate 363 31 Jan 2024
Ubuntu 22.04
14/beta 368 21 Feb 2024
Ubuntu 22.04
14/edge 399 Yesterday
Ubuntu 22.04
juju deploy postgresql --channel 14/stable
Show information

Platform:

Ubuntu
22.04

How to deploy and manage units

Note: All commands are written for juju >= v.3.0

If you are using an earlier version, be aware that:

  • juju run replaces juju run-action --wait in juju v.2.9
  • juju integrate replaces juju relate and juju add-relation in juju v.2.9

For more information, check the Juju 3.0 Release Notes.

Basic Usage

To deploy a single unit of PostgreSQL using its default configuration

juju deploy postgresql --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 --channel 14/stable -n <number_of_replicas>

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

juju run postgresql/leader get-primary

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.

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, run

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.

Replication

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>

Warning: Do not remove the last unit, it will destroy your data!


Help improve this document in the forum (guidelines). Last updated 2 months ago.