PostgreSQL for Healthcare
Patient data demands correctness, not speed hacks. PostgreSQL gives you both.
Variant Systems builds industry-specific software with the tools that fit the problem.
Why this combination
- ACID transactions guarantee data integrity for clinical records and medication orders
- Row-level security enforces PHI access controls directly in the database
- JSONB columns handle semi-structured clinical data without schema migrations
- Mature replication and backup tooling supports disaster recovery requirements
Why PostgreSQL for Patient Data
Healthcare data has unique demands. A medication order can’t partially commit. A patient record can’t silently lose a field during update. Lab results need to be queryable across decades of history. You need a database that treats correctness as non-negotiable.
PostgreSQL’s ACID compliance means every transaction either completes fully or rolls back entirely. There’s no in-between state where a patient has a prescribed medication but no dosage record. Beyond correctness, PostgreSQL’s feature set handles the variety of healthcare data - structured demographics, semi-structured clinical notes in JSONB, binary imaging references, and time-series vitals data. One database handles it all without forcing you into a polyglot storage nightmare. Advisory locks coordinate concurrent access to patient charts so two providers editing the same encounter don’t silently overwrite each other’s documentation. And PostgreSQL’s extension ecosystem means you can add specialized capabilities - pg_trgm for fuzzy patient name matching, btree_gist for exclusion constraints that prevent double-booking appointment slots, or pgvector for semantic search across clinical notes using embeddings.
Row-Level Security and PHI Protection
HIPAA requires that users only access the PHI they need for their role. Most applications implement this in application code - middleware checks, role gates, query filters. That works until someone writes a direct database query that bypasses the application layer.
PostgreSQL’s row-level security solves this at the database itself. You define policies that restrict which rows a given database role can see. A nurse in Department A can’t query patients in Department B, even from a raw SQL console. Combined with column-level permissions and view-based access patterns, the database enforces your access model regardless of which application or tool connects to it. This defense-in-depth approach is what auditors want to see. Policies compose naturally - you can layer temporal restrictions (a provider only sees records for patients with active appointments) on top of departmental access, all expressed in standard SQL predicates. When a new application connects to the database, it inherits the full security model automatically without any additional middleware implementation.
Audit Trails and Compliance
Healthcare regulations require knowing who accessed what data and when. A patient requests their access log. An auditor reviews six months of data access patterns. Your breach response team needs to determine exactly which records were exposed. Without comprehensive audit logging, you’re guessing.
We implement audit trails using PostgreSQL triggers that fire on every INSERT, UPDATE, and DELETE against PHI tables. The audit records land in append-only tables - no one can modify the history. Each entry captures the user, timestamp, operation type, and the before/after state of the data. Point-in-time recovery using WAL archiving means you can reconstruct the exact state of any record at any moment. These aren’t afterthought features. They’re architectural foundations.
Schema Design for Clinical Data
Clinical data is messy. A patient encounter might include structured vitals, free-text notes, coded diagnoses, and references to external imaging studies. Rigid schemas break when the next specialty workflow needs fields you didn’t anticipate.
We use a hybrid approach. Core entities - patients, encounters, providers, orders - live in normalized relational tables with strict foreign keys and constraints. Variable clinical attributes use JSONB columns with check constraints that validate structure without requiring migrations. Lab results and vitals partition by time for efficient range queries across patient history. Full-text search with tsvector indexes makes clinical notes searchable without an external search engine. The result is a schema that’s strict where it matters and flexible where clinical reality demands it.
Compliance considerations
Common patterns we build
- Patient records with JSONB for flexible clinical data attributes
- Trigger-based audit logging for every PHI read and write
- Partitioned tables for time-series clinical data and lab results
- Full-text search across clinical notes and documentation
Other technologies
Services
Building in Healthcare?
We understand the unique challenges. Let's talk about your project.
Get in touch