Moving HAPI FHIR from H2 to PostgreSQL for production

Moving a HAPI FHIR JPA server from embedded H2 to PostgreSQL is a configuration and testing change, but moving existing data is a FHIR export and reload job. This page sets out what maps cleanly, the documented paths and the work involved.

On this page

Why a team running HAPI FHIR on H2 needs to move to PostgreSQL before production

If your HAPI FHIR JPA server still runs on the embedded H2 database that the starter uses by default, you need a production database before real patient or operational data arrives. The switch to PostgreSQL in the starter configuration is a small change. The effort comes from moving the data you have already loaded, adjusting tests that were written against H2, and confirming that the new database behaves the way your applications expect.

H2 is the default because it lets a developer start the server with no external infrastructure. It is intended for development and pilots, not for production storage. The JPA server starter supports PostgreSQL and Microsoft SQL Server for production and does not support MySQL, so the realistic choices for a new production database are narrower than many teams assume. If your organization has not yet chosen between PostgreSQL and SQL Server, settle that decision first, because it determines the driver, dialect and operations skills you will need.

Ask your team three questions before you change any configuration. Which data must survive the move, and is it reproducible from source systems or only held on the H2 file? Which tests, scripts or client applications depend on H2-specific behavior, such as in-memory startup or a particular SQL dialect? Who will own backups, upgrades and access to the new database after go-live? The answers set the scope. Keep in mind that the data move should go through FHIR exports and imports rather than a database copy, because the schema is generated by HAPI FHIR and changes between versions. Confirm the exact steps for your HAPI FHIR version in the HAPI FHIR JPA server introduction and in the hapi-fhir-jpaserver-starter repository before you plan the work.

What maps cleanly from H2 to PostgreSQL and what does not

This table compares the embedded H2 development setup with a PostgreSQL production setup across the areas a team will touch when switching. Read each row as a question to answer in your own environment, since behaviour that the JPA layer hides can still surface in custom SQL, collation, test fixtures and backups. The main takeaway is that the application code often carries over, but the database-specific edges need explicit testing and sign-off.

AreaH2 (embedded default)PostgreSQL (production)
Datasource configurationEmbedded default in the JPA server starter, with no external host to manageExternal database with URL, credentials, driver and connection pool settings that you own and secure
Schema creationCreated automatically on first start in the embedded databaseConfirm how the schema is initialized and migrated for your HAPI FHIR version before first production start
Resource storageResources stored through JPA entities in the HFJ tables, which carry over unchanged in logical structureSame JPA entities, but column types, sequence behaviour and index definitions are PostgreSQL-specific; confirm the dialect setting
Search behaviourResults tested against H2 may differ in string matching, case handling and sortingString matching depends on collation and case sensitivity; test searches on realistic data rather than assuming parity
Custom SQL or direct database accessAd hoc SQL written for H2 may run without change in development onlyCustom SQL and reporting queries need review for PostgreSQL syntax and quoting before they are trusted
Test fixturesTest suites often use in-memory H2, so tests may pass without exercising PostgreSQL behaviourRun integration tests against a PostgreSQL instance matching production major version, such as with a container
Backups and recoveryNo separate database service; backup is usually a file copy during developmentPlan logical or physical backups and a restore test; confirm backup scope with your database team
Direct database copy between enginesNot applicableCopying H2 files into PostgreSQL does not work; move data through FHIR exports and imports instead

Documented paths for switching the database and moving data

