Database / Liquibase interview questions
1. What is Liquibase and what problem does it solve?
Liquibase is an open-source database schema change management tool that tracks, versions, and deploys changes to a database in a controlled, repeatable way. It solves the problem of managing database migrations alongside application code — ensuring every environment (dev, test, staging, productio...
2. What is a changeLog in Liquibase?
A changeLog is the master configuration file (or set of files) that contains all the database changes Liquibase should manage. It acts as the single source of truth for every schema modification your application has ever needed — from the initial table creation to the latest column rename. Liquib...
3. What is a changeSet in Liquibase and how is it identified?
A changeSet is the atomic unit of change in Liquibase — it contains one or more related database operations (create table, add column, insert data, etc.) that should be applied together as a single migration step. Each changeSet is uniquely identified by the combination of three attributes: id , ...
4. What are the DATABASECHANGELOG and DATABASECHANGELOGLOCK tables?
Liquibase creates and manages two system tables in the target database. These tables are the backbone of how Liquibase tracks state and prevents concurrent deployments from corrupting the database. DATABASECHANGELOG is the audit trail of every applied changeSet. Each row records the changeSet ID ...
5. What is the difference between Liquibase and Flyway?
Liquibase and Flyway are the two dominant Java database migration tools, and they share the same core goal — versioned, automated schema management — but differ in philosophy, flexibility, and feature set. Liquibase vs. Flyway Comparison Aspect Liquibase Flyway Migration format XML, YAML, JSON, o...
6. What are contexts in Liquibase and how do you use them?
Contexts in Liquibase are labels you attach to a changeSet to control which environments it runs in. When you execute Liquibase and pass a context value (via command line, properties file, or Spring configuration), only the changeSets whose contexts match the active context will be executed. Chan...
7. What are labels in Liquibase and how do they differ from contexts?
Labels in Liquibase look superficially similar to contexts — both are string tags on a changeSet used to filter which changeSets run. The key difference is in where the expression logic lives. With contexts, the filtering expression is written on the changeSet itself (e.g., context="!prod" ). Wit...
8. How does rollback work in Liquibase?
Liquibase rollback allows you to undo previously applied changeSets, reverting the database to an earlier state. There are two ways to define rollback behavior for a changeSet: automatic rollback and explicit rollback . For many built-in Liquibase change types — createTable , addColumn , createIn...
9. What is a Liquibase precondition and why would you use one?
A precondition is a condition that Liquibase checks before executing a changeSet or the entire changeLog. If the condition is not met, Liquibase can either halt execution, skip the changeSet, mark it as run, or issue a warning — depending on the onFail and onError settings. Preconditions let you ...
10. How do you integrate Liquibase with Spring Boot?
Spring Boot has first-class auto-configuration for Liquibase. When you add the spring-boot-starter-data-jpa or the dedicated liquibase-core dependency alongside Spring Boot, the auto-configuration detects the Liquibase JAR and automatically runs migrations at application startup before the applic...
11. What are Liquibase change types and can you name common ones?
A change type is the specific DDL or DML operation that a changeSet performs. Liquibase provides over 40 built-in change types that are database-agnostic — you write the intent (add a column, create an index) and Liquibase generates the correct SQL for the target database. This is one of Liquibas...
12. What is the Liquibase diff command and when is it useful?
The diff command compares two database connections (or a database against a snapshot) and reports differences in schema objects — tables, columns, indexes, foreign keys, views, sequences, and stored procedures. It is one of Liquibase's most powerful tools for identifying schema drift and for boot...
13. What are Liquibase tags and how do you use rollback to a tag?
A tag in Liquibase is a named marker you apply to the current state of DATABASECHANGELOG — a named checkpoint that records exactly which changeSets have been applied at the time of tagging. Tags are used as rollback targets: instead of counting changeSets or specifying a date, you roll back to a ...
14. What is runOnChange and runAlways in a Liquibase changeSet?
By default, Liquibase runs a changeSet exactly once — it executes it, records it in DATABASECHANGELOG, and never runs it again on subsequent Liquibase runs. Two attributes override this behavior for specific use cases where idempotent re-execution is desired. runOnChange="true" — Re-executes the ...
15. What is the markNextChangeSetRan and markNextChangeSetRanSQL command used for?
The markNextChangeSetRan command records the next unrun changeSet in DATABASECHANGELOG as executed — without actually running it. This is a rescue command for situations where a change was already applied to a database outside of Liquibase (manually or through some other tool), and you need Liqui...
16. How do you manage Liquibase changeLog files in a multi-module Maven project?
In a multi-module Maven project (common in microservices or modular monolith architectures), each module typically manages its own schema. The recommended approach is to have each module own a separate changeLog tree under its src/main/resources , and then compose them from a top-level root chang...
17. What is the Liquibase updateSQL command and when is it used?
The updateSQL command generates the SQL that Liquibase would execute during an update run — without actually applying any changes to the database. It writes the complete SQL to standard output or a file, including the INSERT statements that would update DATABASECHANGELOG and the actual DDL/DML fr...
18. What is a Liquibase snapshot and what commands use it?
A snapshot in Liquibase is a serialised representation of a database's schema state captured at a specific point in time. It records tables, columns, indexes, foreign keys, views, sequences, and other schema objects as a JSON or YAML file. Unlike a database backup, it captures structure — not dat...
19. What is the failOnError attribute in a changeSet and when should you set it to false?
The failOnError attribute on a changeSet controls what Liquibase does when an error occurs during that changeSet's execution. By default, failOnError="true" — any error causes Liquibase to stop, roll back the transaction (if within one), and report a failure. Setting failOnError="false" tells Liq...
20. How does Liquibase handle transactions during migration?
By default, Liquibase wraps each changeSet in a database transaction. If any change within a changeSet fails, the entire changeSet is rolled back and Liquibase stops. This transactional wrapper ensures that a changeSet either succeeds completely or leaves the database unchanged — partial applicat...
21. What is the Liquibase Hub and what does it provide?
Liquibase Hub (now rebranded and incorporated into Liquibase Pro and Liquibase Cloud) was a cloud-based observability service that connected to your local or CI Liquibase runs and provided a centralised dashboard showing deployment history, changeSet execution timelines, and operational statistic...
22. How do you use Liquibase with multiple databases or schemas in a single application?
When an application uses multiple databases or schemas — for example, a multi-tenant SaaS app with one schema per tenant, or an application split across a billing schema and a product schema — Liquibase can manage each independently. The key is that each schema/database gets its own DATABASECHANG...
23. What is the Liquibase Pro checksum validity and how do clearCheckSums and validChecksums work?
Liquibase computes an MD5 checksum for each changeSet when it first runs and stores it in DATABASECHANGELOG. On every subsequent run, Liquibase recomputes the checksum from the current file and compares it against the stored value. If they differ, Liquibase throws a ValidationFailedException and ...
24. What are Liquibase custom change types and how do you create one?
When Liquibase's built-in change types do not cover a specific requirement, you can create a custom change by implementing the CustomChange (or CustomSqlChange for SQL-generating changes) interface. This lets you write Java logic that runs as part of a migration — useful for complex data transfor...
25. How do you handle large table migrations in Liquibase without causing downtime?
Large table migrations — adding a non-nullable column to a 500 million row table, back-filling data, adding an index on a frequently queried column — are among the most challenging database operations to perform without application downtime. The raw DDL that Liquibase would generate often acquire...
26. What is the Liquibase Maven plugin and how do you run migrations with it?
The Liquibase Maven plugin integrates Liquibase commands directly into the Maven build lifecycle, allowing you to run database migrations as part of your build without needing a separate CLI installation. It is the standard approach for Java projects that use Maven as their build tool and want to...
27. What is the Liquibase status command and how does it differ from validate?
The status command queries DATABASECHANGELOG and compares it against the changeLog file to report which changeSets are pending — not yet applied to the database. It shows each pending changeSet's ID, author, filename, and whether a rollback is defined. liquibase status --verbose Example output: 3...
28. What are Liquibase property substitution and how does it work?
Liquibase property substitution allows you to use placeholders in your changeLog files that are replaced with values at runtime. Placeholders follow the syntax ${propertyName} . This makes your changeLogs more portable — table prefixes, schema names, default values, and environment-specific setti...
29. How do you write Liquibase changeLogs in YAML format?
YAML is a supported Liquibase changeLog format that many teams prefer for its readability compared to verbose XML. The structure maps directly to the XML model — databaseChangeLog is the root, containing a list of changeSet entries, each with an id , author , and a list of changes. databaseChange...
30. What is the Liquibase formatted SQL changeLog format?
Formatted SQL changeLog is the option for teams that want to write pure SQL migrations while still using Liquibase's change tracking, rollback, and contextual features. Instead of XML or YAML wrappers, changeSet metadata is embedded as SQL comments in a specific format that Liquibase parses. A fo...
31. What is the Liquibase updateTestingRollback command?
The updateTestingRollback command is a quality assurance command that tests whether your rollback definitions are actually correct and complete. It performs three steps in sequence on the target database: Applies all pending changeSets (like a normal update ). Immediately rolls back all the chang...
32. How do you use Liquibase with Docker and Testcontainers in integration tests?
Testcontainers is a Java library that spins up real Docker containers during JUnit tests, providing actual database instances instead of in-memory databases. Combining Testcontainers with Liquibase gives you integration tests that run against a realistic database — same engine type, same version ...
33. What is the difference between addColumn with a default value and a nullable column in Liquibase for large tables?
Adding a column to a large table is a common migration, but the choice between nullable (no default) and non-nullable (with a default value) has dramatic performance differences depending on the database engine, and Liquibase's generated SQL directly reflects this. Adding a nullable column with n...
34. What is liquibase.properties and what configuration belongs in it?
The liquibase.properties file is the default configuration file for the Liquibase CLI and Maven plugin. When Liquibase runs, it looks for this file in the current working directory (or on the classpath) and reads database connection settings, changeLog location, and default command options. You a...