Hello,
I’m looking for best practices and guidance on managing schema migrations and specialized tasks across multiple FHIR server instances pointing to one database.
SetupI run multiple HAPI FHIR server instances, all pointing to a single shared database. Among these, there is a single dedicated FHIR server instance designed for specialized tasks such as schema migrations and reindexing. This instance has a more substantial CPU allocation due to the CPU-intensive nature of reindexing jobs, and the
setMarkResourcesForReindexingUponSearchParameterChange setting is
enabled.
Issue Observed
Upon startup, these multiple FHIR server instances attempted
concurrent schema migrations because they point to the same database, leading to conflicts. We also noticed high CPU utilization across all instances. For example, here’s a failure from one of the instances:
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "create index IDX_RL_TGT_v2 on hfj_res_link (target_resource_id, src_path, src_resource_id, target_resource_type, partition_id)" via JDBC Statement...The error correlates with the migration task defined in
https://github.com/hapifhir/hapi-fhir/blob/master/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/HapiFhirJpaMigrationTasks.java#L525While HAPI FHIR’s official documentation recommends using the
hapi-fhir-cli migrate-database command to perform schema migrations when moving from one version to the next, I encountered these auto-migrations upon startup.
I’m seeking clarity on a few points:
- How can I ensure that my instances do not initiate automatic schema migrations on startup?
- Given the auto-migrations observed on startup, what is the intended use of the hapi-fhir-cli migrate-database tool? How should it be effectively utilized in a production-like setup? I was planning on running the command manually in the dedicated instance before realizing the migrations ran automatically.
- Concerning the dedicated FHIR server instance focused on reindexing, jobs, perhaps also migrations, what configurations or settings should be unique to ensure primary instance activities are unaffected?
- Are there any other particular precautions to maintain database consistency and integrity during upgrades when operating in a multi-instance setup?
Any insights and recommendations would be highly appreciated.
Relevant properties from application.yaml
server:
max-http-header-size: 4MB
management:
endpoints:
web:
exposure:
include: "health,prometheus"
spring:
main:
allow-circular-references: true
#allow-bean-definition-overriding: true
flyway:
enabled: false
jpa:
properties:
hibernate.format_sql: false
hibernate.show_sql: false
hibernate.dialect: ca.uhn.fhir.jpa.model.dialect.HapiFhirPostgres94Dialect
# we don't use any advanced text searching (yet)
hibernate.search.enabled: false
batch:
job:
enabled: false
Thanks,
Kaush