Astdb error (but sqlite3 file is ok)

I’m using Asterisk 13.7.2 and on start I see errors like show below. I used the ‘database show’ command to confirm the astdb is empty. However, there should be lots of keys! I verified the /var/lib/asterisk/astdb.sqlite3 file exists, it has 775 permission and is owned by asterisk:asterisk. When I use ‘sqlite3’ command to dump the file I see LOTS of keys.

So why isn’t Asterisk reading/loading the database? When I try to to write a key with ‘databse put test 1 b’ I see ast_db_put: Couldn’t execute statement; not an error. Hmmm…seems like an error.

[2017-01-18 22:22:20] WARNING[19230]: db.c:332 ast_db_put: Couldn't execute statment: not an error
[2017-01-18 22:22:20] WARNING[19230]: db.c:332 ast_db_put: Couldn't execute statment: not an error
[2017-01-18 22:22:20] NOTICE[19230]: app_queue.c:8550 reload_queue_rules: queuerules.conf has not changed since it was last loaded. Not taking any action.
[2017-01-18 22:22:42] WARNING[23949]: db.c:332 ast_db_put: Couldn't execute statment: not an error
[2017-01-18 22:22:43] WARNING[23949]: db.c:332 ast_db_put: Couldn't execute statment: not an error
[2017-01-18 22:23:00] WARNING[19309][C-000000c1]: db.c:332 ast_db_put: Couldn't execute statment: not an error
[2017-01-18 22:23:00] WARNING[19309][C-000000c1]: func_db.c:180 function_db_write: DB: Error writing value to database.
[2017-01-18 22:23:00] WARNING[19309][C-000000c1]: db.c:332 ast_db_put: Couldn't execute statment: not an error
[2017-01-18 22:23:00] WARNING[19309][C-000000c1]: func_db.c:180 function_db_write: DB: Error writing value to database.
[2017-01-18 22:23:00] WARNING[19309][C-000000c1]: db.c:332 ast_db_put: Couldn't execute statment: not an error
[2017-01-18 22:23:00] WARNING[19309][C-000000c1]: db.c:332 ast_db_put: Couldn't execute statment: not an error

A reload did nothing, but shutting down and restarting asterisk worked. However, that’s not an acceptable solution (i can’t monitor Asterisk after every boot to ensure the astdb loaded).

The asterisk log shows func_db.so loaded as follows - which I don’t think is a clue.

[2017-01-18 19:16:10] VERBOSE[23668] loader.c: Loading func_db.so. 
[2017-01-18 19:16:10] VERBOSE[23668] pbx.c: Registered custom function 'DB'
[2017-01-18 19:16:10] VERBOSE[23668] pbx.c: Registered custom function 'DB_EXISTS'
[2017-01-18 19:16:10] VERBOSE[23668] pbx.c: Registered custom function 'DB_DELETE'
[2017-01-18 19:16:10] VERBOSE[23668] pbx.c: Registered custom function 'DB_KEYS'
[2017-01-18 19:16:10] VERBOSE[23668] loader.c: func_db.so => (Database (astdb) related dialplan functions)

Is there a way to FORCE Asterisk to close the file handle and try to re-open the astdb.sqlite3 file?

There’s currently no mechanism to have the AstDB close the sqlite database and reopen it.