Why teams run HAPI FHIR on PostgreSQL in production
A team that needs a self-hosted FHIR server usually has to answer one question before anything else: which database will hold the data, and can the team operate it? The HAPI FHIR JPA server starter defaults to an embedded H2 database, which is meant for development. For production, the starter supports PostgreSQL and Microsoft SQL Server, and this page covers the PostgreSQL path. The database is where FHIR resources, their versions, search indexes and history all live, so its configuration and operation shape the server's behavior as much as the application code does.
PostgreSQL is released under the PostgreSQL License, a permissive open source license similar to the BSD and MIT licenses, so the database itself carries no license fee and can run in infrastructure you control. Licensing is only one part of the decision. Your team also needs to settle the HAPI dialect, connection pool sizing and collation, the PostgreSQL-specific indexes that arrived with HAPI FHIR 7.0, and the operating routines of backups, vacuum, replication and major version upgrades. Confirm which PostgreSQL major version your platform team supports and when that version reaches end of life, since the schedule determines when upgrades must be planned.
Before you commit, confirm three things with your database and FHIR teams: which HAPI FHIR release and JDK you will run, which PostgreSQL version your organization can support, and who owns recovery objectives for the FHIR data. The sections that follow turn these decisions into settings and routines. Each choice made at this stage affects how the server is backed up, tested and upgraded later, so it is worth recording them in the design before the first schema is created.
PostgreSQL settings and when each fits
This table compares the settings that shape a HAPI FHIR JPA workload on PostgreSQL: the HAPI dialect, JDBC pool sizing, PgBouncer, collation and encoding, the indexes added in HAPI 7.0, and the PostgreSQL major version. Read each row for when the setting fits and what it adds in complexity, storage or upgrade effort. Several of these choices are fixed once data loads, so settle them during planning before go-live.
| Setting | When it fits | Trade-off to weigh |
|---|---|---|
| HAPI dialect | Required for any PostgreSQL deployment of the JPA server | Must match the HAPI version you run; confirm the class name in the release documentation |
| JDBC connection pool size | Fits when pool limits are set per server instance and summed against database capacity | Larger pools add database load and memory; confirm limits against PostgreSQL connection settings |
| PgBouncer in front of PostgreSQL | Fits many application instances or Kubernetes replicas sharing one database | Adds a network hop and pooling-mode constraints; test HAPI behavior in the chosen mode before production |
| Collation and database encoding | Set when the database is created, so decide before any data loads | Changing later means rebuilding data; confirm the ordering and case rules your searches need |
| PostgreSQL indexes added in HAPI 7.0 | Fits deployments on HAPI 7.0 or later running PostgreSQL | Indexes add storage and write cost; confirm the exact index set in the 7.0 release notes |
| PostgreSQL major version | Fits new builds on a line that is still supported, such as 17 or 18 | Version 14 is supported only until November 12, 2026, so plan the upgrade path early |
How a FHIR workload stresses PostgreSQL differently
A HAPI FHIR JPA server does not behave like a typical application schema, so the PostgreSQL settings that suit a conventional web back end need a second look. Every create or update writes a new row in the resource history table rather than overwriting the current version, and each write also fans out into search index tables and link tables that the JPA layer populates for every searchable parameter. The result is that row counts grow on several tables at once, and the growth is driven by write volume and search parameter count rather than by the number of distinct resources. Autovacuum therefore has more dead and live tuples to process on the write path than a table-per-entity model would produce, and the default autovacuum thresholds may need tuning per table once you have measured the real write rate in your environment.
Index maintenance is the second pressure point. Search index tables are wide in number but narrow in each row, and their indexes are updated on every write, so bloat and index health matter as much as heap health. Connection counts also behave differently: the JPA layer, batch jobs and reindexing work can hold connections for long periods, so the pool sizing you choose in the HAPI configuration has to be checked against the PostgreSQL max_connections budget and any PgBouncer layer you place in front of the database. Confirm pool and transaction-mode settings with your HAPI version's documentation before you change them, because transaction pooling interacts with session state. The schema and storage-size topics in this group explain which tables grow fastest and how index storage can be reduced, so use them to decide which tables to watch first.
Plan monitoring around these effects before go-live. Track dead tuple counts, last autovacuum times, index bloat and active connections per application node on the HFJ tables, and rehearse a bulk load against a copy of your schema so you see the vacuum and connection behavior at realistic write rates. Ask your database team to confirm which PostgreSQL version and vacuum settings they will standardize on, because the choice of major version affects planner statistics handling during later upgrades.
Setting up HAPI FHIR on PostgreSQL step by step
This sequence takes a team from a chosen HAPI FHIR release and PostgreSQL major version to a verified JPA server with a schema created in PostgreSQL, search working and a clean reload proven. Each step ends with a check you can run before moving on.
Confirm the HAPI FHIR version and JDK requirement
The platform team picks the HAPI FHIR release and reads its upgrade and requirements notes before anything else is installed. HAPI FHIR 8.2.0 requires JDK 17, and the latest release line should be checked against the documented versions page for its own Java requirement. Record the exact release number, the JDK build and the FHIR versions you need (for example R4 or R5). Done when a written version record exists and the JDK on the build and runtime hosts reports the required major version.
Provision a supported PostgreSQL major version
A platform engineer installs a PostgreSQL major version that is still inside its community support window at the planned go-live date, checking the versioning policy for end-of-life dates. Confirm the version with your database administrators and your own support requirements, and check that the chosen version appears in the HAPI FHIR documentation for the release you picked. Done when the server reports its version and you have confirmed the end-of-life date in writing.
Create the database and roles
A database administrator creates a dedicated database for the FHIR schema, an owner role for schema changes and a separate application role with only the privileges the server needs at runtime. Use SCRAM password authentication, since MD5 password authentication is deprecated in PostgreSQL 18. Set the database encoding to UTF-8 and review the collation with your team before any data is loaded, because it is hard to change later. Done when a test login with the application role connects and cannot create objects in the public schema outside its grant.
Set the dialect and JDBC settings in the starter
A developer configures the JPA server starter to use the PostgreSQL dialect, the PostgreSQL JDBC driver and a connection URL pointing at the new database, with credentials supplied through environment variables or a secrets store rather than files in source control. Set the connection pool size deliberately and, if you place PgBouncer in front of the database, confirm that pooling mode is compatible with the connection behavior the server expects. Done when the application starts far enough to log its datasource configuration and the values match the intended host, database and role.
Run the schema migration
The team runs the schema creation or migration with the migrator step against the owner role, not the application role, and keeps the migration log with the release record. Review the generated tables and confirm that the expected HFJ tables exist in the target schema. Done when the migration completes without errors, the log is stored, and a query listing the HFJ tables returns the set you expected for that release.
Verify connectivity and search
A developer starts the server and creates a small set of test resources, such as a Patient and an Observation, through the REST API. Then run a search on a common parameter and confirm the returned bundle matches what was created, and check the server logs for errors. Done when a create, a read and a search succeed and the database shows rows in the resource and search index tables.
Reload from a clean state
Drop and recreate the target schema in a non-production environment, run the migration again and load the same test set from a known export file. Compare resource counts and a sample search result against the first run to show the process is repeatable. Done when both runs produce matching counts and results, and the steps are written down as the runbook for your environment. Moving data from an existing H2 development database is covered separately in the sibling topic on moving HAPI FHIR from H2 to PostgreSQL for production.
Backups, vacuum and replication for a FHIR database
A HAPI FHIR JPA server keeps its clinical record in PostgreSQL, so backup, maintenance and availability decisions carry directly into the FHIR API. The cards below cover the parallel operational components that protect that data and keep the database responsive, and they note where PostgreSQL leaves work to external tools.
Continuous archiving and point-in-time recovery
Plan recovery to a point in time, not only to the last nightly dump. Continuous archiving ships write-ahead log segments to storage you control, so a base backup plus archived logs can restore the database to a moment before a bad bulk load or an accidental delete. For HAPI FHIR, check that the base backup and the archive cover the same database the server uses, that archives are stored outside the primary database host, and that the restore procedure has been run on a separate environment. Confirm retention periods with your compliance owner.
Continuous archiving docsRoutine vacuum and analyze
HAPI FHIR writes new resource versions and index rows continuously, so dead tuples accumulate and planner statistics drift. Autovacuum usually handles this, but large history and search index tables may need per-table settings tuned against your load. Watch for tables that grow faster than autovacuum clears them, and schedule an ANALYZE after large bulk loads or reindexing work. Ask your HAPI FHIR operations contact which HFJ tables receive the most writes in your environment before changing defaults.
Streaming replication with hot standbys
A hot standby receives changes from the primary and can serve read-only queries, which can offload reporting or search traffic if the HAPI FHIR server is configured to use a separate read endpoint. A standby is not a backup on its own, because an error on the primary is replicated too. Confirm which read paths your HAPI FHIR configuration can send to a standby, and test that the application behaves correctly when a read returns slightly older data.
High availability docsSynchronous versus asynchronous commit
Synchronous replication makes a commit wait until standbys confirm it, which protects writes but adds latency to every FHIR create or update. Asynchronous replication keeps write latency low but can lose the most recent commits if the primary fails. Choose the mode per workload with your clinical and data owners, and measure the write latency it adds under realistic bulk and transactional loads before you commit to it. Record the decision and its loss tolerance in your operations runbook.
External failover tooling
PostgreSQL does not detect a failed primary or promote a standby by itself. Automatic failover therefore depends on a separate tool or orchestration layer, along with fencing to prevent two servers accepting writes. Ask which tool your team will operate, who is paged when it acts, and how the HAPI FHIR server reconnects after promotion. Test a failover in a non-production environment before relying on it for clinical traffic.
Failover docsConnection pooling with PgBouncer
Each HAPI FHIR application instance holds a pool of database connections, and multiple instances can exhaust PostgreSQL connection limits during peak load. PgBouncer is one option to place between the application and the database to multiplex connections. Confirm its pooling mode is compatible with the transaction and session behavior of the HAPI FHIR JPA server and the Hibernate settings in your build, and test it before production use. Confirm this choice in your own environment rather than assuming it fits.
PgBouncer projectChoosing a PostgreSQL major version and upgrade method
For a new HAPI FHIR JPA server, the main question is which supported major version to start on, and how long that version will receive fixes. PostgreSQL releases a new major version about once a year and supports each one for 5 years after its initial release. Version 18 was first released on September 25, 2025, and is supported until November 14, 2030. Version 17 is supported until November 8, 2029, and version 16 until November 9, 2028. Starting on the newest version that your HAPI FHIR release is certified to run against usually gives the longest support runway.
- Support window: Check the end-of-life date for each candidate version against your planned service life, not only against today's release.
- HAPI compatibility: Confirm in the HAPI FHIR version documentation that the PostgreSQL version you choose is supported for the exact HAPI release you will deploy.
- Driver and dialect: Match the PostgreSQL JDBC driver and the HAPI dialect setting to the chosen major version as the release notes direct.
- Test environment: Build the first schema in a staging environment that mirrors production settings before loading any data.
- Minor version cadence: Plan a recurring window for minor releases, which PostgreSQL ships at least once every three months.
Before going live, confirm the supported version pairing in writing with your HAPI FHIR support provider and record it in your change management system.
Many organizations already run PostgreSQL for other systems and want HAPI FHIR to join that estate. In this case, the version decision is usually already made, and the work is to confirm that the shared version is one HAPI FHIR supports and that it is inside its support window. Minor updates are the routine case: PostgreSQL states that minor releases never change the internal storage format, so updating means replacing the executables and restarting the server, with no data conversion step.
- Minor updates: Apply them on your normal patch cycle, since they keep the storage format and need only a restart.
- Major upgrades: Treat any move to a newer major version as a separate project with its own rehearsal and rollback plan.
- Shared instance risk: A major upgrade of a shared server affects every database on it, so coordinate with the owners of the other systems.
- Extensions and drivers: Check that extensions and client drivers used by other applications support the target version.
- Version pinning: If HAPI FHIR is not yet certified for the target major version, keep the existing version and schedule the upgrade after the HAPI release catches up.
Ask your HAPI FHIR support provider to confirm compatibility for your specific HAPI release before scheduling any major upgrade of the shared server.
PostgreSQL documents three major upgrade methods. Each one trades downtime, disk space, operational complexity and the ability to roll back. The choice depends on database size, the acceptable outage window and how much spare storage exists during the cutover. Dump and restore is the simplest and most portable method, and it rebuilds the data files from scratch. pg_upgrade converts the existing data files in place or with links and is faster on large clusters. Logical replication copies changes between versions while the old server keeps running.
- Dump and restore: Uses pg_dumpall and a restore into the new version. It is simple to reason about, but downtime grows with data size, and it needs enough free disk for the dump.
- pg_upgrade: Converts data files in place, with the option of parallel jobs. PostgreSQL 18 retains planner statistics across major upgrades and adds a --swap option, which reduces some cutover work.
- Logical replication: Works between different major versions and can reduce downtime to several seconds, according to PostgreSQL's upgrade documentation. It requires careful handling of sequences, schema changes and replication setup.
- Rollback path: Keep the old cluster intact until the new one has passed verification, because pg_upgrade changes files in ways that complicate reverting.
- Verification: Compare row counts, FHIR search results and HAPI FHIR startup logs on the new version before reopening access.
Before choosing a method, test it on a copy of production data and measure the downtime you actually observe.
A FHIR server used for clinical or patient-facing workflows often cannot accept a long maintenance window. For this situation, the choice narrows to logical replication, or to pg_upgrade combined with a short, rehearsed cutover. Dump and restore is rarely suitable unless the dataset is small enough that a full restore fits the agreed window. Whatever method you choose, the outage is only one part of the risk: replication lag, schema differences and application behavior during cutover need equal attention.
- Replication setup: Logical replication requires the source and target to be configured in advance, so plan the publication and subscription steps before the window.
- Write freeze: Decide how HAPI FHIR writes are paused or redirected during the final sync, and document who approves it.
- Sequence handling: Confirm that sequences and identity values are synchronized at cutover, since logical replication does not copy them automatically.
- Standby as safety net: Hot standby servers can serve read-only queries during the migration, which may keep read access available while writes are paused.
- Failover tooling: PostgreSQL does not detect primary failure or promote a standby by itself, so confirm which external tool will handle any failover during the window.
Ask your database and HAPI FHIR teams to write down the exact cutover runbook, including the rollback decision point, before the change window is booked.
Securing the PostgreSQL connection and data
The database sits under every FHIR resource, search index and audit trail, so its controls decide who can reach that data and how it can be recovered. The cards below cover how the HAPI server connects, how the database authenticates and encrypts that connection, which roles the server and migrator should hold, and how backups are protected. HAPI FHIR does not provide a complete security layer, so these database controls must sit alongside server-side authorization and audit.
Choose the authentication method
PostgreSQL documents password, GSSAPI, SSPI, LDAP, RADIUS, certificate, PAM and OAuth methods. For the HAPI server, use SCRAM rather than MD5, since PostgreSQL 18 deprecated MD5 password authentication in favor of SCRAM. Confirm which method your identity platform can support for the application account, and whether the migrator needs the same method as the runtime account. Record the choice in your configuration review.
Authentication methodsEncrypt the JDBC connection
Set the JDBC URL to require TLS and verify the server certificate, so the connection is not accepted from a host presenting any certificate. Check the driver version and the certificate chain your Java runtime trusts, because a mismatch often shows up only at startup. Certificate-based client authentication can be added for the application account when your team manages client certificates, which reduces the reliance on a stored password.
Separate runtime and migrator roles
Create one role that owns the schema, used only by the migrator, and a narrower role for the running server that can read and write HFJ tables but cannot alter them. The server does not need DDL rights during normal operation. Confirm with the HAPI documentation for your release which privileges the migrator and runtime need, and test both roles against a non-production copy before granting them in production.
Protect data at rest in infrastructure
PostgreSQL does not itself provide a general encryption-at-rest feature in the way many teams expect, so encryption of data files usually comes from the storage layer: encrypted volumes, encrypted cloud disks or an encrypted SAN. Ask the platform team which layer covers the data directory, WAL and any replica volumes, and confirm that key management is separate from the database host.
Encrypt and restrict backups
Continuous archiving and point-in-time recovery copy the full database, including every FHIR resource and audit-relevant record, to another location. Encrypt base backups and WAL archives before they leave the database host, store keys apart from the archive, and restrict who can restore. Test a restore in a segregated environment, since an unreadable or misplaced backup is itself a security incident.
Continuous archiving docsPair database controls with server authorization
Database roles limit what the server account can do, but they cannot tell which clinician may read a given patient. That decision belongs to the HAPI authorization, consent and audit interceptors and the identity provider in front of them. Document which controls live in the database, which live in the server and which live in the network, and test that a valid database session cannot bypass the server's access rules.
How HAPI FHIR, PgBouncer and PostgreSQL connect
The diagram starts with clients sending FHIR requests through a reverse proxy to the HAPI FHIR JPA server. The server reaches PostgreSQL through PgBouncer, which pools connections so the database is not flooded. The primary streams changes to a hot standby, and archived WAL goes to a separate backup target. The dashed boundary marks the database network: check that only the application tier can reach PgBouncer and PostgreSQL, and that backup and replication traffic stays inside it.
Request path from clients to PostgreSQL, with replication and WAL archiving inside the database network.
Questions teams ask before running HAPI FHIR on PostgreSQL
What drives the cost of a PostgreSQL setup for HAPI FHIR?
Cost depends mostly on how many environments you need, how much database work is new to your team, and how much operational responsibility you keep. Expect one-time costs for design, build, configuration and testing of the HAPI JPA server against PostgreSQL, and recurring costs for database hosting, storage, backups, monitoring, patching and on-call coverage. Storage and index growth scale with the FHIR data you load, so ask any quote to state the expected data volume and growth assumptions. Also ask who pays for each piece: your staff, a partner, your cloud provider or a database vendor. The PostgreSQL License is permissive, so the database software itself carries no license fee; support contracts from third parties are optional and separate.
How long does a HAPI FHIR PostgreSQL setup take?
Duration is set by the number of environments, the complexity of your network and identity setup, whether you need high availability and point-in-time recovery, and how much testing your clinical and integration teams require. A minimal build for a development environment moves much faster than a production build with replication, tested backups and a documented upgrade plan. Your own change approval cycles and security reviews often take longer than the technical work. Ask for a timeline that lists each milestone and what must be ready before it starts, rather than a single end date.
What must our team provide before a PostgreSQL project starts?
Plan to provide the following before the build begins:
- Database administrators who can review connection, storage, backup and replication design, and who will own the database after handover
- Environments in your cloud accounts, data centers or private network, with the required sizing and access rules agreed
- Network access between the HAPI server, PostgreSQL, identity provider, load balancers and monitoring tools, approved by your network and security teams
- Representative FHIR data or a test data plan, plus a clear owner for data classification and retention decisions
Also name a clinical or business owner who can accept test results. Missing items in any of these areas are a common source of delay.
Can our internal team set up HAPI FHIR on PostgreSQL alone?
A capable internal team can do it, provided it has Java and Spring Boot experience to run the HAPI JPA server starter, and database administration skills for PostgreSQL. The harder parts are usually not the first deployment but the operating model: tuning connection pools, verifying collation and indexes, designing backups and recovery, planning major upgrades and running failover. PostgreSQL does not include automatic failover software, so you must choose and operate an external tool if you need it. Assess your team against these skills honestly, and consider a fixed-scope engagement for design and handover while your staff keep ownership.
How do we plan a PostgreSQL major upgrade without long downtime?
Plan the upgrade as a project with rehearsals. PostgreSQL's upgrade documentation describes three main routes: dump and restore, pg_upgrade, and logical replication. Logical replication works between different major versions and, per the PostgreSQL upgrading documentation, can allow a major upgrade with only several seconds of downtime. Check the HAPI FHIR version you run against the PostgreSQL versions it supports before you choose a target. Supported PostgreSQL releases are listed in the PostgreSQL versioning policy, and version 14 reaches end of support on November 12, 2026, so plan that move early. Rehearse the chosen route on a copy of production data and measure the switch-over window before you commit.
Do we need high availability before going live?
Whether you need it depends on your clinical and service-level requirements, which should come from your own risk assessment rather than a default. PostgreSQL supports hot standby servers and both synchronous and asynchronous replication, so the database layer can be designed for resilience. Synchronous replication means commits wait for standbys, which affects write latency, while asynchronous replication can lose the most recent commits on failover. Automatic failover requires external tools, and each option adds operational work. Decide these trade-offs with your database administrators and document the recovery targets you accept.
Which PostgreSQL settings should we verify before go-live?
Engineers should verify the HAPI dialect setting, connection pool sizing, database collation and the indexes that the HAPI version expects. Confirm that backups and point-in-time recovery work by restoring to a separate environment, because untested backups are the most common gap. Check that vacuum and autovacuum settings suit a write-heavy FHIR workload, and that monitoring alerts cover disk growth and replication lag. Confirm the exact property names and default values in the HAPI FHIR and PostgreSQL documentation for your versions rather than relying on memory.
How DeployOpen scopes and delivers HAPI FHIR on PostgreSQL
DeployOpen plans, implements, hardens, backs up, documents and supports self-hosted open-source platforms inside the infrastructure you control, and a HAPI FHIR JPA server on PostgreSQL is delivered the same way. The work runs in your cloud accounts, data center or air-gapped network, so the database, the HAPI FHIR server and their keys, backups and network paths stay under your governance. Scope usually covers the starter deployment, the PostgreSQL instance or cluster, connection pooling, the backup and restore design, the upgrade plan, and the documentation your security and compliance teams need to review the system.
Engagements are fixed-scope. Before work starts, the scope, deliverables and timelines are agreed in writing, so you can see which items are included and which are left to your team. For this topic, the written scope should name the PostgreSQL major version and its support end date (confirm against the PostgreSQL versioning policy), the HAPI FHIR release and its Java requirement, the collation and dialect settings, the restore test you will accept as evidence, and who owns replication and failover tooling, since PostgreSQL does not detect a primary failure on its own. Ask the partner to state each of these as a deliverable rather than a general intent.
A quote follows from that written scope, so the price reflects the components, environments and handover items you agreed rather than an estimate made in advance. Ongoing support, upgrades and continuous testing are available as a retainer, which suits the recurring work on PostgreSQL minor releases, major-version planning and periodic restore tests. Ask any partner, DeployOpen included, to confirm in writing who is responsible for each recurring task after go-live and how changes to the scope are priced and approved.

