Configuring TLS for PostgreSQL connections

A practical guide to encrypting PostgreSQL client, replication and pooler traffic, with the decisions, build sequence and checks that make the setup verifiable in your environment.

On this page

Configuring TLS for PostgreSQL connections: what it protects and when you need it

TLS configuration encrypts traffic on the links between PostgreSQL and the parties that reach it: client connections, streaming replicas and connection poolers such as PgBouncer. It does not encrypt data stored on disk, data in backups, or individual columns, and it does not stop an authorized user from reading data they are allowed to query. Those are separate controls. You need TLS on a link whenever that link crosses a network your team does not fully control, including a shared data center VLAN, a cloud subnet another team administers, a VPN, or a path through a load balancer. A cluster that only accepts connections from a single application host on a locked-down segment still benefits from TLS, but the risk of skipping it is lower and easier to document.

Three things must be true before the link is actually protected. First, the server must be set up to offer TLS, which means a server certificate and private key are installed and the ssl parameter is turned on in postgresql.conf. Second, pg_hba.conf must require it: a host line will accept unencrypted connections, so sensitive databases and roles need hostssl entries, and any remaining host lines for those databases are a gap to find. Third, clients must verify the server rather than trust whatever certificate arrives. Clients that use the default sslmode may encrypt without confirming who they are talking to, which leaves room for interception. The decision for each link is therefore whether the client, replica or pooler checks the server certificate against a trusted CA and the expected host name.

Keep the supported versions in view while you plan. PostgreSQL 14 to 18 are the versions this guidance covers, and the PostgreSQL versioning policy lists 14 as supported until November 12, 2026, so an older cluster may need an upgrade before its TLS design is worth finalizing. Confirm the TLS library and minimum protocol settings your chosen version and distribution support, and check the PostgreSQL authentication methods documentation for the methods that rely on TLS, such as certificate authentication. PostgreSQL is released under the PostgreSQL License, a permissive license, so you own the configuration and the operational burden of keeping certificates valid and trusted.

Which TLS settings fit which connection path

This table compares the TLS choices for each connection path, from application clients and admins to replicas and poolers. Read each row for when the setting fits and what it still leaves unverified, because encryption alone does not prove who is on the other end. Confirm accepted protocol values and sslmode behavior against your PostgreSQL and client library versions.

Connection pathTypical settingWhen it fitsWhat it leaves unverified
Application clients on a private networkhostssl with sslmode=requireTraffic is encrypted but the team has no internal CA yet and the risk is passive eavesdroppingThe client does not check the server certificate, so a spoofed server can accept the connection
Application clients with a trusted internal CAhostssl with sslmode=verify-fullServices connect by a stable DNS name and the team can distribute the CA certificate to each serviceCertificate rotation and hostname changes can break clients if they are not tracked
Clients using verify-casslmode=verify-caThe chain is checked but the team does not control DNS names for the serverThe server hostname is not checked, so a valid certificate for another host may be accepted
Admin and maintenance sessionshostssl with verify-full and separate admin rulesAdministrators connect from managed workstations and need the strictest name and chain checksWorkstations with stale CA bundles or copied key files remain a risk unless access is restricted
Streaming replication linkshostssl in pg_hba.conf for replication with the standby's sslmode set to verify-full or verify-caStandbys and base backup hosts run on known addresses and the replication user is separate from applicationsA standby can connect with a valid certificate that was issued for a different role or host unless names are checked
Connection poolers such as PgBouncerClient to pooler over TLS and pooler to server over TLS, each with its own verificationThe pooler sits between applications and the database and both legs need encryptionEncryption on the client leg does not cover the pooler to server leg, so verify both hops separately
Server certificate from an internal CAPrivate root or intermediate that the team operatesServices are internal, the team controls issuance and can publish the chain to every clientRevocation, expiry tracking and key custody depend on the team's own processes
Server certificate from a public CACertificate issued by a publicly trusted authorityClients outside the organization or many unmanaged clients trust the chain by defaultThe public CA does not confirm your internal hostnames are used correctly, and internal names may not be publicly issuable
Protocol floor set by ssl_min_protocol_versionMinimum version set on the server, then verified in each client libraryOlder clients are either upgraded or consciously excluded from the databaseThe accepted values depend on your PostgreSQL version, so confirm them in the documentation for that release

