Fast database shutdown and improved locking