Connection strings
The shape of a Balta connection string, what each parameter does, the form each client uses to verify the certificate as well, and where to keep the password.
A Balta connection string is an ordinary PostgreSQL connection string. The default one encrypts
the connection with sslmode=require and works with every client we have run, as given. Checking
the certificate as well is a stronger form, and what it takes differs by client.
This page is the reference for each part. Connect is the short path.
The shape
postgresql://ROLE:PASSWORD@HOST/DATABASE?sslmode=require| Part | What it is |
|---|---|
ROLE | A PostgreSQL role in your service. Not a Balta account |
PASSWORD | That role's password. Keep it out of the URL in production, see below |
HOST | Your service endpoint. The name ending in -pooler is pooled, the name without it is direct. Stable, and unchanged if we move the service to another host |
DATABASE | A logical database inside your service. New services are created with appdb |
sslmode | require encrypts the connection. verify-full also checks the certificate and the hostname, see below |
There is no port. Both endpoints use 5432, the standard PostgreSQL port, which every client assumes when the string names none.
There is no file to download and no path to fill in, whichever mode you use. Your endpoint presents a certificate issued by a public authority.
Verifying the certificate, per client
sslmode=require encrypts the connection and does not check who answered. To check that as well,
turn on Verify the certificate on your language's tab in the Connect page. These are the forms it
gives:
| Client | The verified form | Roots it checks against |
|---|---|---|
psql, libpq 16 and newer | sslmode=verify-full&sslrootcert=system | Those of the TLS library libpq was built with |
| Python, psycopg | sslmode="verify-full", sslrootcert=certifi.where() | Mozilla's, from the certifi package |
Node, pg | sslmode=verify-full | Node's |
Go, pgx | sslmode=verify-full | Go's system roots |
Java, pgjdbc | sslmode=verify-full&sslfactory=org.postgresql.ssl.DefaultJavaSSLFactory | The JVM's cacerts |
We test each form three ways against a Balta database: it must connect, refuse a certificate from an authority the client does not trust, and refuse a trusted certificate issued for another name. Copy the form as given: a line that connects has not necessarily checked anything.
libpq needs 16 or newer for system. libpq 14 and 15 read system as a file name and refuse to
connect, with root certificate file "system" does not exist. They fail closed: nothing connects
unchecked.
Python takes its roots from certifi. The psycopg binary package carries its own TLS library,
which looks for roots in a directory that exists only on the machine that built it, so system
finds none. certifi is Mozilla's root list as a package: pip install certifi.
Node and Go need nothing beside the mode. node-postgres and pgx send the hostname and check the
certificate for it with verify-full alone. node-postgres reads sslrootcert as a file path, and
pgx before 5.7 does too, so the forms leave it out.
Java needs the factory as well as the mode. pgjdbc's default SSL factory imitates libpq: it
looks for a root certificate at ~/.postgresql/root.crt and throws a FileNotFoundException
naming that path when the file is not there. sslfactory=org.postgresql.ssl.DefaultJavaSSLFactory
hands verification to the JVM truststore, which already carries the public roots.
Ruby's pg gem and the URI have no verified form here. The URI is read by many drivers that
disagree about sslrootcert, and for the pg gem we found no form that verifies on every system
without naming a file on your computer. Both keep sslmode=require.
Why the Node example adds uselibpqcompat=true. node-postgres 8 reads sslmode=require as
verify-full and prints a warning that this will change in its next major version.
uselibpqcompat=true gives require its standard PostgreSQL meaning, so the line behaves the same
before and after that change, without the warning.
Both endpoints, one port
Balta uses the standard PostgreSQL port, 5432, and every connection is encrypted. Your client must send the server name during the TLS handshake, which libpq 14 and newer and every current driver do. To also verify the certificate, turn on “Verify the certificate” on your language’s tab in the Connect page.
If your connection is refused, the error says why: an address not on the allowlist, a database that is temporarily unavailable, or a client that did not send the server name.
The pooled and direct endpoints are told apart by hostname: the name ending in -pooler is
pooled, the same name without it is direct. Balta reads the name your client sends and routes
the connection to your pooler or to PostgreSQL from it. Switching a consumer from one to the other
is a hostname change, and nothing else in the string moves.
Both names are your service's own, are on the Connect tab, and do not change for the life of the service, including when we move it to another host. A firewall that allows outbound PostgreSQL on 5432 allows Balta.
The examples on this page use db-example-pooler.fsn1.baltadb.net, the pooled name. Drop
-pooler and the same string reaches the direct endpoint. Yours are on the Connect tab.
Keep the password out of the URL
A password in a connection string ends up in process listings, shell history, container inspect output and log lines. Supply it separately.
export PGPASSWORD=<password>
psql "postgresql://[email protected]/appdb?sslmode=require"Every credential in this documentation is the literal string <password>. If you find
something in our docs, dashboard or fixtures that looks like a real password, it is a defect and we
want to hear about it.
Escaping
Some characters are special in a URL: @, :, /, ?, #, %. If a role name or password
contains one, percent-encode it, or use the key-value form instead:
host=db-example-pooler.fsn1.baltadb.net dbname=appdb user=app_writer sslmode=requireThe key-value form has no escaping rules to get wrong, which is a good reason to prefer it in configuration files.
Two parameters worth adding
connect_timeout— without it a client can hang for the operating system's TCP timeout, which is much longer than you want.application_name— it appears inpg_stat_activity, and it is the difference between "some backend" and "the reporting job".
What you will see
\conninfo in psql reports the database, the user, the host and whether TLS was negotiated. It is
the quickest way to confirm which endpoint you reached. On PostgreSQL 18 it prints a table:
Connection Information
Parameter | Value
----------------------+----------------
Database | appdb
Client User | app_writer
Host | db-example-pooler.fsn1.baltadb.net
Server Port | 5432
SSL Connection | true
Superuser | offHost tells you which endpoint you are on, and SSL Connection must read true. On
PostgreSQL 16 and 17 the same command prints a sentence instead of a table.
Troubleshooting
invalid connection option. A parameter name is misspelled, or a URL query parameter was used
where the key-value form was intended. The two forms take the same names and different separators.
root certificate file "system" does not exist. The libpq your client is linked against is
older than 16, and it read the verified form's system as a file name. Use libpq 16 or newer for
that form. The default line, sslmode=require, works on libpq 14 and newer.
A password with a @ in it fails to parse. Percent-encode it, or move the password out of the
URL entirely.
The connection reaches the wrong endpoint. Check the hostname. The pooled one ends in
-pooler; the port is 5432 for both.
Your client did not send the server name. Balta needs the hostname your client sends during
TLS to find your database. Upgrade to libpq 14 or newer, remove sslsni=0 if it is set, and connect
by name rather than by IP address.