Encrypting cardholder data in PostgreSQL for PCI DSS

A plan for protecting stored primary account numbers in self-hosted PostgreSQL, with the requirements it helps meet, the gaps it leaves, and the evidence an assessor will ask for.

On this page

Encrypting cardholder data in PostgreSQL for PCI DSS: what the platform covers

If your team stores primary account numbers (PAN) in a self-hosted PostgreSQL database, PCI DSS requirement 3 applies to that data, and PostgreSQL can help you meet it but cannot meet it on its own. The database gives you column-level encryption through pgcrypto, transport encryption through TLS and access controls through roles and authentication methods, but it does not decide where keys live, how they rotate or whether the surrounding systems keep PAN out of places it should not reach. DeployOpen plans, builds and documents these controls in your infrastructure and prepares the evidence an assessor will ask for. DeployOpen does not issue a Report on Compliance or an Attestation of Compliance. Those come from a Qualified Security Assessor or from your own completed Self-Assessment Questionnaire, and the assessor decides whether your controls satisfy the requirement.

PostgreSQL is released under the PostgreSQL License, a permissive license similar to the BSD and MIT licenses, so the software itself carries no licensing barrier to use in a cardholder data environment. Licensing is not the question an assessor asks, though. The assessment is run against the cardholder data environment as a whole: every system that stores, processes or transmits PAN, every system that could affect its security, the network segments between them, the administrators who can reach the keys and the backups, replicas and logs that copy the data. A PostgreSQL cluster that encrypts columns well but replicates plaintext to a reporting server or writes PAN into application logs will still fail the scope review. Confirm early which systems your payment flows touch, and treat the database as one component in that inventory.

Before you choose between column encryption with pgcrypto and storage-level encryption, ask your acquirer or QSA which PCI DSS version and assessment type applies to you, because the requirement wording and the evidence list depend on it. PCI DSS v4.0.1 is the only active version of the standard, and your assessment template will reflect it. Confirm with your assessor how they expect you to demonstrate key management and whether a defined or customized approach fits your design. Those answers set the scope of the encryption work, and that scope determines the size of the project.

Mapping PCI DSS requirement 3 to PostgreSQL capabilities and configuration

This table maps the stored account data and transmission controls to the PostgreSQL features, operating system settings and external tools that implement them. Rows marked outside PostgreSQL show work that the database cannot do alone, such as key custody and volume encryption, so assessors will look at the surrounding systems as well as the database configuration. Use it to decide which control owner signs off on each row.

Control conceptPostgreSQL capability and configurationWhere the work sits
Protect stored account data (requirement 3)Decide which columns hold PAN. Store only what the business needs, and encrypt or tokenize the rest before it reaches the table.Inside PostgreSQL (schema design), with data flow mapping done by the team
Column-level encryption of PANUse pgcrypto functions such as pgp_sym_encrypt with keys supplied at runtime, never stored in the database or in the schema.Partly outside PostgreSQL: the key must come from an external key manager
Storage encryption at restPostgreSQL does not encrypt its own data files. Use volume, filesystem or cloud disk encryption under the data directory and WAL, and confirm backups and replicas are covered too.Outside PostgreSQL: operating system, storage array or cloud provider
Key management outside the databaseKeep encryption keys in a dedicated key management service or secrets store, with rotation and separation from database administrators. Confirm who can read key material.Outside PostgreSQL: key management platform and its access policy
Protect cardholder data in transit (requirement 4)Set ssl to on, supply ssl_cert_file and ssl_key_file, and use hostssl entries in pg_hba.conf so plaintext connections are rejected. Choose a TLS version and cipher policy your assessor accepts.Inside PostgreSQL for configuration, outside it for certificate issuance and trust chains
Strong authentication for database accessSet password_encryption to scram-sha-256 and use scram-sha-256 in pg_hba.conf. Avoid MD5, which PostgreSQL 18 deprecated in favor of SCRAM.Inside PostgreSQL, with password policy enforced by the identity team
Certificate authentication for servicesUse the cert method in pg_hba.conf with client certificates, mapping certificate names to roles through pg_ident.conf where needed.Partly outside PostgreSQL: certificate authority and rotation process
Replication and backup trafficEnable TLS on streaming replication connections and on connections used by backup tools, and restrict them to known hosts in pg_hba.conf.Inside PostgreSQL for settings, outside it for backup tool and network path configuration

Column encryption with pgcrypto versus storage encryption

PAN protection in PostgreSQL works at several layers, and each one answers a different threat. The cards below compare pgcrypto column encryption with storage encryption, then cover the scope-reduction options that often matter more than either.

