Understanding the HAPI FHIR JPA database schema before you size or tune it
The HFJ schema is the set of relational tables that a HAPI FHIR JPA server uses to store FHIR resources, their versions, the links between them and the search indexes that let clients query them. Knowing this layout matters because storage growth, index behavior, backup size and slow searches all trace back to these tables. A team that treats the database as a black box will struggle to size it, explain a slow query or judge whether a partition design will hold up under load.
The JPA server is written against the JPA API rather than a specific database technology, so the schema is what the chosen database actually holds. The starter defaults to an embedded H2 database for development, while PostgreSQL and Microsoft SQL Server are the supported production choices. The table names, column types and indexes you will see in production therefore depend on the database you run, and the reader should confirm the schema objects against the documentation for the exact HAPI FHIR version they deploy, starting with the HAPI FHIR JPA server introduction.
Teams usually need this knowledge in four situations: sizing storage before go-live, troubleshooting a search that scans more rows than expected, planning backup and restore windows, and reviewing a partition design before data arrives. Before any of these, list the tables in a non-production instance after a test load, record row counts and disk use per table, and identify which tables grow fastest with your message and resource mix. That baseline is the reference point for every later tuning decision.
How resources, versions, links and search indexes split across HFJ tables
The resource and version tables hold the FHIR resources themselves. HFJ_RESOURCE holds one row per logical resource, identified by its type and ID, along with a pointer to the current version and metadata such as the last updated time. HFJ_RES_VER holds one row per stored version, including the resource body. A create writes a row to each table. An update adds a new version row and moves the pointer on the resource row, so earlier versions stay available for history reads.
- Logical resource row: One per resource ID, regardless of how many versions exist.
- Version row: Added on every create, update and delete, so version history drives growth in this table.
- Resource body: The serialized content, stored in the form your configuration selects. Confirm whether resource compression is enabled in your build.
- Deletes: Recorded as a version, so a delete adds rows instead of removing them.
- History settings: Options that disable non-resource history change how many rows are kept per write.
After a test load, compare the row counts in these two tables with the number of resources and updates your loader creates.
Relationships between resources, such as an Observation pointing to a Patient through its subject, are stored in the link table HFJ_RES_LINK. The server extracts references from the resource body when it is written. Each link row records the source resource, the path of the reference element, and the target resource type and ID. Links let the server answer reverse lookups and chained searches without parsing every resource body at query time.
- Reference extraction: Happens on write, so a resource with many references creates many link rows.
- Target resolution: A link can point to a resource that does not exist yet on the server, which is common during bulk loads with out-of-order data.
- External references: URLs to other servers are stored as text and are not resolved locally.
- Updates: Links are rebuilt for the new version. Confirm how the link rows of earlier versions are retained in your release.
- Chained search cost: Chained queries depend on these rows, so a heavily referenced resource type can make link lookups a larger share of query work.
To check how links grow, count link rows per source resource type in a test environment that loads representative data. The HAPI FHIR JPA server documentation at the JPA server introduction is the starting point for the storage model.
Each searchable parameter is written into a type-specific index table. Token values such as codes, identifiers and coding systems go to HFJ_SPIDX_TOKEN. Strings, dates, numbers, quantities and URIs have their own tables, named with the HFJ_SPIDX_ prefix. A single create therefore writes the resource and version rows plus one row for each indexed value in every table that applies. An Observation with several coded values, an effective date and a quantity can touch five or more tables in one transaction.
- Token index: Usually the largest index table in clinical data, because codes and identifiers repeat across many resources.
- String index: Holds text parameters such as names. Its size depends on how many string parameters are active.
- Date, number and quantity indexes: Store typed values so that range comparisons can run against them.
- URI index: Holds URI-valued parameters, usually a small share of rows.
- Hash columns: Store a hash of the parameter name and value, so equality lookups compare fixed-size hashes. Confirm how your version handles hash matches and how the stored value is checked.
To see which index tables grow fastest, count rows per table after a load and compare them with the search parameters your deployment enables.
One resource write touches several tables in the schema
The diagram follows one create or update from a FHIR client into the JPA server. The server writes a resource row and a new version row, then derives search index and link rows from the resource content. Each index entry carries a hash value that the server uses to match entries, so check how these rows accumulate when you review storage. All rows land in the relational database, which is where growth is measured.
One create or update fans out into resource, version, link and index rows.
What the hash columns do and why they matter for search
The HAPI FHIR JPA server stores a hash value alongside each index value so that search lookups can match rows quickly without comparing every indexed string or number in full. When a client searches on a parameter, the server computes the same kind of hash for the search value and looks it up in the matching index table. The hash is derived from the resource type, the search parameter identity and the indexed value, so the lookup is effectively a comparison of identity plus content. The exact hash inputs, the columns they populate and any special handling for partitions change between releases, so confirm the current definitions in the HAPI FHIR documentation for the version you run before you build reports or custom queries that depend on them.
Because the hash is computed from the indexed value, any change to how that value is normalized can change which rows match. A different hashing setting, a changed collation, or a switch between case-sensitive and case-insensitive handling can make a search that worked before return fewer or different results, and an index built under one setting may not line up with queries issued under another. Database collation and case sensitivity therefore belong in the design decisions for the database, not only in its performance tuning. Before you change either, test a representative set of searches on a copy of the data and compare results against the baseline.
Plan the hash-related checks as part of every upgrade and database configuration change. Record a set of reference searches covering string, token and reference parameters, run them before and after the change, and keep the results with the change record. Ask your database administrator to confirm the collation of the FHIR database and any JDBC settings that affect string comparison, and check the release notes for changes to hashing or index layout. If a search returns unexpected results after a change, the hash and collation settings are the first places to examine.
Which tables grow fastest as data is loaded
Each card names one group of HFJ tables that gains rows on every write. Growth depends on how often clients write, how many search parameters each resource type indexes, and how densely resources reference one another. Use these cards to choose which tables to watch during a load test before you size production storage.
Resource version history
Every create and update writes a new row to the resource version table, and earlier content stays in place as history. Growth tracks write volume over time, so a workload that rewrites the same Observation or Encounter many times accumulates versions quickly. After a test load, compare the number of version rows with the number of current resources. Also ask whether clients send full PUT updates for small changes, because each one stores the entire resource again.
JPA server docsString search index rows
Each searchable string parameter, such as a name, address line or family name, produces one or more index rows per resource version. Many indexed parameters on a busy resource type multiply that count, and repeating or multi-valued fields add more. Review which parameters your clients actually search on, because indexes for unused parameters are still written on every save and still take space.
Token search index rows
Token parameters index coded values such as identifiers, codes and status fields, usually as a system and code pair. Resources with several codings, such as Observations carrying multiple code systems, produce several rows each. Check how your version indexes text tokens and whether clients search on them. Ask how often the same code values repeat across many resources, since repetition inflates row counts without adding distinct information.
Reference link rows
Each reference from one resource to another, such as a subject, encounter or performer, is stored as a row in the link table. Dense reference use, for example Observations that point to a Patient, an Encounter and several Practitioners, multiplies those rows. Chained searches and _include depend on this table, so it is the one to size first when references make up most of your data.
History tag rows
Tags and security labels attached to a resource are recorded against its versions, so each new version of a tagged resource can carry its tags forward. Workflows that stamp a tag on every write, such as processing or provenance markers, make this table grow faster than the number of distinct tags suggests. Confirm which tag types your clients send and whether your release keeps tags on every version.
Schema-related settings and when each fits
This table compares configuration choices that change how the HFJ tables are populated or how much storage they use. Read each row as a decision point: what to choose, what it does to storage, and what it costs in search behavior or upgrade effort. The main takeaway is that history, token indexing and schema creation are the settings most worth deciding before the first production load, since changing them later means data work or a planned migration.
| Setting | Decision | Storage effect | Trade-off for search and upgrades |
|---|---|---|---|
| Non-resource history | Keep where clients or auditors read past versions; disable where only current state matters | Each update adds history rows, so write-heavy loads grow history tables fastest | Disabling removes history reads; confirm which history types your clients use first |
| :text token indexes | Keep if clients use the :text modifier; suppress if no search depends on it | Suppression removes index rows for narrative-style token values | Searches using :text may stop matching; test affected parameters before changing |
| Search parameter scope | Enable only the custom search parameters your applications query | Each active search parameter adds index rows to the search tables | Unindexed parameters may run slowly or be rejected; test with real client queries |
| Resource compression | Consider when storage pressure is high and the server has CPU headroom | Smaller stored resource bodies, mainly in the resource content tables | Extra CPU on reads and writes; raw rows are harder to inspect with SQL |
| Schema created by server at startup | Suitable for development and single-instance test environments | No direct storage effect | Schema changes run during startup, so a failed migration can block the server |
| Schema created by migrator as a separate step | Preferred for production, so a database administrator can review and run changes first | No direct storage effect | Adds a pipeline step; migrator and server versions must match |
| Partition mode at schema creation | Choose before the first load, based on tenancy or data separation needs | Separates data per partition; does not reduce total size by itself | Hard to change later; confirm whether switching is supported in your version |
How to inspect the HFJ schema on a running server
This sequence confirms that the database matches the HAPI FHIR release you run, maps the HFJ tables, captures a baseline of row counts and sizes after a test load, and checks which indexes the workload actually uses.
Confirm the database type and version
Start by recording the HAPI FHIR server version, the JDK it runs on, and the exact database engine and version behind the JPA server. Check the server version against the HAPI FHIR versions page, which lists the Java requirement for each release, and confirm the database version is one the chosen release supports. The starter defaults to an embedded H2 database and supports PostgreSQL and Microsoft SQL Server for production, so confirm you are not still on H2 for a production-like environment. Done means you have a written record of server version, JDK, database engine and database version, signed off by the platform owner.
Identify the HFJ tables in the target database
Connect to the database with a read-only account and list the tables whose names start with HFJ, using the database's own catalog views. Group them by role: resource tables, resource version and history tables, resource link tables, and search index tables such as the string, token, date and quantity indexes. Compare the list with the table names produced by the schema migrator for your installed release, which you can generate or review from the server's migration output. Done means the HFJ table list matches the migrator output for that version, and any extra or missing tables are logged as findings before you go further.
Check the hash columns and key constraints
For a sample of search index tables, confirm the presence of the hash columns that the server uses to match search parameters quickly, and check that the expected unique constraints and primary keys exist. Compare column definitions and index definitions with the migrator output rather than relying on memory of earlier releases. Note any hash column or index that differs, because a manual change or an interrupted upgrade can leave the schema out of step with the code. Done means every checked table has the expected columns, keys and indexes, or each deviation has a ticket and an owner.
Record baseline row counts and table sizes
Load a representative test dataset through the server's normal API, not through direct database writes, so that the resource, version, link and index tables fill the way production writes would. Once the load completes, record row counts and total size, including index size, for each HFJ table in a spreadsheet or a versioned file. Repeat the capture after each later load or upgrade so the growth trend is visible. Done means a dated baseline exists for every HFJ table, and you have identified the tables that grew fastest during the load, which is where storage planning should start.
Check index usage with database tooling
Use the database's own statistics views to see which indexes the workload scans, seeks or never reads. On PostgreSQL, the statistics views for index scans show this directly, and on Microsoft SQL Server, the index usage statistics dynamic management view serves the same purpose. Run a set of representative searches against the test server first, so the counters reflect real query patterns. Unused indexes still cost storage and write time, so flag them for review, but do not drop any index until the upgrade and search team confirms it is not needed. Done means you have a list of indexes with their usage counts and a short decision note for each unused one.
Document the schema baseline and repeat after changes
Bring the results from the earlier steps into one document that names the server version, database version, table list, hash column checks, size baseline and index usage findings. Store it alongside the deployment configuration so the next upgrade, migration or partition change can be compared against it. Schedule the same checks after each HAPI FHIR upgrade and after any change to database settings, and confirm with your database team which monitoring tools are approved in your environment. Done means the baseline is stored under version control or your document system, and the owner has signed off that the next review will rerun the same steps.
Security and operational considerations for the schema
The HFJ tables hold every version of every resource, so the database is the most sensitive part of a HAPI FHIR JPA server. HAPI FHIR provides building blocks rather than a single security layer, which means access control and audit sit above the schema and must be designed deliberately. The cards below cover the controls to set around the database before data is loaded.
Restrict direct database access
Only the JPA server's database account should read and write the HFJ tables. Engineers, reporting tools and batch scripts should use the FHIR API or a separately controlled read path, not the same account. Check that the server account cannot alter schema objects and that administrative roles are held by a named, small group. Review grants whenever the server is redeployed, because a new environment often inherits broader access.
Protect backups of all versions
A backup of the HFJ tables contains every stored version of every resource, including versions a client later believed were removed, so it carries the same sensitivity as the live database. Encrypt backups at rest, restrict who can restore them, and set retention that matches your privacy obligations. Test restores into an isolated environment so that a restored copy is not quietly reconnected to live systems.
Audit direct SQL against HFJ tables
Direct SQL bypasses the FHIR layer, so the interceptors that log access and enforce authorization never see it. Record who runs ad hoc queries, keep scripts in version control, and route reporting through an approved, read-only role. Ask whether your database platform can log statements or sessions against the HFJ schema, and confirm how those logs are retained and reviewed.
Keep schema changes under the migrator
Schema changes should run only through the HAPI FHIR migrator during a planned upgrade, never by hand on a production database. Treat each migration as a change: approve it, rehearse it on a copy of production data, and keep a tested rollback path. Confirm that the account used for migrations is separate from the account the running server uses, and that the migration window and index locking effects are known before work starts.
JPA server docsPlace access control above the schema
HAPI FHIR offers authentication interceptors, the AuthorizationInterceptor, consent and search narrowing interceptors and BALP audit logging, but it does not enforce one security model for you. Decide which rules apply to each resource type and compartment, then test them through the API and confirm that partitioning or search parameters cannot widen access. Document the mapping so auditors can trace a permission back to a configured rule.
HAPI FHIR security docsQuestions teams ask about the HAPI FHIR JPA schema
What drives the cost of schema-level work on a HAPI FHIR server?
The main cost drivers are the number of resource types and search parameters in use, the volume of data already loaded or expected, and whether the work covers only a design review or also changes, testing and upgrade planning. Who gets paid matters too. A partner bills for analysis, written findings and any configuration changes, while your team pays for staff time, a staging environment and the database hardware or cloud capacity used for testing. Review work is largely one-time, but upgrade checks recur with each HAPI FHIR release. Ask any quote to list the resource types, custom search parameters, environments and deliverables it covers, so you can compare it against your own estimate.
How long does a HAPI FHIR schema review take?
The duration depends on scope, not on a fixed number of days. The largest factors are how many custom search parameters and profiles your server uses, how much data is loaded, whether you run partitioned storage, and how quickly your team can provide a representative environment and answer design questions. A review that only confirms table layout and index behavior is much shorter than one that also tests load patterns and upgrade steps. No duration is given here because none has been established for your environment. Ask for a timeline in the written scope, with dependencies on your team listed separately.
What does the schema work need from our team?
The work needs a named technical owner who can make decisions on partitioning, retention and index choices, plus a database administrator who can grant read access to the schema and explain your backup and maintenance routines. It also needs a staging server connected to a database restored from a recent copy, or a realistic sample of your data, because schema behavior under load cannot be judged from an empty database. Gather the list of FHIR resource types, custom search parameters, and integrations that read the database directly. Your security team should approve any access to production data before work begins.
Can our own engineers inspect the HAPI FHIR schema?
Yes, the schema is made of ordinary relational tables in the database you choose, so standard SQL clients can list tables, columns and indexes. Interpreting the results is harder. Table names, hash columns and index definitions depend on the HAPI FHIR release you run, and they change between versions, so an engineer should read the documentation for that exact release before drawing conclusions. Avoid writing directly to these tables, because the server expects its own data to be consistent. Start with read-only queries on a copy of production, and record what you find so the next upgrade can be compared against it.
Which HAPI FHIR tables grow fastest as data loads?
Growth is usually led by the tables that store resource content and version history, followed by the search index tables that hold one row per indexed value. Each update to a resource adds a new version, so write-heavy workloads grow history faster than read-heavy ones. Token indexes, which store coded values and identifiers, often become the largest index tables when many parameters are indexed. The exact ranking depends on your resource mix and settings, so measure it instead of assuming it. Load a representative sample, record table sizes at fixed intervals, and project growth from those measurements before choosing storage and backup capacity.
Do the hash columns affect search speed, and what happens if they break?
Hash columns let the server compare compact precomputed values when it looks up search parameters, identifiers and some references, instead of comparing full strings. They are derived from the stored values using the server's own logic, which means any change to that logic in a new release can require data migration. Manual edits to these columns, or SQL that bypasses the server, can cause searches to return incomplete results without raising an error. Test important search queries after every upgrade and any schema change, and keep a record of expected result counts for them. Confirm the hash behavior for your release in the version documentation.
Does the database schema change when we upgrade HAPI FHIR?
It can. Upgrades may include schema migrations that alter tables, add indexes or rebuild data, and the runtime requirements can change as well. For example, HAPI FHIR 8.2.0 requires JDK 17, according to the project's version documentation. Before any upgrade, check the release notes and migration steps for each version you cross, take a verified backup, and run the migration against a copy of production first. Plan time for large index rebuilds, because they can lock tables or slow the server while they run. Use the HAPI FHIR versions documentation as the starting point for the version-by-version checks.
How DeployOpen reviews and operates a HAPI FHIR schema
DeployOpen scopes a schema review as a fixed-scope engagement, with the scope, deliverables and timeline agreed in writing before work starts. The review needs three inputs from the client. The first is the exact HAPI FHIR release in use, because table layouts, hash columns and index definitions change between versions, and the upgrade path for that release must be known. The second is the database engine and version, including the collation and any compatibility settings, since PostgreSQL and Microsoft SQL Server behave differently for the same schema. The third is the load profile: the resource types expected, the approximate volume of versions and history, how often data is written and bulk loaded, and which search parameters clinical and integration users actually run. Confirm with your own team which of these figures you can supply before requesting a quote, because a review without a realistic load profile can only describe the schema, not its growth.
In writing, the review covers the table families that hold resources, versions, links and search indexes, the hash columns used for matching and lookup, and the tables that grow fastest under your load. The deliverable is a written report that maps each high-growth table to the feature driving its growth, such as history retention, search parameter coverage or terminology loading, and states which settings were checked against the running database. The report should also list the database roles, backup and restore responsibilities and the change-control steps that your team, rather than DeployOpen, will own after handover. Ask for the sample queries and checks used so your engineers can repeat them. Ask whether the review includes a retest after the agreed changes are applied.
The findings feed storage sizing and tuning decisions. A reviewed load profile gives a basis for estimating table and index growth, which then drives the disk, backup window and retention choices for your environment, and it shows which index-related settings deserve a change before data volume makes them expensive to change. Tuning recommendations are written as decisions with a reason, a risk and a rollback step, so your platform team can accept, defer or reject each one. Any change to a production schema should be tested on a copy with representative data, since the effect of a change depends on the actual volume and query mix. Plan a follow-up measurement after the first large load to compare real growth against the review's projection.
How DeployOpen delivers HAPI FHIR database work
DeployOpen approaches the HAPI FHIR JPA database schema as a planning and operating question before it is a build task. We scope which schema questions your team must answer, build and test the database layer in infrastructure you control, and document what the schema means for your operations.
How we scope
- Engagements are fixed-scope, with the schema questions, deliverables and timelines agreed in writing before work starts.
- The written scope names which HFJ tables, hash columns and search indexes your team needs to understand for capacity planning.
- We confirm your HAPI FHIR version, target database and expected resource volumes so the schema review matches your environment.
How we build
- We set up a test instance with your chosen database and load representative FHIR data to observe how table growth behaves.
- We review resource, version, link and search index tables against your query patterns and record which tables grow fastest.
- We test hash column behavior and index usage with your own search workload, then document the findings alongside the configuration used.
How we hand over
- You receive written documentation of the schema layout, table growth observations and the storage assumptions behind them.
- Your team gets a walkthrough of the tables and queries so operators can read the schema during incidents and upgrades.
- We record the monitoring points and size checks your team should run, so storage trends are visible after handover.
How we support
- Ongoing support, upgrades and continuous testing are available as retainers for schema changes across HAPI FHIR releases.
- Retainer work can include re-checking table growth after data loads, configuration changes or version upgrades.
- Before any engagement, ask us to confirm which support scope, response arrangements and retesting cadence apply to your environment.

