Denis Stephanov
Denis Stephanov

Reputation: 5241

Multiple apps with liquibase connected to one database

We have multiple spring boot applications (microservices) which are connecting to one database. Each application has custom db schema, for instance App A is connecting to schema_a, App B is connecting to schema_b, and so on.

These applications which are connecting to this DB is about 15 (different apps), and just about half of them started. Second half got stuck because of liquibase which is trying to run scripts, but it is waiting because of record in table databasechangeloglock which has locked set true. I don't understand why some apps started fine and some got stuck.

This is my datasource and liquibase configuration in each application:

spring.liquibase.default-schema=schema_of_app
spring.liquibase.enabled=true
spring.liquibase.change-log=classpath:xxx/changelog.xml

spring.datasource.type=com.zaxxer.hikari.HikariDataSource
spring.datasource.hikari.auto-commit=false
spring.datasource.hikari.maximum-pool-size=20
spring.datasource.hikari.max-lifetime=60000
spring.datasource.hikari.minimum-idle=0
spring.datasource.hikari.leak-detection-threshold=20000
spring.datasource.url=jdbc:postgresql://localhost:5432/app_db?currentSchema=${spring.liquibase.default-schema}
spring.datasource.username=user
spring.datasource.password=pass

Do you have idea what I did wrong and how to fix my problem? Thank you in advice.

Upvotes: 2

Views: 2839

Answers (1)

SteveDonie
SteveDonie

Reputation: 9016

What is likely happening is that while each app only updates its own schema, the Liquibase DATABASECHANGELOG and DATABASECHANGELOGLOCK tables are shared. It is likely that those tables are in the public schema of PostgreSQL. Rather than keeping those in the public schema, you should consider keeping separate copies of each of those two tables with the schema they are tracking. You can do this by setting the spring.liquibase.liquibaseSchemaName property in your configuration.

It sounds like these tables are already in existence in your databases, so you may need to do some extra steps to get them in the right places and populated correctly, and then some cleanup afterwards. This could be done with Liquibase itself, but it might be easier to do manually (depending on the number of databases involved and whether you are set up to run liquibase 'manually' rather than at application startup).

Upvotes: 2

Related Questions