The starter defaults to an embedded H2 database, so moving to PostgreSQL is a configuration change in the starter's datasource settings, followed by a restart against an empty PostgreSQL database. The starter supports PostgreSQL and Microsoft SQL Server for production and does not support MySQL, so the target must be one of those two. Confirm the exact property names in the configuration file for the release and packaging you deploy (Docker image, Spring Boot, WAR or Helm chart), since the mapping of settings can differ between them. Review the hapi-fhir-jpaserver-starter repository for the configuration layout that matches your release.

  • Target database: Create an empty PostgreSQL database and a dedicated role for the server, with rights limited to that database.
  • Driver: Confirm the PostgreSQL JDBC driver is on the classpath for the packaging you use.
  • Connection settings: Set the URL, username and password through datasource properties, ideally sourced from a secrets store rather than a file in version control.
  • Environment mapping: Container and Kubernetes deployments usually pass these as environment variables, so check how your packaging maps them.
  • Reversibility: Keep the H2 configuration under version control so a failed switch can be reverted quickly.

Check that the server starts cleanly against the empty PostgreSQL database and logs the expected JDBC URL before any clinical data is loaded.

How to switch the starter to PostgreSQL and cut over without losing FHIR data

This sequence moves a HAPI FHIR JPA starter from its embedded H2 database to PostgreSQL by rebuilding the data through FHIR exports and imports, then running both systems side by side until the new server is proven.

  1. Inventory resources, configuration and interceptors

    The team lists the resource types and versions in use, the search parameters and custom code, the interceptors and authorization rules, and every starter setting that differs from the defaults. The owner is the platform lead with input from the application teams that call the server. Done means the inventory is signed off and each custom item has a named owner and a decision on whether it moves unchanged, changes, or retires. Confirm the FHIR version and JDK requirements against the HAPI FHIR versions documentation before anything else is pinned.

  2. Choose and provision a supported PostgreSQL major version

    Select a PostgreSQL major version that is still inside its support window on the planned go-live date, and check the dates against the PostgreSQL versioning policy before any build starts, since a version nearing end of support creates an upgrade obligation shortly after launch. The infrastructure team provisions the database host or managed instance in the environment you control, with storage, backups and network access defined. Done means the server is reachable from the test environment, the chosen major version is recorded, and the support end date is written into the operations plan.

  3. Run a pilot on PostgreSQL with the starter configuration

    Point a non-production instance of the JPA server starter at the new PostgreSQL database and let it create its schema, using the same starter version and configuration that will go live. The developers confirm the datasource settings, the PostgreSQL driver and the schema initialization in the logs, and they record any startup errors or warnings. Done means the server starts cleanly, the schema exists, and a small set of test resources can be created, read, searched and deleted through the API.

  4. Update and run the test suite

    Remove assumptions that were only true on H2, such as case handling in searches, the behavior of test fixtures that rely on the embedded database being recreated on each run, and any hard-coded database URLs or dialect settings in test profiles. The QA lead reruns the functional, search and interceptor tests against PostgreSQL and records each failure with its cause. Done means the suite passes against PostgreSQL, the changes are committed to version control, and each change is explained in a short log that the security and application owners have read.

  5. Export data from H2 and reload into PostgreSQL

    Export resources from the H2-backed server through the FHIR API, using bulk export or paged searches for each resource type, and load them into the PostgreSQL server through the API rather than copying H2 table files or running SQL between the two schemas. The data team checks resource counts per type against the H2 source and spot-checks a sample of resources for content, identifiers and references. Done means the counts reconcile, the reference integrity checks pass, and the load log is retained as evidence. Copying database files is not a supported route between the two databases.

  6. Run H2 and PostgreSQL in parallel

    Keep the H2 server available in read mode while the PostgreSQL server receives the same writes from client applications, or replay recent writes from a log if that is what your integration design supports. The operations team compares responses to a set of representative queries on both servers and tracks errors, latency and any resources that differ. Done means a defined period of parallel operation ends with zero unexplained differences in the agreed query set, and the team has confirmed the process to replay writes made during the parallel run.

  7. Cut over clients to the PostgreSQL server

    Switch client endpoints, DNS or the reverse proxy to the PostgreSQL-backed server, then freeze writes to H2 for the final reconciliation. The release manager runs a final count and sample comparison, confirms authentication and audit logging are active on the new server, and sets a rollback point with the H2 instance kept intact. Done means client traffic is confirmed against the new server, the audit trail shows the expected access, and the rollback decision window has closed with no open defects.

  8. Decommission H2 after the rollback window

    Once the agreed rollback window has passed without a return to H2, the team archives the H2 data files and the final export under the organization's retention policy, removes H2 from the configuration and images, and deletes the embedded database from any remaining environments. The owner records the archive location and the retention end date. Done means no service references H2, the archive is verified readable, and the PostgreSQL backup and restore procedure has been tested at least once.

