Charmed PostgreSQL

Channel Revision Published Runs on
latest/stable 316 11 Aug 2023
Ubuntu 22.04 Ubuntu 20.04 Ubuntu 18.04 Ubuntu 16.04
14/stable 288 18 Apr 2023
Ubuntu 22.04
14/candidate 326 19 Sep 2023
14/beta 330 27 Sep 2023
14/edge 330 26 Sep 2023
juju deploy postgresql --channel 14/stable
Show information



Charm Users explanations

There are two types of users in PostgreSQL:

  • Internal users (used by charm operator)
  • Relation/integration users (used by related applications)

Internal users explanations:

The operator uses the following internal DB users:

  • postgres - the initial/default PostgreSQL user. Used for very initial bootstrap only.
  • operator - the user that uses to manage database/cluster.
  • replication - the user performs replication between database PostgreSQL cluster members.
  • rewind - the internal user for synchronizing a PostgreSQL cluster with another copy of the same cluster.
  • monitoring - the user for COS integration.
  • backups - the user to perform/list/restore backups.

The full list of internal users is available in charm source code. The full dump of internal users (on the newly installed charm):

postgres=# \du
                                      List of roles
  Role name  |                         Attributes                         |  Member of   
 backup      | Superuser                                                  | {}
 monitoring  |                                                            | {pg_monitor}
 operator    | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
 postgres    | Superuser                                                  | {}
 replication | Replication                                                | {}
 rewind      |                                                            | {}

Note: it is forbidden to use/manage described above users! They are dedicated to the operators logic! Please use data-integrator charm to generate/manage/remove an external credentials.

It is allowed to rotate passwords for internal users using action ‘set-password’:

> juju show-action postgresql set-password
Change the system user's password, which is used by charm. It is for internal charm users and SHOULD NOT be used by applications.

  type: string
  description: The password will be auto-generated if this option is not specified.
  type: string
  description: The username, the default value 'operator'. Possible values - operator, replication, rewind.

For example, to generate a new random password for internal user:

> juju run-action --wait postgresql/leader set-password username=operator

  UnitId: postgresql/1
  id: "2"
    password: k4qqnWSZJZrcMt4B
  status: completed

To set a predefined password for the specific user, run:

> juju run-action --wait postgresql/leader set-password username=operator password=newpassword

  UnitId: postgresql/1
  id: "4"
    password: newpassword
  status: completed

Note: the action set-password must be executed on juju leader unit (to update peer relation data with new value).

Relation/integration users explanations:

The operator created a dedicated user for every application related/integrated with database. Those users are removed on the juju relation/integration removal request. However, DB data stays in place and can be reused on re-created relations (using new user credentials):

postgres=# \du
                                      List of roles
  Role name  |                         Attributes                         |  Member of   
 relation-6  |                                                            | {}
 relation-8  |                                                            | {}

Note: If password rotation is needed for users used in relations, it is needed to remove the relation and create it again:

> juju remove-relation postgresql myclientapp
> juju wait-for application postgresql
> juju relate postgresql myclientapp

When an application charm requests a new user through the relation/integration it can specify that the user should have the admin role in the extra_user_roles field. The admin role enables the new user to read and write to all databases (for the postgres system database it can only read data) and also to create and delete non-system databases.

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 12 days ago. Help improve this document in the forum.