20.4. Defining the BDR failover "event_notification_command"

Key to "failover" execution is the event_notification_command, which is a user-definable script specified in repmpgr.conf and which can use a repmgr event notification to reconfigure the proxy server / connection pooler so it points to the other, still-active node. Details of the event will be passed as parameters to the script.

Following parameter placeholders are available for the script definition in repmpgr.conf; these will be replaced with the appropriate value when the script is executed:

%n

node ID

%e

event type

%t

success (1 or 0)

%t

timestamp

%d

details

%c

conninfo string of the next available node (bdr_failover and bdr_recovery)

%a

name of the next available node (bdr_failover and bdr_recovery)

Note that %c and %a are only provided with particular failover events, in this case bdr_failover.

The provided sample script (scripts/bdr-pgbouncer.sh) is configured as follows:

        event_notification_command='/path/to/bdr-pgbouncer.sh %n %e %s "%c" "%a"'

and parses the placeholder parameters like this:

        NODE_ID=$1
        EVENT_TYPE=$2
        SUCCESS=$3
        NEXT_CONNINFO=$4
        NEXT_NODE_NAME=$5

Note: The sample script also contains some hard-coded values for the PgBouncer configuration for both nodes; these will need to be adjusted for your local environment (ideally the scripts would be maintained as templates and generated by some kind of provisioning system).

The script performs following steps:

Following successful script execution, any connections to PgBouncer on the failed BDR node will be redirected to the active node.