Which tests and fixtures change when the database changes

The integration tests most likely to break when you move from H2 to PostgreSQL are the ones that start the JPA server with its embedded default and assume the database behaves like H2 in memory. Start by listing every test class that boots the server, every fixture that writes resources directly through the database layer, and every test that runs with a shared in-memory schema. Those are the suites your team must review first. Confirm which of them rely on a fresh database per test, because a shared PostgreSQL instance can carry rows from one test into the next unless each test cleans up or uses its own schema.

Transaction and sort behaviour are the next areas to check. Tests that depend on the order of rows returned without an explicit _sort parameter, on ID generation order, or on how a failed transaction rolls back may pass on H2 and fail on PostgreSQL. Search assertions need the same scrutiny, particularly tests that match on case, accents or partial strings. Confirm whether your expected results were written against H2 output, and whether they reflect what a FHIR client should receive. Where a test asserts on an exact count or a specific ordering, decide whether the assertion is correct or whether it simply captured the old database's behaviour.

To run the same suite against PostgreSQL in CI, start a PostgreSQL container as a service in your pipeline, point the datasource settings at it, and run the existing test classes unchanged wherever possible. Keep the H2 run as a fast local option if your developers need it, but make the PostgreSQL run the gate for merges. Pin the PostgreSQL major version used in CI to the one you run in production, and confirm the version against the PostgreSQL versioning policy before you do. Record which tests were changed, skipped or adjusted during the switch, and have a reviewer confirm each change so the suite still tests what it was written to test.

What drives the cost and duration of the move

This table lists the factors that change the effort of moving a HAPI FHIR JPA server from H2 to PostgreSQL, with who carries each cost and whether it is one-time or recurring. Use it to see which items in a quote are fixed by your environment and which ones you can reduce. The main takeaway is that data volume, custom code and the number of connected systems usually matter more than the database switch itself.

DriverWhy it changes cost or effortOne-time or recurringWhat to ask for in a quote
Data volume and resource typesLarger stores take longer to export, load and verify, and more resource types mean more mapping and validation work.One-timeExport and reload plan by resource type, with a test load timed on a copy of production data.
Custom interceptors and search parametersCustom Java code and extra search parameters must be rebuilt, retested and checked against the PostgreSQL behavior.One-timeInventory of each interceptor and custom search parameter, with the work estimated per item.
Client systems to repointEvery application that calls the server may need a new base URL, credentials or changed search behavior.One-timeList of connected systems, owners and the cutover order agreed with each owner.
Test coverageThin automated tests mean more manual regression testing before the cutover can be trusted.One-timeTest scope covering the FHIR operations you use, with the environments and data sets used for each run.
Identity and audit integrationsConnections to your identity provider, consent services and audit logging must be retested against the new deployment.One-timeNamed integrations, the test accounts needed, and who on your side approves each one.
PostgreSQL hosting modelA managed service shifts patching, backups and failover to the provider, while a self-run cluster puts that work on your team.RecurringWhether high availability, backups and point-in-time recovery are included, and who operates each.
Number of environmentsEach environment needs its own database, configuration, data load and test cycle.One-time and recurringPer-environment setup steps and whether refresh from production is included.
Database operations after go-liveUpgrades, vacuum, monitoring and restore testing continue for the life of the server.RecurringOperating responsibilities after go-live, support hours and the upgrade approach for PostgreSQL and HAPI FHIR.

What usually goes wrong in an H2 to PostgreSQL move

