HSQLDB "database already in use by another process" exceptions on UNIX

Installing a simple Grails application in Tomcat on Linux should really have been the most straightforward of tasks. Instead, I spent a progressively more frustrating morning chasing down a "helpful" feature of HSQLDB that was causing the startup to fail with

org.hsqldb.HsqlException: The database is already in use by another process:
org.hsqldb.persist.NIOLockFile@6b67bdbe[file =/myDb.lck, exists=true, locked=false, valid=false,
fl=null]

exceptions. To save others from a similar waste of time, here's the cause and a workaround:

Cause

Between versions 1.7.2. and 1.8.0.10., HSQLDB attempts to lock the files for file-based DBs in order to "[protect] the user from running the process twice with the same files and corrupting his data", apparently. Unfortunately, if your DB files reside on NFS, which doesn't support these locks, HSQLDB will blow up with the above exception.

It seems that there have been enough problems with this that HSQLDB has reverted to not using locks by default in 1.8.0.10., although this may be changed again in future versions, it seems.

Workaround(s)

  • Move your DB files to a non-NFS location
  • Upgrade to version 1.8.0.10. (or a pre-1.7.2. version)
  • Use a mem rather than a file DB

The details are described in this thread from the HSQLDB forums.

From what is mentioned there, it would seem to be possible to disable file locking somehow. I tried hsqldb.nio_data_file=false, but that doesn't seem to do the trick. If anyone finds out how to do this please add a comment!

Edited on 13 June 2012 to add: as pointed out in comments, it looks like I was using a slightly-too-old version and missing the hsqldb.lock_file=false option. Thanks!

Comments (3)

  1. Andrew Phillips - Reply

    March 23, 2009 at 9:21 am

    A colleague of mine raised a good point: "[Why] would you run Grails from an NFS share?"

    That's completely true, of course - in this case, it was due to the server, Tomcat and web application configurations, and these should be modified appropriately.

  2. Sandor Fiedler - Reply

    March 25, 2010 at 11:24 am

    Running in same problem using JBoss AS 5.1.0.GA (comes with HSQLDB 1.8.0.10) and finally got it working (at least for me):

    update hsqldbjar to 1.8.1.2
    edit the .properties file and setting hsqldb.nio_data_file=false and hsqldb.lock_file=false

  3. Sarjo - Reply

    June 13, 2012 at 8:50 pm

    I had the same problem with the database running on windows server.

    Got it working with hsqldb.jar 1.8.1.3 also by editing .properties file like this:
    hsqldb.nio_data_file=false
    hsqldb.lock_file=false

    It also works for me with "file:" protocol

Add a Comment