Connections
===========

PGD Essential uses the same connection methods as Postgres. The
difference is that most of your connections to the cluster go through
the connection manager that’s built into every data node in the cluster.

Although you can connect directly to the data nodes, we don’t recommend
it for anything other than maintenance when you want to work on a
particular node’s database instance.

For PGD Essential, you must connect to the cluster through the
connection manager. PGD Essential is designed to be simple to deploy and
manage, and that means the cluster has a write leader node that handles
all the writes to the cluster. The connection manager is then
responsible for directing your read-write connections to the write
leader. All your client or application needs to do is to use the
connection manager’s port and the connection manager will handle the
rest.

The connection manager is responsible for directing your writes to the
write leader and ensuring that your reads are directed to the correct
node in the cluster. If you connect directly to a data node, you may not
be able to take advantage of these features. For applications that only
need to read data, the connection manager can direct your reads to a
node that isn’t the write leader. This can help to balance the load on
the cluster and improve performance.

Connecting through the connection manager
-----------------------------------------

Postgres is very flexible for configuring ports and connections, so for
simplicity, this example uses the default port settings for Postgres and
the connection manager. The default port for Postgres is 5432, and the
default port for the connection manager is 6432.

You can use that port in your connection strings to connect to the
cluster. So, for example, if you’re using the psql command line tool,
you can connect to the cluster like this:

.. code:: bash

   psql -h host-1 -p 6432 -U pgdadmin -d pgddb

Where ``host-1`` is the hostname of the node you’re connecting to. The
connection manager will then direct your connection to the write leader
node in the cluster.

Connecting directly to a data node
----------------------------------

You can connect directly to a data node in the cluster, but we don’t
recommend it. However, if you need to connect directly to a data node,
you can use the following command:

.. code:: bash

   psql -h host-1 -p 5432 -U pgdadmin -d pgddb
