Hardening PostgreSQL to the CIS PostgreSQL Benchmark

A practical guide to using the CIS PostgreSQL Benchmark as a hardening baseline for self-hosted PostgreSQL, with the configuration, evidence and gaps that matter to compliance teams.

On this page

Which compliance work the CIS PostgreSQL Benchmark helps with, and which it does not

The CIS PostgreSQL Benchmark gives you a hardening baseline for a self-hosted PostgreSQL estate, and DeployOpen prepares the configuration, settings and evidence that show the baseline is applied. It does not certify anything. Certification and attestation come from independent auditors and certification bodies, and the benchmark is not a compliance scheme in its own right. CIS states that its Controls do not replace any regulatory, compliance or authorization scheme, and the same limit applies to the benchmark that sits under them. If a PCI DSS, HIPAA or other assessment is in front of you, the benchmark answers the question "is this database configured to a recognized secure baseline?" and leaves the question "does this meet the requirement as the assessor reads it?" open.

The benchmark covers the areas a reviewer will look at first: installation and file permissions, logging, authentication and pg_hba.conf, roles and privileges, replication settings, and automated checks. Each area produces artifacts you can show. File ownership and permissions on the data directory and configuration files, the log_* settings that decide what the server records, the rules in pg_hba.conf that decide who can connect and how, the role graph that decides who can do what, and the replication settings that decide what a standby accepts. Confirm with your assessor which of these artifacts they expect, and in what form, before you start. Audit logging depth, role separation for regulated data and retention are covered in the compliance pages of this site, so treat the benchmark as the configuration layer beneath them.

Plan for the gaps the benchmark leaves. Its recommendations are written for the server and its configuration, not for your data classification, your access review process or your evidence retention. Recurring work includes reviewing role membership, rotating credentials, checking that logs leave the host, and rerunning configuration checks after each minor or major upgrade. Ask any partner to state in writing which benchmark recommendations they will apply, which they will mark as not applicable with a reason, and which evidence they will hand over. Confirm the benchmark version you are measured against with your assessor, since the published recommendations change over time.

Mapping benchmark areas to PostgreSQL capabilities and configuration

This table pairs each hardening area in the CIS PostgreSQL Benchmark with the PostgreSQL capability that supports it, the configuration to set and the CIS Controls Navigator mapping to confirm. Use it as a worksheet: take each row to the Benchmark PDF, match the exact recommendation numbers, and record the setting your environment actually uses.

Benchmark areaPostgreSQL capability and configuration to setMapping to confirm
Installation and file permissionsInstall from official packages, restrict ownership of the data directory and configuration files to the postgres OS user, and confirm the server binaries match the minor release you plan to run. Minor releases replace executables and need a restart, so track them as part of patching.Confirm the CIS Controls v8.1 Safeguards on asset inventory and secure configuration of software in the Navigator for your target framework.
LoggingSet logging_collector, log_connections, log_disconnections and log_line_prefix so each entry carries time, user, database and client address. Route logs to a location the database role cannot edit, and add pgAudit where the Benchmark expects statement-level auditing.Confirm the Safeguards on audit log collection, retention and protection in the Navigator, then check the retention period against your own policy.
Authentication and pg_hba.confSet password_encryption to scram-sha-256 and reject md5 entries in pg_hba.conf. Where the environment supports it, use certificate or GSSAPI authentication for administrators, and restrict each rule by database, user and source address. PostgreSQL 18 deprecates MD5 password authentication in favor of SCRAM.Confirm the Safeguards on account management and access control for service and administrative accounts in the Navigator.
Roles and privilegesCreate separate roles for owners, applications and read-only reporting, revoke default PUBLIC privileges on the public schema where the Benchmark recommends it, and grant only the rights each role needs. Avoid using the superuser role for application connections.Confirm the Safeguards on access granting, revoking and periodic access review in the Navigator.
Replication settingsRestrict replication connections to named standby hosts in pg_hba.conf, encrypt replication traffic with TLS, and choose between synchronous and asynchronous replication based on the data-loss trade-off you have accepted. PostgreSQL does not detect a failed primary by itself, so the failover tool must also be hardened.Confirm the Safeguards on data recovery and protection of data in transit in the Navigator, and the matching controls in your target framework.
Automated checksSchedule a script or configuration audit tool that reads pg_settings, pg_hba.conf and file permissions, compares results with the Benchmark recommendations and stores dated output. Treat each check as evidence of a setting at a point in time, and alert when a value drifts.Confirm the Safeguards on continuous vulnerability and configuration management in the Navigator. Note that CIS publishes what to measure in the Assessment Specification, not how to measure it.

How each hardening area is built, tested and kept