What pgcrypto column encryption protects

The pgcrypto extension encrypts individual column values inside rows, so a PAN stored as ciphertext stays unreadable to a role that can select the table but lacks the key. The key question is where the key lives: if the application or the database session holds it, a compromised connected role may still recover plaintext. Check which role can call the decryption functions and whether keys ever reach the database server.

PostgreSQL auth methods

Query and index trade-offs of column encryption

Encrypted columns cannot be matched with ordinary equality or range searches, and randomized ciphertext defeats a standard B-tree index. Lookups usually need a separate keyed hash or blind index column, which itself must be protected. Test the reporting, refund and customer-support queries early, since these are where encrypted PAN columns most often break application behavior.

What storage encryption protects

Volume, filesystem or full-disk encryption protects data at rest on stolen drives, decommissioned storage and backup media. It does not stop a connected database role from reading PAN with an ordinary query, because the database receives decrypted pages. Ask your storage team whether the same key protects backups and replicas, and who can unlock the volumes at boot.

Truncation and tokenization reduce scope

Storing only a token or a truncated PAN in PostgreSQL can remove most stored PAN from the cardholder data environment, provided the token vault sits elsewhere and tokens cannot be reversed inside your database. This often reduces the number of systems to assess more than encrypting columns does. Confirm the design with your assessor before you rely on it.

Keeping PAN out of logs and replicas

A PAN that reaches a statement log, a slow-query log, a backup dump or a standby is in scope wherever it lands, even if the primary column is encrypted. Review log_statement and log_min_duration_statement settings, and check that application error handlers do not echo values. Replicas inherit whatever the primary stores, so the copies need the same controls.

Key rotation and key custody

Column encryption adds a rotation task: re-encrypting existing rows under a new key, keeping old keys until every row and backup is migrated, and recording each rotation. Keys should be held outside the database, in a dedicated key management service or secrets platform, with access logged. Ask how long a rotation takes on your largest table and whether it can run without downtime.

How cardholder data moves through the database and its trust boundaries

Cardholder data starts in the payment application, which sends it to PostgreSQL over TLS and stores the primary account number (PAN) in an encrypted column or under encrypted storage. Keys are fetched from a key management service outside the database, and backups, replicas and logs each receive a copy that must sit inside the same boundary. Check that every arrow leaving the cardholder data environment is encrypted and that no key or PAN appears in a log.

Cardholder data flows from the application into PostgreSQL, with keys held outside the boundary.

Keeping encryption keys outside the database

Keys stored beside the data defeat column encryption. If the pgcrypto key is held in a table, a configuration file, a postgresql.conf setting or a session variable on the same server, anyone who can read the database can usually read the key too, and the encrypted PAN column protects nothing against a privileged user or a stolen backup that includes the key. PCI DSS requirement 3 expects the keys that protect stored account data to be stored and managed separately from the data they protect. The practical options are an external key management service run by your cloud provider, an on-premises key manager such as an HSM-backed KMS, or a secrets platform like OpenBao that you operate in your own infrastructure. Whichever you choose, the application or a dedicated decryption service should fetch the data key through an authenticated call, and the database should only ever see ciphertext and, for queries, a keyed hash of the PAN.

Separate the people who hold keys from the people who run the database. Database administrators should not be able to administer the key manager, and key custodians should not hold database superuser rights. Define at least three roles: key custodians who create and rotate master keys, service identities that may only decrypt for the payment application, and auditors who can read key usage logs without any decrypt rights. Plan rotation as a documented procedure: decide how often the master key rotates, how existing ciphertext is re-encrypted, and how old keys are retained until no record needs them. Confirm with your QSA how the rotation and separation of duties will be evidenced, because the assessor will ask for it. The choice of key manager is yours and must be confirmed against your environment, including your cloud account, data center and approved hardware. DeployOpen does not supply encryption keys as a service.

Plan recovery before you lose a key. A lost master key makes every ciphertext it protects unreadable, so key backup is as important as data backup. Store escrowed or wrapped copies of key material in a separate trust domain with split knowledge or dual control, and rehearse restoring a PAN column from a database backup and the key store together. Test that a restore from backup can reach a working decryption path in a staging environment, and record the result. Ask your key manager vendor or hosting provider to confirm in writing how key deletion, key recovery windows and regional replication behave, because those settings decide whether a mistaken deletion can be undone.

TLS for cardholder data in transit by connection path