Most problems in this move come from treating the database as the only thing that moves. The server configuration, the search behavior, the identifiers clients hold and the recovery path all change together, so each risk below needs a named owner and a check before cutover.

Copying the H2 file as a migration

Copying the embedded H2 database file into PostgreSQL is not a supported migration path, and the H2 file reflects one development setup rather than a reviewed dataset. Plan the move as a FHIR-level export and import, then compare resource counts and sample reads between the old and new servers. Ask the team that owns the H2 data to confirm what actually lives in it before anyone starts the cutover work.

Losing custom search parameters and interceptors

Custom search parameters, interceptors and server settings often exist only in the development configuration, so they disappear when the server is reloaded on PostgreSQL. Inventory every custom SearchParameter resource, every registered interceptor and every server property before the move. Then confirm each one loads on the new server and returns expected results for a set of test searches.

Security docs

Unbounded connection pool settings

A connection pool left at defaults or set without a ceiling can open more connections than PostgreSQL is configured to accept, which shows up under load as refused connections or stalled requests. Set a maximum pool size that fits the PostgreSQL connection limit with room for administrative sessions. Decide whether a pooler such as PgBouncer sits in front of the database, and test the setting under realistic concurrent search and write traffic.

Reference IDs changing during re-import

When resources are re-imported without preserving their logical IDs, every stored reference from other resources and every client bookmark breaks silently. Verify that the export and import keep logical IDs and that references between resources resolve after load. Run a sample of reference-following searches on the target server and treat any unresolved reference as a blocker for cutover.

Thin test coverage before cutover

Test suites written against H2 often pass on PostgreSQL only by accident, because SQL behavior, collation and case handling differ between the two databases. Run the existing integration tests against a PostgreSQL instance, and add tests for searches, paging, history and any custom logic. Record the test results so the team can show what was verified before the switch.

Skipping backup and restore testing

A PostgreSQL server that has never been restored from its own backups has an unverified recovery path, and the first real restore is the wrong time to find out. Take a backup, restore it to a separate instance, start the HAPI server against the restored copy and run the same verification searches. Confirm that point-in-time recovery is configured if you require it, and record how long the restore took.

PostgreSQL archiving docs

Questions teams ask before moving HAPI FHIR to PostgreSQL

How much effort does moving HAPI FHIR from H2 to PostgreSQL take?

The database switch itself is small: the starter is configured to point at PostgreSQL and the schema is created on first start. The effort sits in everything around it: test suites that assumed H2, deployment pipelines, backup and restore routines, connection pool sizing, and the data movement plan. Effort rises with the number of custom interceptors, the volume of data, how many environments need to be rebuilt, and whether the team has run PostgreSQL in production before. Ask any partner to split the quote into configuration, test changes, data migration, operations handover and parallel run, so you can see which part drives the total.

How long does the move from H2 to PostgreSQL take?

Duration depends mostly on the data volume to be moved, the number of environments, and how much of the test suite must be reworked. No duration figure is supplied for this move, so treat any number you receive as an estimate that needs a written basis. Ask for milestones with dates: database provisioning, configuration in a non-production environment, test changes, a rehearsal of the data move, and a cutover window. A rehearsal on a copy of realistic data is the most useful signal for timing the production cutover.

What does the move need from our internal team?

Expect your team to provide access to the target infrastructure, the existing HAPI FHIR configuration and any custom interceptors, a named owner for database operations, and someone who can approve the cutover window. Application developers need to own the test changes, because they know which behaviors the tests rely on. Your DBA or platform team needs to own backups, monitoring, and the PostgreSQL version policy. Confirm these responsibilities in writing before work starts, since unclear ownership is a common reason a move stalls near cutover.

Can our team do the PostgreSQL move alone?

A team with Java, Spring Boot and PostgreSQL experience can usually do the configuration change alone, using the starter's documentation and the HAPI FHIR JPA server documentation as references. The harder parts are the data movement, the test rework and the operational setup for backups and high availability. Whether you go alone depends on those skills in your team and how much time you can release from other work. If you do the work internally, plan a rehearsal and a parallel run regardless, because the first production move is where gaps usually appear.

