Running HAPI FHIR database migrations with hapi-fhir-cli

Running migrate-database safely means backing up first, matching dialect settings to your database, planning heavyweight migrations and clearing a lock only after confirming it is stale. This page sets out the sequence and what each step needs from your team.

On this page

How a HAPI FHIR database migration fits into your upgrade

The schema migration is a separate step inside a HAPI FHIR upgrade, and once it has run against your database, the only dependable way back is a restore from backup. Teams that must move a self-hosted JPA server to a newer version and keep its data intact should treat the migrate-database run as its own change with its own backup, rehearsal and sign-off, not as a side effect of deploying new application images. The application upgrade and the schema change can fail independently, so plan a rollback path for each.

The supplied facts do not include migrate-database flags, migration lock table names or which features depend on the database edition. Confirm those against the release notes and documentation for each target version before you write the runbook, since they change between releases. The current release is 8.8.2, released 25 September 2026, and HAPI FHIR 8.2.0 requires JDK 17. Where the CLI runs matters: the host or container that executes the migration needs a JDK that meets the requirement for the target version, and it should be pinned to the same build you plan to deploy.

Ask your platform team to write down which database engine, version and connection settings the migration will use, and to confirm they match the production JPA server. A migration rehearsed against a copy with different settings proves little. Ask the vendor or your DBA which backup method gives a consistent point to restore to, and time a restore from that backup, not only the backup itself. Use the HAPI FHIR versions page to map your current release to the target and check every intermediate step the upgrade requires.

The sibling sections cover version-specific behavior such as the 8.8 SQL Server change and partition API removals. Here, the decision that matters is whether your maintenance window can absorb a migration that runs long and a restore if it fails partway.

Which version changes affect the database migration

This table lists the release-level changes in each upgrade step that can affect running migrate-database, drawn from the version topics in this group. Read each row as a question to answer before the migration runs: what changes, whether your deployment is affected, and what you must do first. Every row must be checked against the official HAPI FHIR releases page before the plan is signed off.

ChangeImpact on the database migrationAction needed
8.2.0 requires JDK 17The migration tool runs on the JDK it is launched with, so an unsupported JDK blocks the run before any schema change.Confirm the JDK on the CLI host and in any migration container meets the requirement.
8.8 SQL Server case-sensitive IDsAffects SQL Server deployments where ID handling changes, and is the step most likely to break a zero-downtime upgrade.Check your collation and whether you are affected, then plan a maintenance window.
7.x to 8.0 provenance and compartment changesLegacy provenance data and compartment behavior changes can require reindexing after the schema migration.Confirm which reindex steps apply and schedule them after migrate-database completes.
8.10 to 8.12 partition API removalsPartitioned schemas change in the same window, and custom partition interceptors calling removed methods will fail after upgrade.Replace removed methods and test a partitioned copy before running migrate-database in production.
Heavyweight schema migrations named in release notesLarge tables can lock or run for a long time during certain schema steps, which affects the window you need.Read each release's migration notes and time the migration on a rehearsal copy of production.
8.2 unused SP_UPDATED columnThe release notes describe this column as unused, but whether the migration drops or leaves it in place affects rollback planning.Confirm the migration behavior for this column in the release notes and record it in the plan.
6.x to 7.x PostgreSQL index additionsNew indexes are created during migration, which can take time and disk space on large tables.Confirm the indexes listed in the release notes and check free disk space before the run.

How the migration run sits between the old server, the database and the new version

The run starts with a confirmed backup and a restore test, then stops the old server so no writes reach the database. hapi-fhir-cli migrate-database runs against the database using dialect settings that match the target database. Verification queries and checks gate the start of the new server. If verification or startup fails, the team returns to the restored backup rather than patching the schema in place.

Phases of a migration run, with the rollback path to the restored backup.

Preparing for a HAPI FHIR database migration

A migration changes the schema that every HAPI FHIR resource depends on, so the work before the run decides how safely you can recover from it. The six items below cover the backup, the code and configuration inventory, the runtime and a dry run on production-like data, and each one has a clear owner on your side and a clear check on ours.

Tested backup and restore rehearsal

