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 ...