Sql file not actually executed on database but entry made to databasechangelog table

Hi @AnuragEQX,

Yes please do send an email to support, and @SteveZ will respond back.

Ronak

Ronak, do you have your email id?, please share will include you as well.
also share the email id of SteveZ.
stevez@liquibase.com did not work.

I am heaving the Same exact issue (Liquibase is lacking idempotency, changelog table changes even if view creation fails ), what was the resolution for this one?

Does this issue resolved, I have similar issue.
Liquibase version 4.5.0
Database : MSSQL 13

Liquibase property file.

url: jdbc:sqlserver://10.10.11.150:1433;database=sonardb_89
username: sonar8
password: sonar8
driver: com.microsoft.sqlserver.jdbc.SQLServerDriver
classpath: …/drivers/mssql-jdbc-7.4.1.jre8.jar
liquibase.hub.mode=off


Database Change Log (DBChangelog.xml)

<?xml version="1.0" encoding="UTF-8"?>




SQL File (V1_CreateScripts.sql)

create table Liquibase250122
(
ReqSeq number
, Auth_RRNNumber varchar2(15)
, Auth_SeqID number
, RequestPacket varchar2(32767)
, Source varchar2(20)
, Addedon date default sysdate
);

Issue : Its same as mentioned in above trail.

  1. Liquibase executing update command without any error.
  2. Entry found in table DATABASECHANGELOG
  3. Shows also with history command
    DBChangelog.xml
  • Database updated at 2/4/22, 2:37 PM. Applied 1 changeset(s), DeploymentId: 3965623618
    DBChangelog.xml::1::RM

Liquibase command ‘history’ was executed successfully.

However no update on database

@sanjaykdalvi

We’ve encountered similar problem during deployment on production. Migration script was marked as executed in changelog, execution log contains this script and is described as “ran successfully”, but this operation was not reflected on database. This script is simple: one delete and one insert statements.

Is there any fix to avoid this situation to happen?

@mgrom , unfortunately there is no solution provided yet.
The issues appears once in a while and we deal reactively.

@ronak, seems many more face the same issue. hope we get solution soon.

Im seeing this same issue. Add a new changeLog file to our manifest that has two things in it, a sql change and a tagDatabase:

databaseChangeLog:
  - changeSet:
      id: tag-version-1.3
      author: thisguy
      changes:
        - include:
          file: ./my_correct_sql_file.sql
          relativeToChangelogFile: true
        - tagDatabase:
            schemaName: public
            tag: version_1.3```

its added to the manifest like so:
```    - include:
        file: ./tag-1.3.yml
        relativeToChangelogFile: true

and I run an updateToTag command with liquibase tag version_1.3

The sql file is a simple create table command, with 3 columns. id, name, enabled. The sql runs perfectly fine in a psql session.

End Result: version_1.3 tag is present in the databasechangelog table, the table created by the sql file doesnt exist.

Liquibase 3.10.0
of note, the deployment_id column for the row in databasechangelog is NULL, not sure if that indicates anything.

Is this fixed in any newer version?

is this issue resolved ?

It is highly unlikely that Liquibase is updating the DATABASECHANGELOG table without executing the SQL file since this is one of the most fundamental, well-trodden parts of Liquibase. While an error in Liquibase is not impossible, it’s just not the most likely cause of the issue.

I have seen situations where the expected behavior of a command doesn’t match what you see in the database. Here are a couple of common reasons why this could happen:

  • the change is being deployed to a different location (catalog or schema) than expected
  • the stored logic code is not behaving as expected (due to an unexpected code path being traversed, or a bug in the code)

With respect to the original issue, I would investigate the EXCEPTION statements in the stored logic code, understand when the exceptions could occur, and understand the behavior of the stored logic code when they do occur.

I found this article that discussed the reason for the EXCEPTION code and its behavior:

1. What is the purpose of adding the exception handler to the code? 
   What would happen if the exception handler were not there?

As Prakhar at comment#1 points out, WHEN OTHERS THEN NULL 
suppresses any error that might occur in the procedure.

If the exception handler were not there, then in case something 
goes wrong with the code – say, a duplicate record is inserted 
which violates a unique constraint – an error will be raised.

The explanation leads me to believe that any error seen from the execution of that statement will be supressed and the stored logic code will continue as if nothing wrong had occurred. This behavior could cause the reported problem. The problem wouldn’t be from Liquibase not running the command, but rather that the command was executed, got an error, suppressed the error, and returned as successful. I would suggest either removing the EXCEPTION block so the error is respected, or adding logging when the error occurs for traceability of the issue.

For some of the other comments where the change is a Liquibase changeset or a more basic DDL statement, I would suggest the following steps to better debug the situation:

  • Remove the corresponding record from the DATABASECHANGELOG table (so we can re-run the changeset)
  • Run the liquibase update-sql command (to see what SQL Liquibase intends to send to the database – Liquibase won’t send the SQL when you use this command)
  • Inspect the generated SQL to ensure that the catalog, schema, and SQL are what you expect them to be.
  • If everything looks correct, I would verify that the connection string connects to the expected database. (This one has tripped me up many, many times when I’m working on multiple targets and make a mistake or forget to change my target environment.)

If you try all of the above and are still getting stuck, I suggest opening a support case if you are a Liquibase customer, or opening a bug for the community to help that includes the following information:

  • the version of Liquibase you’re using and your target database platform and version
  • detailed steps to reproduce the problem including changelogs, connection details (removing the password and any other sensitive information), etc.
  • the actual results you see
  • the results you expected to see

Please provide as much information as possible to give everyone the best chance to help you troubleshoot the problem.

Commenting here incase it helps anyone-
My scenario is a simple one where I see same issue - entry added to databasechangelog for sql changeSet which is shown executed but is not actually getting executed.
The below statement should copy data from one column to another.

    <changeSet id="1" author="fateh">
        <sql dbms="psql">
            update keystore set encoded_value = encoded;
        </sql>
        <rollback>empty</rollback>
    </changeSet>

I can see the entry in the databasechangelog but the data is not copied from one column to another and I don’t see the command got executed in the history.
Changing dbms from “psql” to “postgresql” fixes the issue.

    <changeSet id="1" author="fateh">
        <sql dbms="postgresql">
            update keystore set encoded_value = encoded;
        </sql>
        <rollback>empty</rollback>
    </changeSet>

The above sql works as expected and data is copied as expected.

For reference-
Using liquibase with Spring
PostgreSQL 9.2.24
Liquibase 4.26

I would have ideally expected liquibase to throw an error/exception if it did not find dbms specified as psql valid