Your team provides a full database backup taken immediately before the run, plus a restore of that backup into a separate environment to confirm it is complete and readable. A backup that has never been restored is not yet a recovery plan. DeployOpen checks that the restore reaches a working JPA server, that the backup timestamp matches the change window, and that the rollback steps name the exact backup to use. Ask the database team to confirm retention and access controls on the backup copy.

Inventory of schema-touching custom code

Your team provides a written list of custom interceptors, providers and partition code that read or write the database directly or through JPA entities. Migrations can change tables and indexes those components depend on, so each item needs an owner and a test. DeployOpen reviews the list against the release notes for the target version, flags direct SQL and entity references, and identifies which components need a test before the migration runs.

Recorded configuration and dialect settings

Your team provides a copy of the current application configuration, including the database dialect, connection settings, and any flags that control schema behavior, stored under version control with the environment it came from. Dialect choice matters because PostgreSQL and Microsoft SQL Server are supported for production and the migration must run against the right one. DeployOpen compares the recorded settings with the live deployment and confirms the values the CLI will read.

Supported JDK at runtime

Your team provides the JDK version on the host, container or build agent that will run hapi-fhir-cli, and confirms it matches what the target HAPI FHIR release requires. Running the CLI on an unsupported Java runtime can fail before any schema change is applied, or fail partway through, which is harder to recover from. DeployOpen checks the runtime in the same image or environment used for the migration, not on a developer workstation, and records the version in the change record.

Dry run on a production copy

Your team provides a copy of production data restored into a non-production database with the same engine and version as production. Running the migration there reveals duration, locking behavior, and failures that a small test database hides. DeployOpen runs the full migration on the copy, records timing and any warnings, and compares row counts and sample searches before and after. Ask whether the copy contains protected health information and whether it is handled under the same controls as production.

Named owners and a stop decision

Your team provides a named person who can approve a stop, a second person who can execute the rollback, and a communication path to the application owners during the window. A migration that stalls needs a decision, not a retry by whoever is online. DeployOpen writes the stop criteria, the rollback sequence and the point of no return into the runbook and confirms that each named owner has the access needed before the change window opens.

Dialect settings for PostgreSQL and SQL Server

The dialect setting must match the PostgreSQL engine and version that the JPA server actually connects to, not the version you intended to deploy. Migrations run DDL and index changes whose behavior depends on the dialect, so a mismatch can produce a migration that succeeds on paper but leaves the schema in an unexpected state. Confirm the exact property and dialect class names in the HAPI FHIR documentation for your target release, because they change between versions and should not be copied from an older runbook.

  • Match the engine version: Record the PostgreSQL major version from the production server and compare it with the dialect option listed for your HAPI FHIR release.
  • Set the dialect in the same place for every run: Use one configuration source for the server and for hapi-fhir-cli migrate-database, so the migration and the running application cannot disagree.
  • Check managed database defaults: Managed PostgreSQL services may run a version that differs from your staging copy, so confirm both environments before the migration window.
  • Keep the connection user privileged for DDL: The migration account needs rights to create and alter tables and indexes, which is separate from the least-privilege account the running server uses.
  • Rehearse on a copy: Run the migration against a restored copy of production with the same dialect and version to surface errors before the real run.

Before the migration, confirm the dialect flag, the PostgreSQL major version and the migration account's privileges against the documentation for your target release.

Which migrations are heavyweight and need a maintenance window

A schema migration that rewrites or indexes large tables takes longer as data volume grows, so the window for a heavyweight migration should be sized from a timed rehearsal on a copy of production, not from the size of the change alone. The same release can run in seconds on a test database with a few thousand resources and take hours on a production database holding years of history. Before the rehearsal, read the release notes and the upgrade page for the target version and list every migration step that adds or rebuilds indexes, changes column types, or rewrites existing rows. Confirm with the HAPI FHIR maintainers or the release notes which steps are flagged as long-running, because that flagging is the only reliable signal available before you run the code against your data.

Record each heavyweight step separately in the rehearsal, with its start time, end time, and the table sizes it touched, so the run time can be attributed to a specific step rather than to the whole migrate-database run. Run the rehearsal on the same database engine, version, and hardware class as production, and repeat it at least once to check variance. Note whether the tool reports progress for each step, and if it does not, have the database team watch active queries and lock waits during the run. Add the recorded durations together with a margin agreed by the change board, then compare the total with the window you have approved.