Application connections carry PAN in queries and results, so they are usually the most exposed path. PostgreSQL supports TLS on client connections through the ssl setting in postgresql.conf, with server certificate and key files referenced by ssl_cert_file and ssl_key_file, and a CA bundle that clients can use to verify the server. The server's pg_hba.conf controls which connections must use TLS, typically by matching only hostssl entries and rejecting plain host entries for cardholder databases.

  • Require TLS in pg_hba.conf: Use hostssl lines for every application role and reject non-SSL matches for the cardholder schema.
  • Verify the server identity: Set clients to verify-full so they check the certificate chain and host name, not just that TLS is present.
  • Use SCRAM for passwords: Set password_encryption to scram-sha-256 and disable md5 entries in pg_hba.conf. PostgreSQL 18 deprecated MD5 password authentication in favor of SCRAM.
  • Consider certificate authentication: The certificate method can identify application clients by a client certificate, which removes shared passwords from application configuration.
  • Pool connections carefully: Connection poolers such as PgBouncer sit on this path, so confirm that TLS is enabled on both the client side and the server side of the pooler.

Confirm cipher suites, minimum protocol versions and certificate lifetimes against your own cryptography policy and your assessor's expectations.

Evidence an assessor will ask for and how to keep it

The evidence for PCI DSS requirement 3 and 4 is mostly configuration, inventory and review records that change as the database changes. The cards below cover the records a PostgreSQL estate should produce and how to keep each one tied to change management rather than rebuilt before an assessment.

Encryption configuration exports

Export the settings that decide how PAN is protected: pgcrypto usage in each table definition, the column list that holds encrypted values, and the storage encryption status of the data volumes and backup targets. Store the exports on a schedule and after every schema migration. Check that the export shows what the database actually does, not what the design document says it should do, because a mismatch is the first thing a reviewer finds.

Key inventory and rotation logs

Keep a register of every key that protects cardholder data: its purpose, the system holding it, its owner, creation date, and the rotation history. Each rotation should leave a record that names the old key, the new key, the re-encryption job and its result. Confirm with your key management vendor how rotation events are logged, since the database itself may not record key access.

Version-controlled pg_hba.conf and TLS settings

Keep pg_hba.conf, postgresql.conf and the TLS certificate configuration in version control with reviewed commits. Every change to ssl, ssl_min_protocol_version or the host rules should have a pull request, an approver and a link to the change ticket. Compare the deployed file with the repository on a schedule, because a file edited directly on the server breaks the chain of evidence.

Data discovery results

Keep dated results from scans that locate PAN across tables, text fields, logs, exports and test copies. A scan proves the cardholder data environment boundary only if it covers every database in scope and is repeated after new features ship. Record what was found, where it was moved or removed, and who approved the disposition. Ask your assessor which scanning method and coverage they expect before you rely on one tool.

Access reviews for key holders

Review who can read or use encryption keys, who holds database superuser or role-management rights, and who can change pgcrypto functions in production. Record the reviewer, the date, the accounts removed and the reason. Tie reviews to the identity provider so that leavers and role changes are reflected in the database automatically, and keep the reviews separate from the people who requested the access.

Change tickets linking the records

Each encryption change, key rotation, TLS update or scope change should produce one change record that points to the configuration diff, the key inventory entry, the updated discovery result and the access review if roles changed. This single trail is what lets a reviewer follow a control from the requirement to the evidence. Ask your QSA which change evidence they sample and how far back they look before you set retention periods.

Configuration sequence for encrypting PAN in PostgreSQL

