Connection Manager overview
===========================

About Connection Manager
------------------------

Connection Manager is a new background worker for EDB Postgres
Distributed (PGD) 6.0 that simplifies the process of connection to PGD
clusters by providing a single point of entry for client applications.
It replaces the PGD 5.x proxy solution with a tightly integrated
approach that exposes read-write, read-only, and HTTP status network
interfaces in PGD.

Connection Manager is fully integrated into PGD and is designed to work
seamlessly with the existing PGD architecture. Every PGD data node has a
Connection Manager instance that listens for incoming connections and
routes them to the appropriate node in the cluster, specifically the
current write leader in the cluster. It also provides a read-only
interface for applications that only need to read data from the cluster.

Starting in PGD 6.3.0, Connection Manager starts by default on
subscriber-only nodes, ensuring that even nodes dedicated primarily to
receiving replicated data have access to advanced connection pooling and
session management features.

Connection Manager consolidates three capabilities that previously
required separate tools. It routes writes to the current leader,
distributes read traffic across nodes, and pools backend connections.
Because it runs inside PGD, authentication is configured once in
``pg_hba.conf`` and applies to both the proxy layer and the database,
with no separate user list to maintain.

Starting in PGD 6.5, Connection Manager runs on a multi-threaded engine
instead of a single thread. Client traffic, pooling, and authentication
are handled across multiple threads, so connection capacity scales with
the number of CPU cores available to the node. Configuration and routing
updates are processed on a separate thread, off the traffic path, so
they don’t add latency to client connections. The number of worker
threads is controlled by :ref:`bdr.conn_mgr_worker_threads <bdr.conn_mgr_worker_threads>`  , which defaults to sizing itself
automatically as the number of CPU cores divided by 4, clamped between 2
and 8.

Using Connection Manager
------------------------

Connection Manager follows the Postgres server’s configuration by
default. There are three ports, the read-write port, the read-only port,
and the HTTP port. The read-write port is used for write operations,
while the read-only port is used for read operations. The HTTP port is
used for monitoring and management purposes.

The read-write port is, by default, set to the Postgres port + 1000
(usually 6432). The read-only port is set to the Postgres port + 1001
(usually 6433). The HTTP port is set to the Postgres port + 1002
(usually 6434).

To use Connection Manager, configure your client applications to connect
to its read-write or read-only port on the data node. Connection Manager
routes the connection to the appropriate node in the cluster.

Connecting to the read-only port restricts the connection to read-only
operations, similar to 
`SET TRANSACTION READ ONLY <https://www.postgresql.org/docs/current/sql-set-transaction.html>`_  , except that it’s not possible to
change it to read-write. The 
`transaction_read_only <https://www.postgresql.org/docs/17/runtime-config-client.html#GUC-TRANSACTION-READ-ONLY>`_  configuration parameter
correctly reports ``on`` in these connections.

Authentication
--------------

Connection Manager performs TLS termination and pre-authentication using
the same ``pg_hba.conf`` configuration as Postgres, with no separate
user list to maintain. See :ref:`Connection Manager Authentication <Connection Manager Authentication>`  for supported methods and
constraints.

Connection pooling
------------------

Connection Manager includes built-in connection pooling, removing the
need for a separate pooler such as pgBouncer in most deployments.
Pooling reduces the number of backend Postgres connections by sharing
them across many client connections, lowering memory and process
overhead on the database server. See :ref:`Connection pooling <Connection pooling>`  for reference
details, :ref:`Configuring connection pooling <Configuring connection pooling>`  for DBA setup guidance, and :ref:`Using connection pooling in your application <Using connection pooling in your application>`  for
developer guidance.

Load balancing
--------------

Connection Manager isn’t a replacement for a load balancer. Use an
external load balancer to distribute client traffic across Connection
Manager instances running on different nodes. See :ref:`Load Balancing with Connection Manager <Load Balancing with Connection Manager>`  for
configuration details and HAProxy examples.

Configuration
-------------

Connection Manager is configured through PGD group options, including
ports, connection limits, consensus timeouts, and pool mode. See
:ref:`Configuring Connection Manager <Configuring Connection Manager>`  for the full option reference.

Monitoring
----------

Connection Manager exposes connection counts and pool utilization
through catalog views and HTTP endpoints. See :ref:`Monitoring the Connection Manager <Monitoring the Connection Manager>`  for
available metrics.
