How it works...

This recipe relies on a dirty trick to avoid the long and irritating process of rebooting a server. The patroni daemon considers itself the solitary coordinator of the PostgreSQL service. Just as it will restart databases we stop without its permission, it will also stop running databases if we end the patroni service itself.

The pkill command is extremely useful for stopping services without knowing their process ID. By invoking it with the -f flag, we tell it to match the full text of the command that launched the patroni daemon. As a result, any and all currently running processes with patroni in the name will cease.

We need to execute the pkill command on the server currently acting as the primary node. Without Patroni ...

Get PostgreSQL High Availability Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.