How to Make PostgreSQL HIPAA Compliant: A Step-by-Step Guide

Product Pricing
Ready to get started? Book a demo with our team
Talk to an expert

How to Make PostgreSQL HIPAA Compliant: A Step-by-Step Guide

Kevin Henry

HIPAA

February 07, 2026

7 minutes read
Share this article
How to Make PostgreSQL HIPAA Compliant: A Step-by-Step Guide

Making PostgreSQL HIPAA compliant means putting the right technical and administrative safeguards in place to protect electronic protected health information (ePHI). This step-by-step guide shows you how to harden PostgreSQL, prove accountability, and reduce breach risk while keeping performance and usability intact.

Encrypt PHI at Rest and in Transit

Encryption is a foundational control that limits exposure if systems, media, or networks are compromised. You should protect ePHI both on disk and over the wire using well-vetted algorithms and configurations.

At rest

  • Use AES-256 encryption for storage volumes or disks. On premises, enable full-disk/volume encryption; in the cloud, use provider-managed encrypted volumes with restricted key access and audit trails.
  • Apply column-level encryption with the pgcrypto extension for especially sensitive fields (for example, SSN or diagnosis codes). Keep keys outside PostgreSQL and decrypt only in trusted code paths to minimize PHI exposure.
  • Avoid indexing sensitive encrypted columns directly. If you must support equality queries, evaluate deterministic encryption or keyed hashes/“blind indexes,” understanding the trade-offs and potential leakage patterns.
  • Ensure backups, snapshots, temporary files, and WAL archives are encrypted to the same standard as primary storage.

In transit

  • Enable SSL/TLS protocols and enforce TLS-only connections. Set ssl = on, restrict to strong protocols (for example, ssl_min_protocol_version = 'TLSv1.2' or higher), and prefer modern cipher suites that provide forward secrecy.
  • Use server certificates from a trusted CA and configure ssl_cert_file, ssl_key_file (with strict file permissions), and ssl_ca_file to validate clients and servers.
  • Require encrypted connections in pg_hba.conf via hostssl entries only; optionally require client certificates (mTLS) for administrative and service accounts.
  • Pair TLS with strong authentication such as SCRAM-SHA-256 passwords, Kerberos/GSSAPI, or certificate authentication, and disable legacy/weak methods.

Implement Role-Based Access Controls

Role-Based Access Control (RBAC) helps you meet HIPAA’s “minimum necessary” standard by mapping privileges to job duties instead of individuals. You grant access to roles, then assign users to those roles.

  • Create group roles (no-login) for common duties—reader, writer, reporting, and admin—and grant object privileges to those roles, not to users directly.
  • Lock down defaults: revoke broad PUBLIC privileges, grant only what each role needs, and use ALTER DEFAULT PRIVILEGES so new tables inherit the same tight controls.
  • Separate duties for DBAs, security auditors, and application service accounts. Avoid superuser for routine operations; employ controlled, audited elevation only when necessary.
  • Centralize identity and authentication where possible, and review role memberships regularly to remove stale access.

Enable Audit Logging with pgAudit

Audit trails demonstrate who accessed what and when—critical for incident response and HIPAA accountability. pgAudit logging adds structured, fine-grained records beyond standard PostgreSQL logs.

Configuration steps

  1. Preload the extension by setting shared_preload_libraries = 'pgaudit' and restarting the cluster.
  2. Enable it per database with CREATE EXTENSION pgaudit;
  3. Choose coverage: for broad visibility, set pgaudit.log = 'read, write, ddl, role, misc' (or a narrower subset to reduce volume). Keep pgaudit.log_parameter off in production to avoid leaking PHI into logs.
  4. Strengthen base logging: turn on logging_collector, use CSV logs, set a rich log_line_prefix, and enable log_connections, log_disconnections, and log_lock_waits.
  5. Ship logs to a secure, write-once target (for example, an immutable object store or SIEM), protect them with RBAC, and retain per policy. Monitor for anomalies such as mass reads or off-hours access.

Configure Row-Level Security Policies

Row-Level Security (RLS) enforces per-row access rules inside the database, so even valid users see only the PHI they are permitted to view or change.

Ready to simplify HIPAA compliance?

Join thousands of organizations that trust Accountable to manage their compliance needs.