The first decisions are where the server binaries come from, which operating system account owns the data directory, and who can read configuration files that hold connection or replication settings. Teams that install from official packages usually inherit sane defaults, but the data directory, the configuration directory and any WAL archive location still need explicit ownership and mode settings. Plan the separation between the service account, administrators and backup software before the first start, because changing ownership later tends to be done under pressure.

  • Package source: Record which repository and version the binaries came from, and confirm that the version is still in support on the PostgreSQL versioning policy page.
  • Data directory mode: Confirm that only the PostgreSQL service account can read the data directory, and that backup accounts reach it through the database protocol or a controlled archive path.
  • Configuration files: Check that postgresql.conf and pg_hba.conf are not writable by the service account in production, so changes go through review.
  • Extension and library paths: Confirm that only approved shared libraries load, and that no writable directory sits on the library search path.
  • Risk: Overly broad group membership on the data directory exposes every table through the file system, even when roles look correct inside the database.

A reviewer should be able to list each file and directory with its owner and mode, and explain why each account needs access to it.

How the benchmark controls fit around the PostgreSQL server

The diagram starts with client applications and administrators outside the database host. Connections pass the pg_hba.conf gate before reaching the server, where roles and privileges limit what each login can do. The server writes logs to a pipeline that the operations team reviews, and streams changes to replicas that need their own hardening. A scheduled check job reads the configuration and writes evidence, so the team can see which settings still drift from the benchmark. Confirm each trust boundary with your own network and access owners before treating the diagram as final.

Trust boundaries and hand-offs between clients, the database host and operations.

Evidence a reviewer can check for each hardening control

Each hardening control in the CIS PostgreSQL Benchmark should leave behind a record a reviewer can read without asking you what it means. The items below are the records we would expect a security or audit team to ask for, and each one is only useful if it names the PostgreSQL major and minor version, the benchmark section it supports, and the date it was captured.

Configuration files under version control

Keep postgresql.conf, postgresql.auto.conf and any included override files in a Git repository, with each change tied to a commit, an author and a reason. The commit history shows what was set, when it changed and who approved it, which is the first thing a reviewer compares against the benchmark recommendation. Tag each release of the configuration with the PostgreSQL version it targets, so a later minor update does not silently invalidate the record. Confirm that production files match the repository, because drift between the two is a common finding.

PostgreSQL HA docs

pg_hba.conf review records

Store a dated review of pg_hba.conf that lists every rule, the connection type, the database and user it matches, the address range, and the authentication method used. Record why each rule exists and who owns the application behind it. Reviewers look for rules that allow trust or weak methods, broad address ranges, and entries that no longer match a live application. Repeat the review on a fixed schedule and after every change to network or identity configuration.

Authentication methods docs

Role and privilege listings

Export the role catalog and the privileges granted on schemas, tables and functions as a dated listing, for example from \du and queries against the system catalogs. Note which roles can log in, which hold superuser or create-role rights, and which are shared by more than one person or application. Compare each listing with the benchmark sections on roles and privileges and record every exception with an owner and a reason. Ask your team to confirm that a listing taken from production matches the one from the same PostgreSQL version in a staging system.

Log configuration and sample entries

Keep the logging settings that the benchmark asks you to review, such as log_connections, log_disconnections, log_line_prefix and the logging collector, with the file that sets them. Alongside the settings, keep a few sample log entries from the same period showing a successful login, a failed login and a privilege change. Samples prove the settings produce output, which a settings file alone does not. Check that the log path has the correct owner and permissions, and that the retention period set for these files matches your own policy.

Continuous archiving docs

Replication and archive settings

Record the replication settings in effect, including wal_level, the max_wal_senders limit, synchronous_standby_names, and the archive_mode and archive_command used for continuous archiving. Show which standby connections are allowed in pg_hba.conf and whether replication uses TLS. Capture the output of pg_stat_replication on the primary to show which standbys are connected and in what state. Because replication settings change with failover design, tie each capture to the PostgreSQL version and the date, and rerun it after any failover test.

Output from automated checks

Scheduled scripts that test configuration against the benchmark produce the most repeatable evidence, provided their output is kept. Save each run with a timestamp, the target host, the PostgreSQL version, the benchmark version and the list of checks that passed, failed or were excluded with a reason. Treat the output as an internal control record, not an audit report: it shows what your team tested and what it found, and an independent assessor still decides what counts as compliance. Keep failed runs as well as passing ones, since a history with no failures is harder to trust.

The hardening sequence from baseline to repeatable checks

