How to build statistics for an update run

There are hooks, but they are not trivial to implement. Datical has been doing just this sort of work on top of Liquibase. It may be more than you need though.

Logging is not the right place to put this. If you want to do it yourself, start by looking at the ChangeExecListener interface. You will need to run Liquibase programatically and then you can call setChangeExecListener() on the Liquibase object and then get calls back into your code whenever a changeset is run.

It would also be possible to extend the Liquibase integrations so that you could supply a listener via command line or ant or maven, etc.

Steve Donie
Principal Software Engineer
Datical, Inc. http://www.datical.com/

Liquibase is a great tool. I have just started using it to replace our mix of hand-crafted and generated .sql setup files.
One of the enhancements we’d like to make to our DB setup and upgrade process is to generate statistics on what SQL statements were run, how long they take, how many rows they affected, etc. The data would be in a JSON file that we could easily view in an HTML app.

Does Liquibase have any hooks for accumulating this kind of data? I noticed there are extensions for custom loggers, but I’m not sure if logging is the right layer for this. Are there other extension points that might be better suited to capturing performance data?

Thank you,
AHG

Thanks Steve, I’ll try out the ChangeExecListener. It looks like it could support what we need. I was planning on running Luquibase programmatically anyway as I need to also orchestrate the database setup and schema creation process.

I’ll update this topic with my results.

I implemented a change exec listener which generates a JSON file. I’ve created a gist with the source. It’s written in Scala, but it should be relatively easy to port over to Java.

https://gist.github.com/newyankeecodeshop/a1226709f36ec59e2269

Thanks again for the advice.

Nice! I’ve never done any Scala, but it is certainly readable. Seems like it would be pretty straightforward to translate to Java or Groovy or whatever.

I like your github username, by the way.

Steve Donie
Principal Software Engineer
Datical, Inc. http://www.datical.com/

I have pushed a PR for supporting setting a ChangeExecListener and Properties file for the listener instance via the command line.

The properties added are:

  • changeExecListenerClass

* changeExecListenerPropertiesFile

As part of this change the ChangeExecListener can have one of several constructors, which will be determined at run time using some reflection.

ChangeExecListener()
ChangeExecListener(Database db, Properties props)
ChangeExecListener(Database db)
ChangeExecListener(Properties props, Database db)
ChangeExecListener(Properties props)

I also added a default impl of the ChangeExecListener which means you can override it and just implement the methods you need.

liquibase.changelog.visitor.ChangeExecListenerAdaptor

https://github.com/liquibase/liquibase/pull/505