Use sqlite locking on db file

As blurted out on irc yesterday, the improves reliability against sqlite access conflicts (sqlite manages conflicts), and ensures tables are created without clobbering or sql error handling.

Use CREATE INDEX/TABLE IF NOT EXISTS to prevent DB errors and
preserve creation functionality for new instances.