The sequence turns the CIS PostgreSQL Benchmark from a reference document into a set of settings, evidence and scripted checks that stay valid as the database changes. Each step builds on the one before, so the final checks test a configuration someone has already justified.

  1. Confirm the supported version and end-of-life date

    Before any benchmark work, confirm which PostgreSQL major version is running or planned and check its end-of-life date in the PostgreSQL versioning policy. Hardening a version that is about to lose support means repeating the work during an upgrade, so the team should decide the target major version first. The output is a written record of the version, its support end date and the owner who will plan the next major upgrade.

  2. Scope the benchmark profile and assets

    Identify which servers, clusters, backup hosts and client-facing connection points fall inside the hardening scope, and which Benchmark recommendations apply to each. The security lead and the database owner should agree which recommendations are required, which need compensating controls and which are documented exceptions with a reason. The output is a scope statement that maps each in-scope host to its profile and lists every recommendation accepted as an exception.

  3. Apply installation and file permission settings

    Harden the operating system account, installation paths, data directory, configuration files and binaries so only the intended service accounts can read or change them. Remove or restrict default packages and tools that the server does not need. The platform engineer carries out the change through configuration management so it can be reproduced, and the output is a permissions report showing owner, group and mode for the data directory, configuration files and key material.

  4. Configure logging and authentication

    Set server logging so connections, failed logins, disconnections and configuration changes produce records that are stored away from the database host. Then tighten the authentication design in pg_hba.conf so only approved networks, users and methods can connect, with password hashing set to SCRAM rather than MD5. The output is a reviewed configuration file and a test log showing a failed login recorded with the expected fields.

  5. Set roles and privileges

    Create named roles for applications, administrators, read-only reporting and maintenance, and remove broad privileges from the public schema and from default roles. Application accounts should hold only the grants they need on specific schemas and tables. The database owner and security engineer review the role map together, and the output is a privilege matrix that can be compared against the live catalog during each check.

  6. Configure replication settings

    Review streaming replication and any hot standby configuration so replication connections use dedicated roles, approved networks and encrypted transport. Confirm that replication users have only the privilege they need and that standby servers receive the same file permission and logging baseline as the primary. The output is a replication settings review with each standby checked against the same profile as the primary.

  7. Script the checks and store the evidence

    Turn each hardened setting into an automated check that reads the live configuration, catalog and file system and writes the result with a timestamp. The CIS Controls Assessment Specification describes what to measure for related safeguards, but the scripts and their thresholds are the team's own work to write and maintain. The output is a scheduled check job, a baseline of expected results and stored reports that show the state of each setting over time.

  8. Retest after each minor update

    Minor PostgreSQL releases replace executables and restart the server without changing the storage format, but package updates can still reset file modes, add default settings or change behavior. Run the full check suite after every minor update and after any configuration change, then compare results with the baseline. The output is a dated retest record that either confirms the baseline still holds or lists each drift with an owner and a fix.

What the benchmark and the platform do not cover

A CIS benchmark sets a configuration baseline, but it does not test your environment, prove compliance or make PostgreSQL highly available. The cards below name the gaps that remain after hardening, and who or what has to close each one.

No assessment of your environment

The benchmark describes recommended settings, not whether your servers meet them. Someone must run the checks against each host, record the results and explain each deviation. Confirm the exact benchmark version and each recommendation's profile and scope with CIS before you start, because recommendations change between versions.

CIS PostgreSQL Benchmarks

Assessment specification defines what, not how

The CIS Controls Assessment Specification defines the inputs, operations and measures used to verify a Safeguard, but CIS states it covers what to measure rather than how. Your team must write the queries, scripts or procedures that collect the evidence, and decide how often they run and who reviews the output.

About the CIS CAS

No failure detection or automatic failover

Hardening does not make a cluster survive a failed primary. PostgreSQL does not detect a primary failure or notify a standby, so automatic failover depends on external tools that you select, configure and test. Replication settings in the benchmark control how data is protected, not how quickly service returns.

PostgreSQL failover docs

Benchmark items do not satisfy compliance schemes

Meeting a benchmark recommendation does not show that a PCI DSS, HIPAA or other compliance requirement is met. CIS states its Controls do not replace regulatory or authorization schemes. Map each hardened setting to the requirement it supports, and have your assessor confirm the mapping for your environment.

Operating system and network controls

Many benchmark items assume a host that is already protected. File permissions, service accounts, package sources, firewall rules, and network exposure of port 5432 are set at the operating system and network layers. Confirm who owns those controls and include them in your review, or PostgreSQL hardening will rest on an unverified base.

Key and certificate management

The benchmark can require TLS and strong password hashing, but it does not decide where private keys live, how certificates rotate, or who can read the server key file. Key generation, storage, rotation and revocation sit with your secrets and PKI processes. Document those owners before you mark any encryption item as complete.

Questions buyers ask before hardening PostgreSQL to CIS

Can our own team harden PostgreSQL to the CIS benchmark without a partner?