This sequence takes stored primary account number (PAN) data from discovery to documented, tested controls, so each PCI DSS requirement 3 decision in the database is traceable to an owner, a configuration and a restore result. Most steps depend on your cloud, data center or key management setup, so confirm those details with your platform and security teams before you start.

  1. Confirm scope and discover PAN locations

    Your QSA or internal assessment lead defines which systems count as the cardholder data environment (CDE), and your DBA team searches every PostgreSQL database, schema, table, log, dump, replica and test copy for PAN and sensitive authentication data. Record each location with its owner, purpose and data flow. This step is done when the team can show a reviewed inventory that matches the assessment's scope statement. Ask your assessor to confirm the scope boundary in writing before any design work begins.

  2. Reduce where PAN is stored

    Before choosing an encryption method, challenge each location. Many teams find PAN in staging copies, analytics extracts or application logs that do not need the full number. Remove what the business process does not require, truncate or tokenize where the use case allows, and move cardholder data that belongs to a payment provider out of your database. Document each removal and its approval. The output is a smaller inventory, and every remaining PAN location becomes a known control point for the later steps.

  3. Choose column, volume or application encryption

    Select the encryption layer for each remaining PAN location. Column-level encryption with pgcrypto protects the field even when someone reads the table files or a dump, but it requires key handling in the application or in functions and limits how the data can be searched or indexed. Volume or storage encryption at the operating system or disk layer protects media and backups but does not stop a database user with query rights from reading plaintext. Application-level encryption keeps keys furthest from the database. Many designs combine layers. Record the decision, the threat each layer addresses, and the team that owns each key.

  4. Provision an external key manager

    Place encryption keys outside the PostgreSQL server and outside the database's own administrative roles. Options include a hardware security module, a cloud key service or a self-hosted secrets and PKI platform such as OpenBao, depending on what your infrastructure supports. Define key hierarchy, rotation ownership, access approvals and an emergency recovery process. Confirm with your platform team which key manager your environment is permitted to use under your own policies. The step is complete when keys are created, access is limited to the application or service identity that needs them, and rotation has been tested in a non-production environment.

  5. Configure TLS and SCRAM authentication

    Enable TLS for every client and replication connection so PAN is encrypted in transit between the application, the database and any replicas. Use certificates issued by your internal or public certificate authority, and set the server to require encrypted connections for the CDE. Set password_encryption to scram-sha-256 and create roles with SCRAM credentials, since PostgreSQL 18 deprecated MD5 password authentication in favor of SCRAM. Confirm with your identity team whether directory or certificate authentication should replace passwords for administrators. Verify the result with a connection test that fails when TLS is not negotiated.

  6. Lock down pg_hba.conf and privileges

    Restrict who can connect and from where by writing explicit rules in pg_hba.conf, ordered so that the first matching rule is the intended one. Allow only the CDE application subnets, administrative jump hosts and replication hosts, with hostssl entries for all of them. Grant table privileges only to the roles that need PAN, and keep decryption rights separate from ordinary application rights where your design allows. Remove default access for public roles. Review the file and the role grants with a second person, and keep the reviewed copy under version control. The output is a rule set that your assessor can trace line by line.

  7. Test restore of encrypted backups

    Take a base backup and a logical dump of the encrypted database, then restore both into an isolated environment. Confirm that the restored database can decrypt PAN only with keys retrieved from the external key manager, and that keys are not stored in the backup itself. Check that backup media and copies follow the same encryption and access controls as production. Point-in-time recovery depends on archived WAL files, so test that path too. Record the restore duration and any failures. Your DBA and backup owner should sign off, and the result should be repeated after each significant change.

  8. Document results and retain evidence

    Assemble the evidence set for your assessor: the scope and inventory, data-reduction decisions, encryption design and key ownership, TLS and SCRAM settings, the reviewed pg_hba.conf, privilege reports, and the restore test records. Map each item to the PCI DSS requirement it supports, and note which steps rely on your environment, such as your key manager or certificate authority. Assign an owner and a review date for each control. DeployOpen can prepare systems and evidence for your assessment, but the report on compliance or self-assessment questionnaire and attestation are issued by your QSA or by you, not by DeployOpen.

Questions buyers ask before hiring help for PCI DSS database encryption

How much work is PCI DSS database encryption, and what drives the effort?

The effort depends mostly on how many databases hold primary account numbers (PAN), how many systems read or write them, and how much of the existing data model has to change. A single database with one application writing card numbers is a very different job from a estate where PAN is copied into reporting schemas, logs, exports and backups. Other drivers include whether the team needs column encryption, storage encryption or both, how keys are issued and rotated outside the database, how TLS is enforced for every client and replica, and how much evidence the assessor will expect. Ask for a written scope that lists each database, each data flow and each deliverable before comparing quotes.

Can our own team implement PCI DSS encryption in PostgreSQL without a partner?

Often yes, if the team already runs PostgreSQL in production and has someone who understands key management and the cardholder data environment. The skills that tend to be missing are not SQL skills but decisions about key hierarchy, key custody, rotation and recovery, and the discipline to prove each control with records. A useful self-check is whether your team can name who holds the key-encryption keys, how a rotation is tested, and where the evidence for each requirement is stored. If those answers are unclear, a partner can help with the design and the evidence, while your staff keep ownership of the running system.

What do we need to provide from our own staff during the engagement?

Expect to supply people and access more than money. The usual inputs are the owner of the cardholder data environment, a database administrator, an application owner for each system that handles PAN, a network or platform engineer for TLS and segmentation, and someone from security or compliance who can accept the design. You will also need to provide read access to schemas and configuration, a test environment that resembles production, and a change window for migrations. Agree these responsibilities in the written scope so that delays are visible and attributable.