How TLS differs for applications, admins, replicas and poolers

Application clients connect directly to the PostgreSQL server, or to a pooler in front of it, and TLS ends at the server or pooler listener. The part teams most often get wrong is verification: encryption without verification protects against passive observers but not against a server impersonated on the network. Application clients should verify the server certificate against your internal certificate authority and check the host name. Each application needs its own trust bundle and connection string, and the database driver must be configured to fail closed rather than fall back to an unencrypted connection.

  • Verification mode: Set the client sslmode to verify-full so the driver checks both the certificate chain and the host name.
  • Trust anchor: Ship the internal CA certificate to each application host or container image, and confirm the driver reads it from the path you configured.
  • Server hostname: Use a name in the certificate's subject alternative names that the application actually connects to, including any load balancer name.
  • Driver behavior: Confirm that the driver does not silently downgrade when TLS negotiation fails, and test that a connection with a wrong CA is refused.
  • Minimum protocol: Align the client minimum version with the server's ssl_min_protocol_version so a stale runtime cannot negotiate weak settings.

Before release, check every application connection string in your deployment repositories for sslmode=disable, prefer or require without a root certificate, since those settings encrypt without authenticating the server.

Setting up TLS on a PostgreSQL cluster step by step

This sequence takes a self-hosted PostgreSQL cluster from plaintext connections to encrypted client and replication traffic, with a check at each stage so you can confirm the server, the rules and the clients behave as intended before you rely on them.

  1. Issue and place server certificates correctly

    Your PKI or security team issues a server certificate and private key whose subject alternative names match the exact host names clients will use, including any load balancer or pooler name. The private key file must be readable only by the operating system account that runs PostgreSQL, and the certificate chain should include any intermediate CA. Confirm the names with openssl x509 on the certificate and confirm the key file permissions on the server before you continue. Done means the certificate lists every name clients will verify and the key is not readable by other users.

  2. Set the ssl parameters and file paths

    In postgresql.conf, set ssl to on, then point ssl_cert_file and ssl_key_file at the certificate and key, and ssl_ca_file at the CA bundle if you verify client certificates later. Set ssl_min_protocol_version to the lowest TLS version your clients support, and confirm the value against the PostgreSQL configuration reference for your release. Changing ssl usually needs a full restart, not a reload, so schedule the change. Check the result with SHOW ssl; it should return on, and the server log should show no errors about loading the certificate or key.

  3. Set the minimum TLS protocol version

    Set ssl_min_protocol_version in postgresql.conf to a protocol version that your security baseline and every client library accept, and record the choice in your configuration standard. Older TLS versions should not be permitted, so confirm with your security team which version they require and test a client that only offers the lower version. After the restart, run SHOW ssl_min_protocol_version to confirm the active setting. Done means the setting shows the value you chose and a client limited to an older version is refused.

  4. Require hostssl for remote addresses

    Edit pg_hba.conf so every remote connection uses hostssl, and remove or comment out plain host entries for non-local addresses. Keep local socket entries separate, and keep replication entries on hostssl as well. Rule order matters because PostgreSQL uses the first matching line, so place specific hostssl rules above broader ones. Reload with SELECT pg_reload_conf() or pg_ctl reload, then confirm with SELECT * FROM pg_hba_file_rules() that no remote host entry remains without ssl.

  5. Configure replication entries over TLS

    Add a hostssl line in pg_hba.conf for the replication pseudo-database for each standby address, using the replication role and an authentication method your design already uses. Standbys must also be configured to connect with sslmode set in primary_conninfo, so the replication connection is encrypted and verified. Replication setup itself depends on the steps in the high availability documentation, so follow that guidance for slot, role and standby creation first. Verify by checking pg_stat_replication on the primary and confirming ssl is true for each standby.

  6. Set client sslmode and root certificate

    On each application or admin client, set sslmode to verify-full and point sslrootcert at the CA that signed the server certificate. Use the host name in the connection string that appears in the certificate subject alternative names, because verify-full checks the name as well as the chain. Ask each application team to confirm their driver version supports these options. Done means a client connects with the expected name and the connection fails when the CA file is wrong or the host name does not match.

  7. Reload and verify encrypted connections

    Reload the configuration and confirm that the server accepts encrypted connections. Connect a client with verify-full and run SELECT * FROM pg_stat_ssl WHERE ssl; to see the encrypted sessions, including the protocol version and cipher. Then attempt a plaintext connection from a remote address by setting sslmode to disable, and confirm the server rejects it with a no pg_hba.conf entry error. Record these results with the date and the pg_hba.conf version so auditors and reviewers can see the evidence.

