Fix #9563 Use a lock file for the database

The old hack by using sqlite locking seems to no longer work with newer
sqlite releases. So let's change to lock files.