Discovering Connection Strings v5

PGD CLI can be installed on any system which is able to connect to the PGD cluster. You will require a user with PGD superuser privileges - the bdr_superuser role - or equivalent (e.g. edb_admin on BigAnimal distributed high-availability) to use PGD CLI.

PGD CLI and database connection strings

You may not need a database connection string. For example, when Trusted Postgres Architect installs the PGD CLI on a system, it also configures the connection to the PGD cluster. This means that PGD CLI will automatically connect when run.

Getting your database connection string

Every deployment method has a different way of deriving a connection string for it. This is because of the range of different configurations that PGD supports. Generally, you can obtain the required information from the configuration of your deployment; this section provides a guide of how to assemble that information into connection strings.

For a TPA-deployed PGD cluster

Because TPA is so flexible, you will have to derive your connection string from your cluster configuration file (config.yml). You will need the name or IP address of a host with the role pgd-proxy listed for it. This host will have a proxy you can connect to. Usually the proxy will be listening on port 6432 (check the setting for default_pgd_proxy_options and listen_port in the config to confirm). The default database name is bdrdb (check the setting bdr_database in the config to confirm) and the default PGD superuser will be enterprisedb for EPAS and postgres for Postgres and Postgres Extended.

You can then assemble a connection string based on that information:

"host=<hostnameOrIPAddress> port=<portnumber> dbname=<databasename> user=<username> sslmode=require"

To illustrate this, here's some excerpts of a config.yml file for a cluster:

...
cluster_vars:
  ...
  bdr_database: bdrdb
  ...
  default_pgd_proxy_options:
    listen_port: 6432
  ...

instances:
- Name: kaboom
  backup: kapok
  location: dc1
  node: 1
  role:
  - bdr
  - pgd-proxy
  networks:
  - ipv4_address: 192.168.100.2
    name: tpanet
...

The connection string for this cluster would be:

"host=192.168.100.2 port=6432 dbname=bdrdb user=enterprisedb sslmode=require"
Host name versus IP address

In our example, we use the IP address because the configuration is from a Docker TPA install with no name resolution available. Generally, you should be able to use the host name as configured.

For a BigAnimal distributed high-availability cluster

  1. Log into the BigAnimal Clusters view.
  2. Select your cluster.
  3. In the view of your cluster, select the Connect tab.
  4. Copy the Read/Write URI from the connection info. This is your connection string.

For an EDB PGD for Kubernetes deployed cluster

As with TPA, EDB PGD for Kubernetes is very flexible and there is no one way to obtain a connection string. It depends, in large part, on how the Services have been configured for the deployment. If the Node Service Template is used, there should be direct connectivity to each node and proxy service available. If the Group Service Template, there will be a gateway service to each group. Finally, if the Proxy Service Template has been used, there should be a single proxy providing an entry point to the cluster for all applications. Consult your configuration file to determine this information. You should be able to establish a host name or IP address, port, database name (default: bdrdb) and username (enterprisedb for EPAS and postgres for Postgres and Postgres Extended.).

You can then assemble a connection string based on that information:

"host=<hostnameOrIPAddress> port=<portnumber> dbname=<databasename> user=<username>"

You may need to add sslmode=<sslmode> if the deployment's configuration requires it.