I was trying to run Liquibase 4.1.1.programmatically. However, it is throwing the following exception on an existing database that has the databasechangeloglock table.
INFO: Create Database Lock Table
Exception in thread “main” liquibase.exception.LockException: liquibase.exception.JDBCException: Error executing SQL CREATE TABLE [DATABASECHANGELOGLOCK] ([ID] INT NOT NULL, [LOCKED] BIT NOT NULL, [LOCKGRANTED] DATETIME, [LOCKEDBY] VARCHAR(255), CONSTRAINT [PK_DATABASECHANGELOGLOCK] PRIMARY KEY (ID))
at liquibase.lock.LockHandler.waitForLock(LockHandler.java:176)
at liquibase.Liquibase.listUnrunChangeSets(Liquibase.java:518)
Caused by: liquibase.exception.JDBCException: Error executing SQL CREATE TABLE [DATABASECHANGELOGLOCK] ([ID] INT NOT NULL, [LOCKED] BIT NOT NULL, [LOCKGRANTED] DATETIME, [LOCKEDBY] VARCHAR(255), CONSTRAINT [PK_DATABASECHANGELOGLOCK] PRIMARY KEY (ID))
at liquibase.database.template.JdbcTemplate.execute(JdbcTemplate.java:55)
at liquibase.database.template.JdbcTemplate.execute(JdbcTemplate.java:86)
at liquibase.database.AbstractDatabase.checkDatabaseChangeLogLockTable(AbstractDatabase.java:755)
at liquibase.lock.LockHandler.waitForLock(LockHandler.java:145)
… 3 more
Looks like your db is in a locked state as far as liquibase is concerned. This happens when maybe liquibase operation or the target db gets cut off or shut down improperly.
You may be right it is not a permission issue but, I am not able to see that based on what you have provided. Are you using the same user / password credentials programmatically as well as in the liquibase maven?
Or rather the exact maven liquibase goal you are running that works?
You could set the schema in your liquibase changeset. All objects can be set with schemaName.object. If schema differs from environments, you can use property substitution. Hope that helps.
It is not with my changesets. It is related to an internal liquibase table. Maven plugin works with the same changeset xml. The JAVA method is giving errors. Please have your dev team to review.
What database are you running this against? Does the same thing happen if you use the vendor’s based jdbc driver vs the open source driver?
In maven you are calling updateSQL and in the java method you are using listUnrunChangeSets.
Hi @ronak
I tried update() method call but it’s showing all changesets including the ones had executed. Therefore, I was looking into the other method.
From your original post, I’m not able to tell what the actual error you’re seeing is. The stacktrace is just saying “error calling create table” but it’s not listing what that actual error was. Is there more of the stacktrace?
In your maven setup, you are setting defaultSchemaName = my_schema. Calling database.setDefaultSchemaName("my_schema") is the corresponding call in the java code. Probably best to call that right after creating the Database instance.
The defaultSchemaName will make it so the SQL generated by liquibase includes objects fully qualified to that schema.
Given that you’re also seeing unrun changes in update, I’m guessing that without the defaultSchemaName being set it is checking for the databasechangelog and databasechangeloglock tables in whatever schema is your connection’s default and not finding either. But, if you do setDefaultSchemaName("my_schema") it will do what you expect.
Glad to hear you got this working @tom2011 , this should be helpful to others with the same use case. Thanks for digging in, and thanks for answering @NathanVoxland