How do i manage multiple databases with Liquibase?

Hello, I want to manage multiple databases in one of my PostgreSQL using Liquibase.

I have already setup a dedicated SQL repository for this purpose, but I am struggling on the changelog structure. I try to follow the guide in Managing Multiple Schemas with Liquibase, where I think both of it does not work.

1.Create a root changelog in each database folder.

With this approach, it becomes trouble as I cannot use includeAll in my root changelog to simply include the whole database folder, which will result in circular error. It still works if I just use include, but then I have to update root changelog everytime when I have a new version of changelog.

2.Create a master changelog outside the database folder. Create a root changelog in each database folder.


Following the example, I assume I will include all the child root changelog in my master changelog.

<include file="schemaA/changelog.xml" context="schemaA"/>
<include file="schemaB/changelog.xml" context="schemaB"/> 
<include file="schemaC/changelog.xml" context="schemaC"/>

But the master changelog is totally useless as I cannot use it during liquibase update which is called per database --url=jdbc:postgresql://{db_hostname}/{db_name}. If I use the liquibase update using the master changelog, then it will apply other database changelog to the incorrect database.

Please suggest any changelog structure for managing multiple database, thanks.

I think the structure in your changelog is fine. JDBC and Postgresql connections are indeed tricky. I’ve seen users with a similar use case setup the changelogs like this and then created a script or use something like maven to run multiple liquibase update operations.

You might also be able to use USE database_name; commands in your .sql files, but I haven’t tried that out before.