Connecting

There are two important things to know when connecting to a Crunchy Bridge cluster:

  1. Connection strings contain your hostname, username, password, and login details
  2. SSL is required

To provision a new cluster in Crunchy Bridge, see the Provision an instance section of the Getting Started guide.

Getting connection strings

Once you've created a cluster, you'll see it listed in the Team Dashboard. Click on the name to view the Cluster page.

In the Cluster page, you can find the Postgres instance credentials on the Connection tab. Select the role and format that work best for you, then you can copy the connection string.

About connection strings

For each individual cluster, Crunchy Bridge provides a connection string to use to connect directly via psql or to input into your application configuration. You can access the connection string for a cluster from the dashboard or via the CLI or API.

Info

A cluster's connection string will remain the same across cluster management operations unless you explicitly rotate the credentials.

The connection string as a database URL contains the following parameters:

  • protocol: postgres://
  • username: postgres, application, and user are supported out of the box
  • password
  • hostname: Cluster hostnames begin with p. and end with postgresbridge.com.
  • port: Defaults to 5432 unless you’re using connection pooling
  • database name: Defaults to postgres

Connection string formats

Crunchy Bridge provides connection details in five different formats, making it simple to connect to your cluster in a variety of different ways.

URL

Many modern frameworks like Ruby on Rails or Django will allow for an environment variable to be set for the DATABASE_URL. The connection string URL format is perfect for this use.

psql

Used in a terminal, psql will initiate an interactive session you can use to run queries against databases in your cluster:

psql postgres://postgres:JDcPwuav5S0MC6EsJ@p.vbjrfujv5beutlw725gvi3i.db.postgresbridge.com:5432/meteors

env

Use this format for environment variables for any libpq system:

PGHOST="p.vbjrfujv5beutaoelw725gvi3i.db.postgresbridge.com"
PGDATABASE="meteors"
PGUSER="postgres"
PGPASSWORD="JDcPwuav5SYe6NacDLpK9MbbyEoC6EsJ"

yaml

Use this format inside a yaml file:

host: "p.vbjrfujv5beutaoelw725gvi3i.db.postgresbridge.com"
database: "meteors"
username: "application"
password: "qNvJYuEDV2f7Oqtn7wtazQKvFtTpM4KJ0gZfvV09My4"

JDBC

If you're using Java, you may want to connect to your Crunchy Bridge cluster using a JDBC driver:

jdbc:postgresql://p.vbjrfujv5begvi3i.db.postgresbridge.com/meteors?user=postgres&password=JDcPwuav5SYe6NpK9MbbyEoC6EsJ&ssl=true

Note the &ssl=true parameter at the end of JDBC connection strings.

SSL

SSL is required to connect to a Crunchy Bridge cluster regardless of firewall settings. This is not currently configurable.

Note that only TLS v1.2 and v1.3 are supported, meaning older clients may not be able to connect despite enabling SSL.

Troubleshooting connection encryption

When connecting clients and applications to your cluster we recommend using SSLMODE=require. Some clients will default to SSLMODE=prefer, which allows the client to fall back an unencrypted connection if SSL connection fails. This will cause errors referring to no encryption since Crunchy Bridge clusters do not allow unencrypted connections.

If a client's encryption settings are misconfigured you may see errors like:

FATAL: no pg_hba.conf entry for host "x.x.x.x", user "postgres", database "postgres", SSL off

or

FATAL: no pg_hba.conf entry for host "x.x.x.x", user "postgres", database "postgres", no encryption

node.js

node-postgres requires some configuration in order to get TLS/SSL connections working. You can review the full documentation for connecting either with a certificate or a connection string at node-postgres.com.

The connector should be configured with a block similar to this one:

const sql = postgres(process.env.DATABASE_URL, {
  ssl: {
    require: true,
    rejectUnauthorized: false
  }
})

More tutorials for connecting applications and user interface tools

We've created a variety of tutorials to help you connect your Crunchy Bridge cluster to your applications and tools:

Reach out to support if you're having trouble connecting and don't see the tutorial you need. We're happy to help guide you.