Connect to a database
Connect over TLS with the connection strings on the Connection tab, and verify the server with the platform's CA bundle.
Replace orders_admin and orders with your master user and database, and ewdb-0123456789ab with your database's id.
Prerequisites
- Permission for
rds:DescribeDBInstances(also what downloading the CA bundle needs). - The password: see Manage the master password, or Create a login for a person of their own.
- A client that can reach the endpoint: from the database's network, or from anywhere if the database is public (see Instances, clusters and endpoints).
Get the connection strings
- Open the database, then choose Connection.
- Copy Application (pooled, port 6432), Direct (port 5432), or, on a cluster, Read replicas (pooled).
dcloud rds instances get ewdb-0123456789abThe endpoint address and port are in the output.
GET /rds/api/instances/ewdb-0123456789abNot available in Terraform. A connection is not a resource; `dcloud_db_instance` exports `endpoint_address`, `endpoint_port` and `private_endpoint_address`.
Substitute the password:
postgresql://orders_admin:<password>@192.0.2.7:6432/orders?sslmode=require # applications
postgresql://orders_admin:<password>@192.0.2.7:5432/orders?sslmode=require # direct
postgresql://orders_admin:<password>@192.0.2.7:6433/orders?sslmode=require # read replicas, cluster onlyThe console's strings use the host to connect to: the endpoint's DNS name once the database's certificate carries it, otherwise its address; for a private database, its address or name inside the network.
sslmode=require encrypts the connection. To also verify that you are talking to your database,
use verify-full. Node.js is different: node-postgres treats require as verify-full, so a
Node app needs the CA bundle even with require; see From Node.js.
Choose the port
The pooler on 6432 runs PgBouncer in transaction mode: a server connection belongs to a client
only for one transaction, then serves another client. Anything that lives longer than a
transaction does not survive there.
| What connects | Port |
|---|---|
| Request handling in a web app or API | 6432 (pooled) |
| Job queues that lock rows or jobs (pg-boss, Graphile Worker, Oban) | 5432 (direct) |
Migrations, pg_dump, pg_restore, psql sessions |
5432 (direct) |
Advisory locks, LISTEN/NOTIFY, SET outside a transaction, temporary tables |
5432 (direct) |
| Reads that may lag the primary, on a cluster | 6433 (replicas, pooled) |
An app with both kinds of code uses two strings, for example DATABASE_URL on 5432 for its
worker and migrations, and DATABASE_URL_POOLED on 6432 for its web process.
Timeouts on the pooled port. A client may send statement_timeout, lock_timeout or
idle_in_transaction_session_timeout when it connects (node-postgres does when you set those
options). On 6432 the pooler accepts the connection but does not apply these values: the
role's or the database's own setting applies. Set the timeout there, once:
ALTER ROLE orders_app SET statement_timeout = '30s';It applies to every new server connection of that role, pooled or direct. For the whole database
or every role, use Tune parameters. On 5432 the client's own values apply
as usual. Any other unknown startup parameter, search_path included, is refused with
unsupported startup parameter; set it with ALTER ROLE … SET too.
Connect with verify-full
- On the database's Connection tab, choose Download CA bundle.
- Copy Application with certificate check (port 6432) and replace
<path-to-…>with where you saved the bundle.
dcloud rds exec downloads the CA and runs your command with it:
dcloud rds exec -- node migrate.js
dcloud rds exec -- psql "postgresql://orders_admin:<password>@<id>.db.apps.<root-domain>:6432/orders?sslmode=verify-full"It caches the CA as ~/.dcloud/rds-ca.pem, fetches it again after 30 days or with --refresh
(a stale copy is used if the download fails), and runs your command with NODE_EXTRA_CA_CERTS and
PGSSLROOTCERT pointing at it. node-postgres then stops failing with
SELF_SIGNED_CERT_IN_CHAIN, and libpq tools can use verify-full. The command's exit code is
passed through.
GET /rds/api/ca-bundleIt downloads as dcloud-rds-ca-bundle.pem. Then:
postgresql://orders_admin:<password>@192.0.2.7:6432/orders?sslmode=verify-full&sslrootcert=/path/to/dcloud-rds-ca-bundle.pemNot available in Terraform. A connection is not a resource.
The CA bundle is the same file for every database in the installation. The certificate names the
endpoint address and the endpoint's DNS names (<id>.db.apps.<root-domain> for the public
endpoint, <id>.private.db.apps.<root-domain> for the private one); verify-full succeeds against
any of them. Without sslrootcert, verify-full and verify-ca fail.
From an app deployed on Deutsche Cloud, no download is needed: every container has the CA at
/etc/ews/ca/platform-ca.pem, and Node trusts it already (see
Bind a managed database in the Apps User Guide). Use that path
as sslrootcert.
From Node.js
node-postgres treats sslmode=require as verify-full. Until it trusts the platform's CA, every
query fails with self-signed certificate in certificate chain (SELF_SIGNED_CERT_IN_CHAIN).
Download the CA bundle: Download CA bundle on the Connection tab, or
dcloud rds ca-bundle download > dcloud-rds-ca.crt. It is a public certificate, safe to commit.Point
NODE_EXTRA_CA_CERTSat it in every process that connects: the web process, the worker, migrations and one-off scripts. In a container image:COPY dcloud-rds-ca.crt /etc/ssl/certs/dcloud-rds-ca.crt ENV NODE_EXTRA_CA_CERTS=/etc/ssl/certs/dcloud-rds-ca.crtOn your computer,
dcloud rds exec -- <command>does this for one command.Connect by name (
<id>.db.apps.<root-domain>, as the console shows), not by address: node-postgres cannot verify a certificate for an IP host. A database created before the names existed is shown with its address until its certificate is next renewed.
Keep sslmode=require in the string; node-postgres then verifies the server against the bundle.
Do not use rejectUnauthorized: false: it turns verification off for the connection.
TLS reference
| Where TLS is served | every port, direct and pooled |
| Certificate subject | the database id |
| Certificate names | the endpoint address, as an IP, and the endpoint DNS names |
| Issuer | Deutsche Cloud Managed Databases CA (an older installation's CA keeps the name it was made with), one per installation, valid ten years |
| Certificate validity | two years from creation |
| Renewal | automatic, from the machine, once the certificate is inside its last 30 days; connections are not interrupted |
| Expiry warning | written to Activity from 30 days out, once a day; as an error inside 7 days |
| CA bundle | GET /rds/api/ca-bundle → dcloud-rds-ca-bundle.pem |
| Shown on the database page | the certificate's expiry and serial |
sslmode values, as libpq treats them against this database:
sslmode |
Encrypted | Verifies the server | Needs sslrootcert |
|---|---|---|---|
disable |
no | no | no |
allow, prefer |
yes | no | no |
require |
yes | no | no |
verify-ca |
yes | issuer only | yes |
verify-full |
yes | issuer and address | yes |
With Require TLS on (the default for new databases), a client that does not ask for TLS is
refused: no pg_hba.conf entry … no encryption on 5432, SSL required on 6432. With it off, it
gets a plaintext connection. See Require TLS.
Result
SELECT version(); answers. With verify-full, the client has checked that the certificate was
issued by the platform's CA for the address or name you connected to.