Configuring haproxy v23

TPA will install and configure haproxy on instances whose role contains haproxy.

By default, haproxy listens on 127.0.0.1:5432 for requests forwarded by pgbouncer running on the same instance. You must specify a list of haproxy_backend_servers to forward requests to.

TPA will install the latest available version of haproxy by default. You can install a specific version instead by setting haproxy_package_version: 1.9.15* (for example).

Note: see limitations of using wildcards in package_version in tpaexec-configure.

You can set the following variables on any haproxy instance.

VariableDefault valueDescription
haproxy_bind_address127.0.0.1The address haproxy should bind to
haproxy_port5432The TCP port haproxy should listen on
haproxy_backend_serversNoneA list of Postgres instance names
haproxy_maxconnmax_connections×0.9The maximum number of connections allowed per backend server; the default is derived from the backend's max_connections setting

Server options

TPA will generate /etc/haproxy/haproxy.cfg with a backend that has a default-server line and one line per backend server. All but the first one will be marked as "backup" servers.

Set haproxy_default_server_extra_options to a list of options on the haproxy instance to add options to the default-server line; and set haproxy_server_options to a list of options on the backend server to add options (which will override the defaults) to the individual server lines for each backend.

Example

instances:
- Name: one
  vars:
    haproxy_server_options:
    - maxconn 33
- Name: two
…
- Name: proxy
  role:
  - haproxy
  vars:
    haproxy_backend_servers:
    - one
    - two
    haproxy_default_server_extra_options:
    - on-error mark-down
    - on-marked-down shutdown-sessions