How the certificate chain and connection paths fit together

The diagram starts with the internal CA, which issues the server certificate to the PostgreSQL primary and the client certificates to the application and the standby. The application connects through a PgBouncer pooler, and the pooler opens its own TLS session to the primary, so encryption and verification must be checked on both hops, not only at the application. The streaming standby also connects to the primary over TLS using its own certificate. Check that each client verifies the server name against the issued certificate, and that the pooler is trusted as a client on the backend side.

Certificate issuance and the encrypted hops from client through pooler to primary and standby.

Security risks that remain even after TLS is switched on

Turning on TLS does not by itself make a PostgreSQL connection trustworthy. The risks below sit around the encryption: which connections are allowed to skip it, what the client actually verifies, who can read the private key, which certificates are trusted, and where traffic is decrypted and re-sent. Each one can leave a deployment that looks encrypted while still exposing data or accepting the wrong server.

Plaintext fallback through host rules

A host line in pg_hba.conf matches connections whether or not they use TLS, so a broader rule added earlier can let a client connect in plaintext even when a hostssl rule exists for the same network. Review the full rule order, not just the TLS rules, and confirm that every address range that reaches the server is matched by a hostssl entry or is rejected. Test from each client network with TLS disabled to see which rule answers.

Authentication methods docs

sslmode=require is not identity verification

With sslmode=require, the client encrypts the session but does not check that the server certificate was issued by a trusted authority or matches the host name. Anyone who can redirect the connection can present their own certificate and still receive the password or query traffic. For services that must confirm the server, set sslmode=verify-full and point sslrootcert at your internal CA. Check the connection string in every application, driver and deployment script, since defaults differ between tools.

Private key file permissions

The server private key must be readable only by the operating system account that runs PostgreSQL, and PostgreSQL refuses to start if the key file is readable by other users. Problems appear when keys are copied into shared configuration directories, container images or backup archives with loose modes. Check the owner and mode of the key file on every node, including standbys and any replaced host, and check that copies of the key in backups or configuration management are protected to the same standard.

Certificates trusted through a broad root store

If the client trusts a public or system-wide root store instead of a single internal CA, any certificate issued by any trusted authority can pass verification for your database host name. This matters most for verify-full clients, where the check is only as narrow as the trust anchor. Point sslrootcert at the internal CA file used for PostgreSQL, confirm the server certificate's subject alternative names match the names clients use, and review which CA certificates are installed on application hosts.

Poolers that terminate TLS and forward plaintext

A connection pooler such as PgBouncer can accept TLS from clients and then open a separate connection to PostgreSQL, and that second leg may be unencrypted unless it is configured with its own TLS settings. The client sees a secure session while the traffic between the pooler and the database crosses the network in the clear. Check the pooler's server-side TLS settings and the matching pg_hba.conf rule for the pooler's address, and test the pooler path separately from the direct path with the same verification mode.

PgBouncer site

Logs that expose connection details

Connection logging can record user names, client addresses, database names, application names and, in some setups, error text that includes connection parameters. Logs also tend to be copied to shared log platforms with wider access than the database. Review log_connections and log_disconnections settings, check what application name and client fields are sent, and confirm that log storage, retention and access follow the same controls as the database. Look for certificate or key paths and passwords in deployment logs as well as server logs.

Rotating server and client certificates without outages