Decide before the window opens whether the server stays readable during the migration. Some migrations hold locks that block reads, and others allow reads but block writes, so confirm the lock behavior of each heavyweight step with your database administrators. If reads are allowed, decide whether the load balancer will keep sending traffic to the server being migrated, because queries against partially rebuilt indexes can be slow or incorrect. If writes must stop, define who announces the freeze, how clients are told to queue or retry, and how you confirm that no writes were accepted after the freeze began. Write these decisions into the change record so the on-call engineer does not have to make them during the window.

Running migrate-database in order, with a rollback point at each step

This sequence moves a HAPI FHIR JPA schema forward without losing data, and each step leaves a point where the team can stop or return to the last known good state. The exact command and dialect settings come from the documentation for the target version, so the team confirms them before anything runs.

  1. Restore the backup onto a separate copy

    Before any change to production, the database team restores the most recent backup to a separate database server or instance that mirrors production's engine and version. They confirm the restore completes, the schema loads, and a sample of resources can be read through a test instance of the current server. Rollback point: production is untouched at this stage, so the team can stop here if the backup does not restore cleanly. Done when the restore is logged and the copy answers a set of read requests.

  2. Freeze writes and stop the old server

    The platform owner announces a maintenance window, blocks or pauses clients that write to the server, and stops the running HAPI FHIR instances so no new transactions reach the database during the migration. They confirm the load balancer no longer routes traffic to the old pods or containers. Rollback point: restarting the old server against the unchanged database restores service, so the team keeps the stopped instances and their configuration available. Done when no active connections to the schema remain and the change is recorded.

  3. Record the current schema version

    The database owner queries the schema to record the current version and the state of the migration tables, then saves the output with the backup identifier and the old server image or WAR version. This record tells the team exactly which migrations have run and gives them a reference if the migration stops partway. Rollback point: the recorded version and backup together define the state to return to. Done when the version, timestamp and backup ID are stored in the change record and reviewed by a second person.

  4. Run migrate-database with the target CLI and dialect

    The migration engineer runs hapi-fhir-cli migrate-database using the CLI version that matches the target server and the database settings for the engine in use, such as the PostgreSQL or SQL Server dialect flag. The exact invocation is taken from the documentation for the target version, not from older examples or blog posts. Watch the output for each migration step and keep the console log. Rollback point: if the run fails, the team restores the backup on the production database and returns to the recorded version. Done when the tool reports completion without errors and the log is saved.

  5. Check the schema and record the result

    After the run, the database owner compares the migration table and schema objects against the expected state for the target version, including indexes and any tables the release notes list as changed. They record the final version and any warnings from the log in the change record. Rollback point: a mismatch means restoring the backup and not starting the new server. Done when the check passes, the final version is recorded, and the reviewer signs off.

  6. Start the new server and send test requests

    The platform team starts one new HAPI FHIR instance pointed at the migrated database, keeps it out of the public load balancer, and sends a fixed set of test requests covering create, read, search, update and history on representative resource types. They compare responses with the expected results from the rehearsal on the copy. Rollback point: the team stops the new instance and restores the backup if responses differ. Done when the test set passes and the server logs show no schema errors.

  7. Open the server to users

    Once the test requests pass, the platform owner adds the new instance to the load balancer, scales to the planned number of instances, and watches error rates and database connections for an agreed observation period. They notify clients that the maintenance window has closed. Rollback point: the old server image and the recorded backup remain available until the team confirms stable operation. Done when traffic is flowing to the new instances, monitoring shows no new errors, and the change record is closed.

Partition mode, migration locks and Standard edition locking

Partition mode changes what a migration touches, so confirm partition settings before you run migrate-database. When partitioning is enabled, the server stores each resource in a partition, and the partition-aware tables and any custom partition interceptors must match the schema of the target version. HAPI FHIR's partitioning documentation describes partitions as a way to support multitenancy, separate data sources or group data by region, so a team with several partitions has more to validate than a team with a single default setup. Record which partition mode the running server uses, which interceptors are registered, and whether any custom code calls partition APIs. Then check the target release notes for partition-related changes before you plan the run. Confirm these points on the copy of your database you use for rehearsal, not only on the live system.