Practical pattern

  • Enable RLS on PHI tables: ALTER TABLE patients ENABLE ROW LEVEL SECURITY; Then create policies that filter rows using session context (for example, tenant ID or user ID provided by the application).
  • Example: limit reads and updates to a user’s tenant—CREATE POLICY tenant_isolation ON patients FOR ALL USING (tenant_id = current_setting('app.tenant_id', true)::uuid);
  • Enforce RLS even for table owners with ALTER TABLE patients FORCE ROW LEVEL SECURITY; Reserve superuser-only access for break-glass procedures and audit it rigorously.
  • Test policies from representative roles to confirm least-privilege access and acceptable query plans.

Develop Secure Backup and Recovery Plans

HIPAA stresses availability and integrity. Your backup strategy must protect PHI, support point-in-time recovery, and prove you can restore quickly when it counts.

  • Perform regular base backups and archive WAL for continuous protection. Tools like pgBackRest or Barman can orchestrate this reliably.
  • Encrypt all backup data with AES-256 encryption and store media offsite or in immutable storage. Control access via RBAC and monitor with audit logs.
  • Define clear RPO/RTO targets, run routine restore drills to a clean environment, and document the results. Treat successful test restores as a release criterion.
  • Protect the backup pipeline: sign artifacts, verify checksums, and avoid PHI in backup file names or operational logs.

Manage Encryption Keys Outside Database

Strong cryptography fails if keys are mishandled. Keep keys out of PostgreSQL and manage them in a dedicated system with strict controls and auditing.

  • Use a Hardware Security Module (HSM) or cloud Key Management Service for generation, storage, and access control. Favor FIPS-validated modules when required.
  • Adopt envelope encryption: application data keys protect columns or files; a master key in the KMS/HSM protects those data keys. Store only key identifiers in the database.
  • Rotate keys on a defined schedule and upon personnel or vendor changes. Track key versions per record so you can decrypt during migration.
  • Apply dual control and separation of duties for key administration. Monitor and retain key-access audit logs alongside database logs.
  • Back up key material securely per vendor guidance; never co-locate key backups with encrypted data.

Ensure Business Associate Agreements

A Business Associate Agreement (BAA) documents each party’s responsibilities when vendors handle PHI. Any provider touching your PostgreSQL environment—hosting, managed database, backup, monitoring, or support—should offer a BAA and only use HIPAA-eligible services and configurations.

  • Inventory all services that may store, process, transmit, or log PHI and obtain a Business Associate Agreement (BAA) for each.
  • Define encryption, access control, auditing, breach notification timelines, and data disposition in the BAA. Verify the provider’s controls during onboarding and at regular intervals.
  • Limit PHI exposure to vendors by design—scrub identifiers from alerts, traces, and tickets unless absolutely necessary and covered by the BAA.

Conclusion

To make PostgreSQL HIPAA compliant, encrypt PHI at rest and in transit, enforce RBAC and RLS for least-privilege access, enable pgAudit logging for accountability, implement tested encrypted backups, manage keys in a dedicated KMS/HSM, and secure BAAs with every party that may touch PHI. Treat these controls as a cohesive program and verify them continuously.

FAQs.

Use AES-256 encryption for disks, volumes, and backups. For especially sensitive fields, apply column-level encryption with the pgcrypto extension and keep keys external to the database. Protect all connections with modern SSL/TLS protocols (TLS 1.2 or 1.3) and strong authentication such as certificates or SCRAM-SHA-256.

How does Row-Level Security improve PHI protection?

Row-Level Security enforces per-row filters inside PostgreSQL, so users and applications only see PHI they are authorized to access. Policies can reference session context (for example, tenant or user IDs) to prevent cross-tenant or cross-patient reads and updates, reducing the blast radius of credential misuse.

What is the role of audit logs in HIPAA compliance?

Audit logs create a tamper-evident trail of access and changes. With pgAudit logging, you can capture reads, writes, and DDL, link events to authenticated identities, and forward records to a SIEM. This supports incident detection, forensics, user accountability, and documented proof of compliance activities.

How should encryption keys be managed for HIPAA adherence?

Store and control keys outside PostgreSQL in a Hardware Security Module (HSM) or cloud KMS. Use envelope encryption, restrict key use with RBAC and policy, rotate keys routinely and on personnel changes, log all key operations, and keep key backups separate from encrypted data. Never embed or store keys in the database itself.

Share this article

Ready to simplify HIPAA compliance?

Join thousands of organizations that trust Accountable to manage their compliance needs.

Related Articles