Certificate rotation is an operational task that starts with the expiry date, not the day the certificate is replaced. Every server certificate and client certificate has a validity window, and when it closes, connections fail at the TLS handshake with no warning inside PostgreSQL itself. Plan rotation as a recurring change with an owner, a calendar entry well before expiry, and a record of which certificate each server, standby, pooler and client uses. Confirm in the PostgreSQL documentation for your exact major version which settings reload with pg_reload_conf() and which need a restart, because the server certificate and key paths, the CA file and the CRL behavior may differ in how they take effect. Do not assume a reload picked up new material until you have checked the server log and a fresh handshake from a test client.

The safest transition overlaps trust rather than swapping it in one step. Where a new internal CA or intermediate is introduced, the root.crt used for client verification and the root.crt trusted by replicas, poolers and applications must contain both the old and new authorities until every certificate issued under the old chain has been replaced. Connection poolers add a second trust boundary: the client-to-pooler certificate and the pooler-to-server certificate are validated separately, so each side needs its own update and its own reload step. Inventory every trust store, including monitoring agents, backup tools and ETL jobs that use sslmode=verify-full, because a missed store will fail only when its job next runs.

Run the entire procedure on a non-production cluster first, using the same PostgreSQL version, pooler version and client images as production. Test the reload, the restart fallback, a standby reconnecting after the primary's certificate changes, and a client that still holds the old CA. Record the rollback steps, including keeping the previous key and certificate files until the new chain is confirmed. Ask your internal PKI or any outside CA provider for their issuance lead time, renewal reminders and revocation process before you set the production date, since these determine how much overlap you can afford. Repeat the test whenever the PostgreSQL major version, the pooler or the certificate authority changes.

Limits to confirm in your environment before you commit

TLS for PostgreSQL is only as strong as the weakest client, pooler, replica or automation step that touches it. The cards below list the limits that most often surprise teams after go-live, so you can confirm each one against your own drivers, packages and compliance requirements before you set hostssl rules and verify-full as the standard.

Client driver and certificate support

Confirm that every application driver, language client and admin tool you use can enforce sslmode=verify-full, load a custom root CA, and check the server hostname against the certificate. Some older libraries accept require silently or read only the system trust store, which leaves traffic encrypted but unauthenticated. Test each client against a staging server signed by your internal CA, and record which driver versions need a bundle path set explicitly.

Authentication methods docs

Reload and rotation automation

Check whether your configuration management, Kubernetes operator or scripts can replace the server certificate and key, set file ownership and permissions, and trigger a configuration reload without a full restart. Also confirm who owns the renewal calendar and how an expired certificate is detected before clients fail. A rotation process you have not rehearsed on a non-production cluster is a likely cause of a late-night outage.

Version and package coverage

Confirm that your PostgreSQL major version is on the supported list, since TLS settings such as ssl_min_protocol_version and the OpenSSL build behind them depend on the packages you install. Versions 14 through 18 are currently supported, and older releases are unsupported. Check that your distribution packages link against an OpenSSL build that supports the protocol versions and cipher policy your organization requires.

Versioning policy

TLS on every replication and pooler path

Map each connection that carries data: applications to the pooler, pooler to PostgreSQL, primary to standby, backup tools, monitoring exporters and administrators. Requiring TLS on the client-facing listener does not protect a pooler-to-server hop or a streaming replication connection that uses a different rule. Confirm that the pooler you choose supports TLS on its server side, and that failover tooling connects to standbys with verified certificates.

FIPS and cipher requirements

If your environment must use FIPS-validated cryptography or a specific cipher policy, ask your assessor which module and configuration they will accept before you choose an OpenSSL build or cipher list. Whether a given PostgreSQL build and operating system combination meets that requirement is a question for your certification team and the vendor, not something this page can settle. Record the answer in writing so the configuration can be shown to an auditor later.

Performance impact in your workload

TLS adds handshake cost on new connections and some CPU cost per encrypted byte. Measure connection setup latency and throughput on your own workload with and without encryption, especially for applications that open many short-lived connections without pooling. Use the results to decide whether session reuse in your pooler or a larger connection pool is needed, rather than relying on general estimates.