A stuck migration lock is one of the few places where a fast fix can cause lasting damage. Before you clear a lock, confirm that no migration process is still running. Check every host, container and job that could be executing the CLI or the server startup, and wait for any active run to finish or fail. Then take a verified backup of the database, so you can restore if the migration was interrupted partway through. Clearing the lock while a schema change is still in progress can leave the schema half changed and the next run unpredictable. Write down who approved the step, the time, and the backup identifier in your change record.

The lock mechanism and the feature set of Standard editions are not described in the supplied HAPI FHIR facts, so confirm them before you plan around them. The HAPI FHIR README points to Smile CDR for commercial support, and that is the right first contact for questions about how locking works in Standard editions, which operations they guard, and how to clear a lock safely in that edition. Ask for the procedure in writing, the version it applies to, and any support limits on running it yourself. Also ask whether an edition change affects your migration path or your support entitlement. Keep those answers with the runbook, since they will matter again at the next upgrade.

What makes a database migration run longer or riskier

This table lists the factors that change how long a hapi-fhir-cli migrate-database run takes and how much can go wrong during it. Read each row as a question to answer about your own database before you schedule the window. The main takeaway is that the number of versions crossed and the absence of a tested restore usually matter more than raw table size.

DriverWhy it changes effortWhat to check
Data volumeSchema steps that rewrite or rebuild large resource and search index tables take longer as row counts grow, and the database may need extra free space during the run.Row counts for HFJ_RESOURCE, HFJ_RES_VER and search index tables, plus free storage headroom on the database host.
Number of versions crossedEach release between your current schema and the target can add its own migration steps, so a multi-version jump runs more steps in one window.The list of schema migrations between your current version and the target, taken from the release notes for each version.
Heavyweight schema stepsSome index creation, column type changes or table rebuilds lock tables or consume large amounts of temporary space, which can block the server or fail midway.Which migration steps the tool flags as long-running, and whether your engine can build indexes online.
Custom code that reads or writes the schemaCustom interceptors, providers or direct SQL that depend on table or column names can break when the schema changes, and they may hold locks while the migration runs.Any direct SQL in your codebase, custom DAOs, scheduled jobs and reports that touch HFJ tables, tested against the target schema.
Partition modePartitioned deployments add partition columns and per-partition data, so migration steps touch more rows and the partition configuration must match the target release.Whether partitioning is enabled, the number of partitions in use, and whether partition interceptors are affected by the target version.
Database engine and hostingPostgreSQL and Microsoft SQL Server behave differently for locking, index builds and case sensitivity, and managed hosting may limit session settings, extensions or maintenance access.The engine and version, the dialect flag you will pass to the CLI, and whether your hosting provider allows the operations the migration needs.
Availability of a restore rehearsalWithout a tested restore of a recent copy, a failed migration leaves little safe way back, which pushes teams toward longer, more conservative windows.A dated backup restored to a separate environment, a timed rehearsal of the migration on that copy, and a documented rollback decision point.
Concurrent server trafficClients writing during a migration can conflict with schema changes or extend lock waits, so a run against a live server needs more planning than one with the server stopped.Whether the server will be stopped for the run, how writes are paused or queued, and who can stop the process if locks persist.

Questions teams ask before running a HAPI FHIR database migration

What does a HAPI FHIR database migration cost, and what is one-time versus recurring?

The migration itself is a one-time cost made up of planning, a rehearsal on a copy of production, the production run, verification and handover. Recurring costs come later: each HAPI FHIR upgrade that changes the schema needs the same cycle again, and the database must still be backed up and monitored between upgrades. Cost rises with the number of schema steps between your current version and the target, the size of the database, the number of custom interceptors or partition code paths that need checking, and how many environments must be rehearsed. If you engage a partner, ask for a quote that separates rehearsal, production run, validation and post-run support, and states what is out of scope, such as application code changes or database hosting. No price is estimated here; the quote follows from the written scope.

How long does the migration take, and why can't a duration be quoted in advance?

Run time depends on the schema steps involved, the table sizes in your database, the database engine and its hardware, and whether any heavyweight migration step rewrites or reindexes large tables. Those factors are unknown until the migration has been rehearsed on a copy of your production data, so any duration quoted before that rehearsal would be a guess. Ask for the rehearsal timings to be recorded per migration step, then use them to size the maintenance window. The migrate-database command reports progress, so the rehearsal log is the most useful evidence you can bring into a planning discussion.

