If the database is "new" and "empty" the following conditions hold: `select count(*) from sqlite_master;` will be 0 `pragma journal_mode;` will be 'delete' `pragma application_id;` will be 0 `pragma user_version;` will be 0 `pragma page_count;` will be 0 If these conditions all hold then do: ``` pragma locking_mode=exclusive; begin immediate; pragma application_id=(some non-zero number) pragma user_version=(some non-zero number) commit; ``` If you get here, then you have exclusive access to the database so that you can do your initialization after which you do: ``` pragma locking_mode=normal; pragma journal_mode=wal; ``` and you are good to go. If any of the pre-conditions fail, then this is not a "new and empty database" and if the application_id/user_version are not what you want then you need to wait a bit and check again, eventually bailing because it is not a database you can work with.