After importing a production database dump into our dev environment, our Spring Boot applications (two services sharing the same PostgreSQL database) fail to start with the error:
Copy
.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase'...
liquibase.exception.LockException: Expected single row from ... but got 2
The issue occurs only in the dev environment after importing the dump. Locally, both services work fine when started together.
Key Details:
Problem: The DATABASECHANGELOGLOCK table has multiple rows (expected: 1 row with ID=1).
Cause: Likely caused by importing a corrupted DATABASECHANGELOGLOCK state from the production dump.
What We’ve Tried:
Manually deleting extra rows in DATABASECHANGELOGLOCK and resetting the table (works temporarily).
Confirmed both apps use the same Liquibase changelog files (see configurations below).
Question: How to prevent this error when importing production dumps to dev?
Configurations:
app-backend-1 (DatabaseConfig.java):
java
@Bean
public SpringLiquibase liquibase(DataSource dataSource, LiquibaseProperties liquibaseProperties) {
// ... sets changelog to "classpath:config/liquibase/master.xml"
}
app-backend-2 (DatabaseConfiguration.java):
java
@Bean
public SpringLiquibase liquibase(DataSource dataSource, LiquibaseProperties liquibaseProperties) {
// ... also uses "classpath:config/liquibase/master.xml"
}
Liquibase Changelog (master.xml):
xml
<databaseChangeLog>
<include file="config/liquibase/changelog/00000000000000_initial_schema.xml"/>
<!-- ~30 other included changelogs -->
</databaseChangeLog>
Error Context:
Locally, both apps start without issues.
In dev, after importing the dump, the apps fail with the BeanCreationException.
Hypotheses:
The production dump includes a DATABASECHANGELOGLOCK table with invalid state.
Both apps attempt to run Liquibase migrations simultaneously, causing lock conflicts.
Ask: How can we ensure the DATABASECHANGELOGLOCK table remains valid after importing a production dump? Are there best practices for handling Liquibase in multi-service environments with shared databases?
After importing a production database dump into our dev environment, our Spring Boot applications (two services sharing the same PostgreSQL database) fail to start with the error:
Copy
.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase'...
liquibase.exception.LockException: Expected single row from ... but got 2
The issue occurs only in the dev environment after importing the dump. Locally, both services work fine when started together.
Key Details:
Problem: The DATABASECHANGELOGLOCK table has multiple rows (expected: 1 row with ID=1).
Cause: Likely caused by importing a corrupted DATABASECHANGELOGLOCK state from the production dump.
What We’ve Tried:
Manually deleting extra rows in DATABASECHANGELOGLOCK and resetting the table (works temporarily).
Confirmed both apps use the same Liquibase changelog files (see configurations below).
Question: How to prevent this error when importing production dumps to dev?
Configurations:
app-backend-1 (DatabaseConfig.java):
java
@Bean
public SpringLiquibase liquibase(DataSource dataSource, LiquibaseProperties liquibaseProperties) {
// ... sets changelog to "classpath:config/liquibase/master.xml"
}
app-backend-2 (DatabaseConfiguration.java):
java
@Bean
public SpringLiquibase liquibase(DataSource dataSource, LiquibaseProperties liquibaseProperties) {
// ... also uses "classpath:config/liquibase/master.xml"
}
Liquibase Changelog (master.xml):
xml
<databaseChangeLog>
<include file="config/liquibase/changelog/00000000000000_initial_schema.xml"/>
<!-- ~30 other included changelogs -->
</databaseChangeLog>
Error Context:
Locally, both apps start without issues.
In dev, after importing the dump, the apps fail with the BeanCreationException.
Hypotheses:
The production dump includes a DATABASECHANGELOGLOCK table with invalid state.
Both apps attempt to run Liquibase migrations simultaneously, causing lock conflicts.
Ask: How can we ensure the DATABASECHANGELOGLOCK table remains valid after importing a production dump? Are there best practices for handling Liquibase in multi-service environments with shared databases?
Share Improve this question edited Mar 13 at 9:30 DarkBee 15.5k8 gold badges72 silver badges118 bronze badges asked Mar 12 at 22:42 HAFIDA FAOUZIHAFIDA FAOUZI 92 bronze badges2 Answers
Reset to default 11. Use session-level instead of transaction-level LockService implementations. Session-level locks get automatically released if the database connection drops. This way, there won't be any garbage in the DATABASECHANGELOGLOCK table and it will always be in a valid state.
2. I would exclude the data of the DATABASECHANGELOGLOCK table from your dump entirely, as it represents Liquibase processes of the production state and not the dev state.
How I Fixed the "Expected Single Row" Liquibase Error
Manually copying the sanitized dump into PostgreSQL via PG Admin’s query console resolved the issue.
Import the Clean Dump:
Open PG Admin’s Query Tool.
Copy-paste the entire sanitized dump content into the editor.
Execute the script