Can we copy the H2 database file straight into PostgreSQL?

No. H2 and PostgreSQL are different database engines with different storage formats and SQL behavior, so a file or table copy is not a supported route to a working HAPI FHIR server. Move existing data through the FHIR API instead: export resources from the H2-backed server, then load them into the PostgreSQL-backed server, and verify resource counts, versions and references. This route also lets you check the data against validation rules on the way in. Confirm the export approach and any custom resource handling with the team that will run the move.

Which PostgreSQL version should we choose, and how long is it supported?

Choose a version that is still within its support window for the whole planned life of the server. According to the PostgreSQL versioning policy, version 18 was first released on September 25, 2025 and is supported until November 14, 2030, version 17 until November 8, 2029, and version 16 until November 9, 2028. Version 14 is supported only until November 12, 2026, so it is a poor choice for a new production deployment. Also confirm which PostgreSQL versions your chosen HAPI FHIR release supports, since that is a separate check against the HAPI FHIR documentation.

What does a parallel run involve before cutover?

A parallel run keeps the H2-backed server and the PostgreSQL-backed server both receiving the same test traffic for a agreed period, so you can compare results before switching users over. Compare search results, resource counts, validation outcomes, error logs and response times for the workloads your applications use. Decide in advance what counts as a match, who signs off, and what the rollback path is. Ask the partner to show the comparison method and the acceptance criteria as part of the written scope, and confirm the length of the run with your own change board.

How the cutover phases and data path fit together

The diagram starts at the H2 development server, where the team takes a full FHIR export through the server's bulk export and keeps it as the migration artifact. The export is reloaded into a freshly built PostgreSQL-backed JPA server, which is then run in parallel with client traffic. The decision point is parallel-run validation: if reads, searches and writes do not match expectations, the team fixes the gaps and reloads, and only a clean result moves on to cutover and H2 decommissioning.

Phases of the H2 to PostgreSQL cutover, with the validation gate before cutover.

How DeployOpen works on this

DeployOpen plans, implements and hardens self-hosted open-source platforms inside the client's own infrastructure, so the H2 to PostgreSQL move is scoped against your actual HAPI FHIR server, data volumes and environment. Work is agreed in writing before it starts, and the result is documented so your team can run and review it.

How we scope

  • Written scope covers the HAPI FHIR version, JDK version, deployment method and PostgreSQL target agreed before work starts.
  • Scope records which test suites, integrations and data sets must be checked after the switch to PostgreSQL.
  • Scope states the FHIR export and import approach for existing data, and the downtime window your team has approved.
  • Engagements are fixed-scope, with deliverables and timelines confirmed in writing before the first change.

How we build

  • Configure the PostgreSQL datasource, the schema initialization approach and connection settings in a non-production environment first.
  • Update the test harness so integration tests run against PostgreSQL rather than the embedded H2 default.
  • Run a full FHIR export from the existing server and import it into PostgreSQL, then compare resource counts and sample reads.
  • Test authentication to the database, backup and restore steps, and the rollback path before any production cutover.

How we hand over

  • Deliver the configuration files, environment variables and change record so your engineers can reproduce the setup.
  • Document the export and import runbook, including validation checks, known limitations and the order of steps.
  • Provide a cutover checklist and rollback procedure written for the operators who will run the server.
  • Walk your platform, DBA and security teams through the design so they can review it against their own controls.

How we support

  • Ongoing support, upgrades and continuous testing are available as a retainer after the migration is complete.
  • Retainers can cover PostgreSQL minor updates, HAPI FHIR upgrades and retesting after configuration changes.
  • Ask any partner to confirm response arrangements, access model and which environments they will operate in before signing.
  • Confirm with your PostgreSQL and HAPI FHIR release notes which versions your environment is expected to run.

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.