db: set up locks for r/w database access
db: keep open in read-only mode, lock and open in read-write on demand