Step 7 - Configure proxies v5
Configure proxies
PGD can use proxies to direct traffic to one of the cluster's nodes, selected automatically by the cluster. There are performance and availability reasons for using a proxy:
- Performance: By directing all traffic (in particular, write traffic) to one node, the node can resolve write conflicts locally and more efficiently.
- Availability: When a node is taken down for maintenance or goes offline for other reasons, the proxy can direct new traffic to a new write leader that it selects.
It's best practice to configure PGD Proxy for clusters to enable this behavior.
Configure the cluster for proxies
To set up a proxy, you need to first prepare the cluster and subgroup the proxies will be working with by:
- Logging in and setting the
enable_raft
andenable_proxy_routing
node group options totrue
for the subgroup. Usebdr.alter_node_group_option
, passing the subgroup name, option name, and new value as parameters. - Create as many uniquely named proxies as you plan to deploy using
bdr.create_proxy
and passing the new proxy name and the subgroup to attach it to. Thebdr.create_proxy
does not create a proxy, but creates a space for a proxy to register itself with the cluster. The space contains configuration values which can be modified later. Initially it is configured with default proxy options such as setting thelisten_address
to0.0.0.0
. - Configure proxy routes to each node by setting route_dsn for each node in the subgroup. The route_dsn is the connection string that the proxy should use to connect to that node. Use
bdr.alter_node_option
to set the route_dsn for each node in the subgroup. - Create a pgdproxy user on the cluster with a password or other authentication.
Configure each host as a proxy
Once the cluster is ready, you need to configure each host to run pgd-proxy:
- Create a pgdproxy local user.
- Create a
.pgpass
file for that user that allows the user to log into the cluster as pgdproxy. - Modify the systemd service file for pgdproxy to use the pgdproxy user.
- Create a proxy config file for the host that lists the connection strings for all the nodes in the subgroup, specifies the name for the proxy to use when fetching proxy options like
listen_address
andlisten_port
. - Install that file as
/etc/edb/pgd-proxy/pgd-proxy-config.yml
. - Restart the systemd service and check its status.
- Log in to the proxy and verify its operation.
Further detail on all these steps is included in the worked example.
Worked example
Preparing for proxies
For proxies to function, the dc1
subgroup must enable Raft and routing.
Log in to any node in the cluster, using psql to connect to the bdrdb
database as the enterprisedb user. Execute:
SELECT bdr.alter_node_group_option('dc1', 'enable_raft', 'true'); SELECT bdr.alter_node_group_option('dc1', 'enable_proxy_routing', 'true');
You can use the bdr.node_group_summary
view to check the status of options previously set with bdr.alter_node_group_option()
: