The last thing we are going to add should be considered a requirement when building a high-availability PostgreSQL cluster. Any time the status of Pacemaker changes, we can have it transmit an e-mail alerting us to the activity. Not only is this possible with Pacemaker, it's relatively easy to set up.
This recipe will outline the steps necessary to add an e-mail alert to Pacemaker.
As we're continuing to configure Pacemaker, make sure you've followed all the previous recipes.
Perform these steps on any Pacemaker node as the root
user:
primitive
to Pacemaker with crm
:crm configure primitive pg_mail ocf:heartbeat:MailTo params email="[email protected]" subject="Pacemaker cluster status changed: "
crm
:crm resource cleanup pg_mail
crm
:crm resource status
To add an e-mail alert, we need to configure
another primitive
with crm
. We name this resource pg_mail
so that it fits in with the other services that we've configured so far. As always, we need a resource agent for Pacemaker to invoke when necessary, and the ocf:heartbeat:MailTo
agent works well for our use case.
The MailTo
agent is not a regular resource, as it does not represent any actual system service. It's more of a defined action that Pacemaker should invoke while managing other cluster resources. This means it's essentially useless until we associate it with another Pacemaker primitive
.
The MailTo
agent also has two parameters (params
) we are interested in setting. We begin by setting email
to an e-mail address for a recipient tasked with monitoring the PostgreSQL cluster. In most cases, this is either a single DBA or the entire team. In any case, we strongly suggest that you transmit these alerts to anyone associated with the PostgreSQL database, in case one or more members of the team are unavailable.
The next setting that concerns us is the subject
of the message. If we don't set this, Pacemaker uses a suitable default, but it's good to have more control over the messages in case we want to set up e-mail rules or filters. Use any message you like, but there are a couple of important notes:
). Otherwise, Pacemaker will print out a lot of errors and refuse to add the primitive
.With that said, we are now ready to clean up and view our list of resources. Let's see the output of resource status
on our test system:
We can see from this output that pg_mail
is listed as Started
, even though it doesn't do anything by itself. We'll be fixing this soon enough.
3.145.202.61