PGD Proxy configuration
=======================

Group-level configuration
-------------------------

Configuring the routing is done through either SQL interfaces or through
PGD CLI.

You can enable routing decisions by calling the :ref:`bdr.alter_node_group_option() <Node management>`  function.
For example:

.. code:: text

   SELECT bdr.alter_node_group_option(region1-group, enable_proxy_routing, true)

You can disable it by setting the same option to ``false`` .

Additional group-level options affect the routing decisions:

-  ``route_writer_max_lag`` — Maximum lag in bytes of the new write
   candidate to be selected as write leader. If no candidate passes
   this, no writer is selected automatically.

-  ``route_reader_max_lag`` — Maximum lag in bytes for a node to be
   considered a viable read-only node (PGD 5.5.0 and later).

Node-level configuration
------------------------

Set per-node configuration of routing using :ref:`bdr.alter_node_option() <Node management>`  . The
available options that affect routing are:

-  ``route_dsn`` — The dsn used by proxy to connect to this node.

-  ``route_priority`` — Relative routing priority of the node against
   other nodes in the same node group. Used only when electing a write
   Leader.

-  ``route_fence`` — Determines whether the node is fenced from routing.
   When fenced, the node can’t receive connections from PGD Proxy. It
   therefore can’t become the write Leader or be available in the
   read-only node pool.

-  ``route_writes`` — Determines whether writes can be routed to this
   node, that is, whether the node can become write leader.

-  ``route_reads`` — Determines whether read-only connections can be
   routed to this node (PGD 5.5.0 and later).

Proxy-level configuration
-------------------------

You can configure the proxies using SQL interfaces.

Creating and dropping proxy configurations
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

You can add a proxy configuration using :ref:`bdr.create_proxy <bdr.create_proxy>`  . For example,
``SELECT bdr.create_proxy('region1-proxy1', 'region1-group');`` creates
the default configuration for a proxy named ``region1-proxy1`` in the
PGD group ``region1-group`` .

The name of the proxy given here must be same as the name given in the
proxy configuration file.

You can remove a proxy configuration using
``SELECT bdr.drop_proxy('region1-proxy1')`` . Dropping a proxy
deactivates it.

Altering proxy configurations
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

You can configure options for each proxy using the :ref:`bdr.alter_proxy_option() <EDB Postgres Distributed Proxy overview>` 
function.

The available options are:

-  ``listen_address`` — Address for the proxy to listen on.

-  ``listen_port`` — Port for the proxy to listen on.

-  ``max_client_conn`` — Maximum number of connections for the proxy to
   accept.

-  ``max_server_conn`` — Maximum number of connections the proxy can
   make to the Postgres node.

-  ``server_conn_timeout`` — Connection timeout for server connections.

-  ``server_conn_keepalive`` — Keepalive interval for server
   connections.

-  ``consensus_grace_period`` — Duration for which proxy continues to
   route even upon loss of a Raft leader. If set to ``0s`` , proxy stops
   routing immediately.

-  ``read_listen_address`` — Address for the read-only proxy to listen
   on.

-  ``read_listen_port`` — Port for the read-only proxy to listen on.

-  ``read_max_client_conn`` — Maximum number of connections for the
   read-only proxy to accept.

-  ``read_max_server_conn`` — Maximum number of connections the
   read-only proxy can make to the Postgres node.

-  ``read_server_conn_keepalive`` — Keepalive interval for read-only
   server connections.

-  ``read_server_conn_timeout`` — Connection timeout for read-only
   server connections.

-  ``read_consensus_grace_period`` — Duration for which read-only proxy
   continues to route even upon loss of a Raft leader.