Questions buyers ask before configuring PostgreSQL TLS

What drives the cost and effort of PostgreSQL TLS work?

The main drivers are the number of client applications, the number of distinct connection paths, and how much of the certificate chain already exists. Each path adds work: direct client connections, connection poolers such as PgBouncer, streaming replicas, backup tools and admin tools all need their own TLS settings and tests. Effort also rises when the team has no internal certificate authority, when drivers differ across applications, or when older clients cannot negotiate the protocol version you want to require. Ask any quote to list each client type, each hop between client and server, and who issues and installs the certificates.

How long does it take to configure TLS for PostgreSQL?

Duration depends mostly on your environment rather than on PostgreSQL itself. The server-side change is small, but the schedule is set by how many applications must be updated, how many certificate requests must go through your PKI process, and how many change windows you need. A single database with a few well-known clients moves much faster than a fleet with poolers, replicas and third-party tools. Ask for a timeline that is tied to a written list of clients and hosts, and confirm which steps depend on your security or change board.

What does the team need to provide before TLS work starts?

Four things usually decide whether the work moves smoothly. First, shell access to database hosts and poolers, plus rights to reload PostgreSQL. Second, a named owner for the certificate authority who can approve signing requests and set certificate lifetimes. Third, application owners who will change connection strings and driver settings, since the database team cannot do this alone. Fourth, change windows for restarts and for any PgBouncer configuration reload. A written inventory of clients and their driver versions saves the most rework.

Can our own team configure PostgreSQL TLS without outside help?

A team with Linux, PostgreSQL and PKI experience can usually handle a small, single-site deployment alone. The settings themselves are documented, and the risk lies mostly in the details: verifying the server name against the certificate, keeping the CA trust file in step with each client, and checking every path, including poolers and replication connections. Outside help tends to save rework when many applications use different drivers, when the internal CA is new, or when the change must be documented for an assessment. Whichever route you choose, require a test that confirms each client actually negotiates TLS and verifies the certificate.

Does enabling TLS on PostgreSQL satisfy an audit requirement?

No. Encrypting connections is one control among several, and auditors usually check it alongside authentication rules, privilege design, logging, backup protection and key handling. TLS protects data in transit, but it does not limit who can log in, what they can read, or whether activity is recorded. Your compliance team should map the TLS configuration to the specific control statements that apply to your environment, and your auditor decides whether the evidence is sufficient. DeployOpen prepares systems, settings and evidence for assessments but does not issue audit reports or certifications.

How are PostgreSQL server certificates rotated after go-live?

Rotation is a recurring process, not a one-time task. Plan for a documented renewal before expiry, a way to replace the server certificate and key files, and a reload or restart step that PostgreSQL requires for the change to take effect. Clients that pin or bundle the CA must receive any new CA or chain before the old one is retired. Test the procedure in a non-production environment, and track expiry dates with monitoring so that an expired certificate does not cause an outage. Confirm with your PKI owner how renewal is automated, and who is responsible for each step.

Where do connection poolers and replicas fit into TLS planning?

Each hop needs its own TLS decision. Clients may connect encrypted to PgBouncer, and PgBouncer may connect encrypted to PostgreSQL, but these are two separate sessions with their own certificates and settings. Streaming replicas and backup tools also open connections that must be encrypted and verified. Check the PgBouncer version you run, since the project publishes security fixes in its releases, and confirm that certificate verification is configured on every hop rather than assumed from the first one.

What evidence to keep for security reviewers

Security reviewers will not accept a statement that TLS is configured. They will ask for the files and outputs that show it, and the set should be kept current from the first deployment. The core set is the server and client configuration files, including postgresql.conf settings for ssl, ssl_cert_file, ssl_key_file, ssl_min_protocol_version and ssl_ciphers, together with the pg_hba.conf rules that use hostssl and reject plaintext host entries for remote addresses. Keep these under version control with the date and the change ticket for each edit, so a reviewer can see what the rule set was on any given day and who approved it. Also keep the replication entries in pg_hba.conf, since replication traffic is often overlooked in reviews.

