Postgresql Charm Switchover

If anybody is searching for how to perform a graceful switchover of you Live Master Postgresql to your secondary here’s how to do it:

Ensure the command is run against the Leader unit. From the juju status output the unit with the * is the leader:

root@maas-01:~# juju status
Model            Controller                Cloud/Region              Version  SLA          Timestamp
postgresql-home  lab.devzero.home-default  lab.devzero.home/default  2.8.1    unsupported  22:34:55Z

App         Version  Status  Scale  Charm       Store       Rev  OS      Notes
postgresql  12.5     active      2  postgresql  jujucharms  208  ubuntu

Unit           Workload  Agent  Machine  Public address  Ports     Message
postgresql/0   active    idle   0        192.168.51.30   5432/tcp  Live master (12.5)
postgresql/1*  active    idle   1        192.168.51.3    5432/tcp  Live secondary (12.5)

Machine  State    DNS            Inst id       Series  AZ    Message
0        started  192.168.51.30  postgresql-0  focal   AZ-1  Deployed
1        started  192.168.51.3   postgresql-1  focal   AZ-2  Deployed

The exact context to turn postgresql/1 to the master

juju run-action postgresql/1 switchover --wait --string-args master=postgresql/1

The reason for this post is the required switchover arguments aren’t clear from the juju actions output on the cli or on Charms homepage / documentation in the store.
I was lucky enough to stumble upon the required arguments on this unrelated post in discourse.

For a new Juju user this type of thing will be infuriating and probably be the reason they abandon using Juju.

4 Likes

Would this rather be part of the docs in the charm?

That would be my expectation. If the Charm supports actions there should be a section on the Charms homepage covering what the actions do with a couple of examples.

The Ceph OSD charm does this quite nicely.

Actions and relations are what makes Juju sooooo powerful, but if it’s not clear how to use them, they become kinda useless right?

I’m really thinking that the charmstore should present the actions.yaml schema data in a useful way in the same manner it does config.yaml.

The schema of actions.yaml is quite clear as to what the action does and the required parameter, but the auto-documentation of charmstore doesn’t really spell this out.

I would agree, temporarily, it may be helpful to put this change into the README for the charm, but I think it’d benefit all charms to have action schema documentation be made readable as documentation on charmstore.

While it’s not a user-friendly interface to this kind of documentation, adding --schema to juju actions command can help you determine the required and available params of a charm’s actions.

juju actions --schema postgresql
*snip*
switchover:
  description: |
    Promote a specific unit to master. Must be run on the leader unit.
  properties:
    master:
      description: Unit to promote to master (eg. postgresql/3).
      type: string
  required:
  - master
  title: switchover
  type: object
*snip*

@afreiberger we are actually currently migrating charms to the new charmhub.io . If a charm has a actions.yaml it should appear in the details page of the charm, see the action tab.

Currently not all charms are imported and may not have their actions.yaml imported too, but we are on it :wink:

This is an example of how it will look like: Deploy Graylog using Charmhub - The Open Operator Collection

4 Likes

A cosmetic note for actions in charmhub.io is that parameters that are required could just be marked as such rather than repeated in a section below. It’s more clean and less scrolling etc.

Nice work.

1 Like

Ah, that’s a very good idea, +1

1 Like

The new charmhub mechanism for docs managed as discourse topics is really nice. We are polishing up the navigation / index format at the moment but I really like how it has come together.

ah, @erik-lonroth great idea! @danielmutis @toto something for us adjust

In addition to the improvements already mentioned; the Juju Dashboard will be gaining the ability to list, initiate, and monitor actions in the new year. We will be sure to post here once that’s available.

2 Likes

That’s amazing!

@lasse @xinyuem @hallback