Yes, if you have engineers who know PostgreSQL administration and your change process. The CIS PostgreSQL Benchmark is a set of secure configuration guidelines, and CIS Benchmarks are freely available in PDF format for non-commercial use, so the guidance itself costs nothing to read. The harder part is applying it consistently across every server, proving each setting with evidence and keeping it in place through upgrades. Teams that run this in-house usually need one owner for the baseline, a way to check settings automatically and a review step for exceptions. A partner is useful when those pieces are missing or when the team lacks time to build them.

What makes the hardening effort larger or smaller?

Effort follows the shape of your estate more than the benchmark itself. The main drivers are:

  • The number of clusters, servers and environments that must match the baseline
  • Replication design, since synchronous standbys, failover tooling and backup links each need their own checks
  • Authentication integration, such as directory login, certificates or OAuth, which changes pg_hba.conf and role management
  • Existing tooling, including configuration management, monitoring and ticketing, which can be reused or must be built
  • Exceptions, where a business application needs a setting the benchmark does not allow and the risk must be documented

Ask any partner to break its quote down by these drivers so you can see which ones your environment adds.

What do we need to provide before hardening work starts?

Plan for access, time in your change calendar and named owners before the work begins. Engineers need administrative access to the test and production hosts in scope, the ability to read PostgreSQL configuration files and logs, and a way to test changes outside production first. Change windows matter because some settings, such as authentication rules and the logging configuration, need a configuration reload or a restart. Most important are owners for roles: someone must confirm which application accounts, administrators and reporting users should exist and what each one needs, because role and privilege decisions cannot be made safely by the implementer alone. Your security team should also agree how exceptions are approved.

How long does CIS hardening take for a PostgreSQL estate?

Duration depends on the same drivers as effort: how many clusters are in scope, how much of the baseline is already in place, how complex authentication and replication are, and how quickly your change approvals run. Ask for a timeline in the written scope rather than a general number, and make sure it includes time for testing, change windows and the agreed review of exceptions. Most engagements are fixed-scope, so deliverables and timelines are agreed in writing before work starts. Ask the partner which milestones produce evidence you can review, so progress can be checked before the final handover.

Does DeployOpen certify that our PostgreSQL meets CIS or compliance requirements?

No. DeployOpen does not issue audit reports, attestations or certifications. It plans and implements the hardening, prepares the configuration, evidence and controls that an assessor would review, and can run security testing against the result. Independent auditors and certification bodies make the assessment decision. CIS also states that the Controls do not replace any regulatory, compliance or authorization scheme. Confirm with your assessor which evidence they accept for benchmark-based settings, and agree the evidence format with them before work starts.

How is the CIS hardening retested after PostgreSQL upgrades?

Treat each minor or major upgrade as a trigger for rerunning the checks. PostgreSQL minor releases replace executables and require a restart, while major upgrades can use pg_upgrade, dump and restore, or logical replication, so the configuration and roles may need review after the change. A sound approach is to keep the automated checks in version control, run them against a staging copy before the production upgrade, and rerun them afterward, recording the results. Ask any partner whether retesting after upgrades is included in the fixed scope or sold as a retainer, and what evidence the retest produces. Your own team should confirm the supported version window for each major release in the PostgreSQL versioning policy before scheduling an upgrade.

How DeployOpen works on this

DeployOpen plans, implements, hardens, documents and supports self-hosted open-source platforms inside your own infrastructure, including PostgreSQL. For CIS PostgreSQL Benchmark hardening, the work starts with a written scope that maps each benchmark recommendation to your actual deployment, then applies and tests the settings in your environment.

How we scope

  • Engagements are fixed-scope, with the PostgreSQL versions, servers and recommendations in scope agreed in writing before work starts.
  • The scope lists which benchmark sections apply to your deployment, and which recommendations you accept, change or document as exceptions.
  • Ask for the scope to name the PostgreSQL major version, operating system, and whether replicas and pooled connections are included.

How we build

  • Configuration changes cover installation and file permissions, logging, pg_hba.conf authentication, roles and privileges, and replication settings.
  • Each change is tested against a non-production copy of your cluster before it reaches production, with the before and after state recorded.
  • Automated checks are written so the same benchmark tests can run again after every change, upgrade or configuration review.

How we hand over

  • You receive a configuration record mapping each in-scope recommendation to the setting applied, the file changed and the test that verified it.
  • Documented exceptions include the reason, the compensating control and the owner who accepted the risk, so auditors can follow the reasoning.
  • Runbooks explain how to rerun the automated checks, interpret failures and roll back a setting without weakening the rest of the baseline.

How we support

  • Ongoing support, upgrades and continuous testing are available as retainers, for example when a new PostgreSQL minor release changes a setting.
  • Re-checks after PostgreSQL major upgrades confirm that hardened settings carried over and that new defaults were reviewed.
  • Ask any quote to state what recurs under a retainer, what is one-time, and which items depend on your own change process.

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.