Next, keep verification evidence rather than intent. Record the output of psql sessions made with sslmode=verify-full against each endpoint, including the server version and the SSL details shown by \conninfo, and the output of a query against pg_stat_ssl showing ssl as true for the sessions in use. Pair these with test results from deliberate plaintext attempts, which should show the server refusing connections that do not use TLS, and with a check that a client presenting an untrusted or wrong-name certificate is rejected. Store the test scripts and the dated results together. The certificate inventory should list each certificate and its issuer, subject alternative names, serial number, expiry date and the nodes or clients that hold it, and it should be reviewed on a schedule the team sets and documents.

Finally, keep the rotation runbook and its history. The runbook should name who issues certificates, where private keys are stored and with what file permissions, how a reload is performed without a restart, and how the team confirms that new connections use the new certificate. Rotation records showing when each certificate was replaced, and any emergency revocation, give reviewers evidence that the process runs in practice. DeployOpen prepares these artifacts and tests them, but independent auditors and certification bodies are the ones who assess them against any framework you are subject to, so confirm early which evidence format that assessor expects.

How DeployOpen scopes and delivers PostgreSQL TLS work

The sequence below takes a TLS requirement from a written scope to a verified, documented configuration that your team can rotate and operate inside your own infrastructure.

  1. Agree the written scope first

    Before any change, DeployOpen and your team agree in writing which PostgreSQL servers, client applications, replicas, standby nodes and connection poolers are in scope, which certificate authority will sign server and client certificates, and which deliverables close the work. Your team confirms the PostgreSQL major version in use and whether it is still supported, since the TLS steps depend on the version. The step is done when the signed scope lists every connection path to be encrypted and the named owners for each.

  2. Map every connection path

    DeployOpen inventories how traffic reaches the database: direct application connections, admin sessions, streaming replication to standbys, backup tools, monitoring agents and any PgBouncer instances between clients and servers. Each path is recorded with its source address, current sslmode or connection string setting and the driver or library in use. The output is a path inventory that shows which paths are unencrypted today and which client libraries need configuration changes before enforcement is possible.

  3. Issue and install server and client certificates

    Working inside your certificate authority or the internal CA you designate, DeployOpen prepares server certificates whose names match the hostnames clients use, and client certificates where certificate-based authentication is planned. Private keys stay on your hosts with restrictive file permissions, and the chain is verified on each server. The step closes when a client on a test host completes a TLS handshake against the new certificate with the expected name check.

  4. Set protocol and cipher policy on the server

    DeployOpen configures ssl, the certificate and key file paths and ssl_min_protocol_version in the server settings, then sets pg_hba.conf so that remote connections are matched by hostssl rules and plaintext host entries are removed or narrowed. Replication entries are reviewed separately so that standbys connect over verified TLS. The server is reloaded or restarted as the change requires, and the result is confirmed by showing the active settings and the rule order in a test session.

  5. Configure clients and pooler hops

    DeployOpen sets sslmode to verify-full with the correct root certificate on each application and tool, and tests that a connection refused without TLS is rejected by the server. Where PgBouncer or another pooler sits in the path, the client-to-pooler and pooler-to-server legs are configured separately, so that each leg is verified and no leg silently falls back to plaintext. The step closes with a test matrix showing each client, pooler and replica connection, its negotiated protocol and whether certificate verification succeeded.

  6. Test failure and negative cases

    DeployOpen checks that expired, mismatched or untrusted certificates are rejected, that a client with the wrong root certificate fails closed, and that a standby with an invalid certificate cannot join replication. These tests confirm that the controls do what the written scope says, not only that the happy path works. Results are recorded with the command or query used, so your team can rerun them after later changes.

  7. Document the rotation and handover

    DeployOpen delivers handover documentation that covers certificate inventory, expiry dates, the reload procedure for certificate replacement, the rollback steps, the process for adding a new client or pooler, and the monitoring checks your team should run. Your team runs one planned rotation with DeployOpen observing, so that the procedure is proven before the handover is accepted. Optional retainers can cover later upgrades and rotation support; the scope and fees for those are quoted separately from the written scope, since DeployOpen does not publish a price list.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.