What does the migration need from our team?

Plan for four inputs before the window opens. You need database access with rights to alter schema and create indexes, a verified backup and restore path that someone has tested, a change window long enough to cover the rehearsed run plus rollback, and named owners for the database, the HAPI FHIR application, and go/no-go decisions. Your team also needs to confirm which HAPI FHIR version and dialect settings apply to each environment, and to tell the implementer about any custom interceptors, partition interceptors or direct SQL that touch the schema. Missing any of these usually adds time on the day rather than in planning, which is why the checklist should be agreed in writing before work starts.

Can our internal team run the migration without a partner?

Yes, if your team has Java and database administration skills, can run a full rehearsal on a production copy, and has someone who can read migration logs and make a rollback decision. Teams most often struggle with three things: deciding when a long-running step is still progressing, handling a migration lock left behind by an interrupted run, and confirming that custom code still works after the schema change. Ask yourself whether you have run a schema migration on this database engine before, and whether the person who would make the rollback call is available for the whole window. If the answer is unclear, a fixed-scope engagement that includes a rehearsal and a written runbook can be a lower-risk way to build that knowledge.

When should we bring in a partner for the migration?

Consider a partner when the migration spans several major versions, when the database is large enough that the production run must be scheduled tightly, when partition mode or custom partition code is in use, or when your compliance evidence must show a controlled change with a tested rollback. A partner is also useful if the team lacks a rehearsal environment. Engage early enough for the rehearsal to happen before the change freeze, because the rehearsal results determine the window and the rollback plan. DeployOpen implements, hardens, backs up, upgrades and documents self-hosted platforms inside the client's own infrastructure, so the work runs in your environment, under your change control.

How is a stuck migration lock different from a slow migration?

A slow migration is still making progress: its log keeps advancing, the database shows active work on the target tables, and the step is expected to finish given the rehearsal timings. A stuck lock means the process that held the migration lock has stopped, often after a crash, a killed container or a dropped connection, and nothing is advancing. Before clearing a lock, confirm the owning process is really gone, check the database for active sessions, and confirm the last completed step in the logs. Clearing a lock while a migration is still running can leave the schema partly changed, so restoring from a verified backup may be the safer route. Treat lock clearing as a controlled procedure with a named decision maker, not a routine fix.

What should we confirm with our database team before a migration window?

Confirm the database engine and version you run, since the JPA server starter supports PostgreSQL and Microsoft SQL Server for production and does not support MySQL. Confirm the backup, restore and point-in-time recovery arrangements, the storage headroom needed for the migration, and the dialect setting that matches your engine. Also confirm who can approve a restore if the run fails. The HAPI FHIR versions page and the release notes for your target version list the schema-related changes to check against your current release.

How DeployOpen works on this

DeployOpen plans and runs hapi-fhir-cli database migrations for HAPI FHIR JPA servers inside your own infrastructure. We start from your database platform, backup position and upgrade path, then agree the steps, checks and handover in writing before any change is made to a shared environment.

How we scope

  • Written scope names the HAPI FHIR version, source and target versions, and the database engine in use.
  • Scope records whether the server runs on PostgreSQL or Microsoft SQL Server, and which dialect flags apply.
  • Scope states whether partition mode, heavyweight migrations or a stuck-lock recovery are included or excluded.

How we build

  • We build the migration runbook with backup, restore and rollback steps for your database platform.
  • We rehearse each migrate-database run on a copy of your database before the production window.
  • We test the application against the migrated schema, including partitioned data if partition mode is in use.

How we hand over

  • You receive the runbook, the exact hapi-fhir-cli commands used, and the verification queries for each step.
  • Handover covers the lock-clearing procedure, with the checks to confirm no other migration is still running.
  • Documentation records the Standard edition locking constraints and the steps your team repeats on the next upgrade.

How we support

  • Engagements are fixed-scope, with deliverables and timelines agreed in writing before work starts.
  • Ongoing support, upgrades and continuous testing are available as a retainer.
  • Ask any partner, including DeployOpen, to confirm which steps your own operators will perform after handover.

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.