How it works...

HAProxy has a very powerful configuration syntax, which is backed by hundreds of parameters. While this makes it quite versatile, trying to write a configuration file from scratch would be extremely difficult. In our case, the number of parameters we need to set is actually fairly minimal.

We start by creating a simple role named haproxy_check so HAProxy can attempt to connect to PostgreSQL and verify the server is responding. HAProxy uses its own connection method that has some compatibility problems if no username is specified. PostgreSQL roles are not allowed to connect to any database by default, but are sufficient to pass a connectivity attempt. Once HAProxy has attempted to connect to PostgreSQL and has received an expected ...

Get PostgreSQL 12 High Availability Cookbook 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.