EDB Postgres Distributed Proxy v5

EDB Postgres Distributed Proxy is a daemon that acts as an abstraction layer between the client application and Postgres. It interfaces with the BDR consensus mechanism to obtain the identity of the current write leader node and redirects traffic to that node.

There is always at least one global group and one data group in the PGD cluster. BDR elects the write leader for each data group which has the enable_proxy_routing and enable_raft options set to true. Proxy can be attached to a global group or data group. There could be multiple proxies attached to each group.

PGD Proxy is a TCP layer 4 proxy.

How it works ?

Upon starting, PGD Proxy connects to one of the endpoints given in the local config file and fetches DB connection information for all nodes, proxy options like listen address, listen port, routing details like current write leader, etc. Endpoints given in config file are only used at the time of startup, after that actual endpoints are taken from bdr catalog bdr.node_routing_config_summary#route_dsn.

The write leader election is managed by BDR itself. Proxy internally interacts with BDR to get write leader change events notifications on Postgres notify/listen channels and routes client traffic to current write leader. Proxy disconnects all client connections on write leader change. Write leader election is a Raft backed activity and is subject to Raft leader availability.

PGD Proxy responds to write leader change events that can be categorized into two modes of operation viz., Failover and Switchover.

Automatic transfer of write leadership from current write leader node to new node in the event of but not limited to Postgres or Operating system crash is termed as Failover. BDR automatically elects a new write leader when the current write leader goes down or becomes unresponsive. Once the new write leader is elected by BDR, proxy will close existing client connections (which were to the old write leader) and redirect new client connections to newly elected write leader.

User controlled, manual transfer of write leadership from the current write leader to a new target leader is termed as Switchover. Switchover is triggered through the PGD CLI switchover command. The command is submitted to BDR which attempts to elect the given target node as new write leader. Similar to failover, proxy will close existing client connections and redirect new client connections to the newly elected write leader. This is useful at the time of server maintenance, e.g. if the current write leader node needs to be stopped for maintenance like a server update, OS patch update etc.

Managing PGD Proxy

PGD CLI provides a few commands to manage proxies in PGD cluster such as create-proxy, delete-proxy, set-proxy-options and show-proxies. See PGD CLI for more information.

See Connection management for more information on BDR side of configuration and management of PGD Proxy.

Proxy log location

syslog

  • Debian based - /var/log/syslog
  • Red Hat based - /var/log/messages

Use journalctl command to filter and view logs for troubleshooting Proxy. Below are few sample commands for quick reference.

journalctl -u pgd-proxy -n100 -f
journalctl -u pgd-proxy --since today
journalctl -u pgd-proxy --since "10 min ago"
journalctl -u pgd-proxy --since "2022-10-20 16:21:50" --until "2022-10-20 16:21:55"