How long does it take, and what sets the timeline?

The timeline is set by the number of data stores that hold PAN, the amount of application code that must change, the number of environments to migrate, and how quickly your key management decisions are approved. Data migration from plaintext columns to encrypted columns usually takes the longest, because it needs a tested rollback and a short cutover. We do not publish a duration in advance. Ask for a phased plan with milestones for design, test migration, production cutover and evidence collection, and check which milestones depend on your own approvals.

Does DeployOpen certify that our environment is PCI DSS compliant?

No. DeployOpen plans, implements and documents the controls and prepares the evidence for your assessment, but it does not issue reports, attestations or certifications. Under PCI DSS, validation is documented on official templates, either a Report on Compliance completed by a Qualified Security Assessor or a Self-Assessment Questionnaire with an Attestation of Compliance. Your assessor or acquirer determines which applies to you. Certificates are not recognized as validation. Confirm the assessment type with your acquirer before the work starts, so the evidence we prepare matches what the assessor will sample.

Does pgcrypto alone satisfy PCI DSS requirement 3?

No single tool does. The pgcrypto extension can encrypt individual columns, but requirement 3 is about protecting stored account data as a whole, which also covers key management, access to keys, and how keys are protected and rotated. If the keys sit beside the data in the same database, a column encryption design can be defeated by anyone who can read both. Storage encryption protects files at rest but does not stop an authorized database user from reading plaintext. Most designs combine approaches, keep keys in a separate system, enforce TLS for transmission, and reduce where PAN exists at all. Confirm the approach with your assessor, because the control must meet the requirement's intent for your environment.

What changes if PCI DSS is revised again?

The current version is PCI DSS v4.0.1, published on 11 June 2024, and it is the only active version. The PCI Security Standards Council ran a request for comments on v4.0.1 from 3 June to 20 July 2026 to start the next iteration, and as of October 2026 it had announced no release date for a new version. Until a new version is published, your design should follow v4.0.1. When a revision arrives, the changes that matter for encryption are usually in the requirement wording, the testing procedures and the future-dated items. Ask your assessor which version applies to your next assessment, and keep key management and TLS settings in configuration you can review and change.

What does the quote for this work include and how is it priced?

A quote follows from the written scope, which lists the databases and data flows, the design and migration tasks, the key management integration, the testing, the handover documentation and the evidence deliverables. Costs are mostly labor for design, implementation, testing and knowledge transfer, plus any retainer for ongoing support. Recurring costs usually include key rotation, patching, backup testing and periodic review, and these are often separated from the one-time build. We do not publish a price list. Ask for the scope, the assumptions behind each task, the client responsibilities and the items excluded.

How DeployOpen works on this

DeployOpen scopes the PostgreSQL encryption work in writing before any build starts, then implements it inside infrastructure you control and hands over the configuration, key handling and evidence your assessor will ask for. The work is aligned to the cardholder data environment you define, so the database controls can be reviewed by your team and your Qualified Security Assessor.

How we scope

  • Engagements are fixed-scope, with the systems, data stores and environments covered agreed in writing before work starts.
  • We map which PostgreSQL clusters store, process or transmit primary account numbers and which can affect them.
  • We agree whether column encryption, storage encryption or both apply, and which key custody model your organization uses.
  • Scope also records the transmission paths that need TLS and the connections that move cardholder data out of the database.

How we build

  • We configure encryption for the agreed PAN columns, with key material held outside the database server, in your key management system.
  • We set TLS for client, replication and backup connections, and document the protocol and certificate settings used.
  • We test that application roles can read decrypted values only where the design requires it, and that other roles cannot.
  • We verify encrypted backups and restores in a test environment before any production data is handled.

How we hand over

  • You receive the configuration, architecture notes and key lifecycle runbook for the encryption design.
  • The handover includes a control-to-evidence map so your team and assessor can trace each database control to its records.
  • We document the cardholder data environment boundary and the reasons each component is in or out of scope.
  • Knowledge transfer sessions cover key rotation, certificate renewal and how to request a fresh restore test.

How we support

  • Ongoing support, upgrades and continuous testing are available as a retainer that follows your PostgreSQL release schedule.
  • We retest encryption, TLS and access settings after changes to the schema, PostgreSQL version or key management system.
  • Compliance evidence is prepared for your assessment. DeployOpen does not issue audit reports, attestations or certifications; your QSA or assessor does.

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.