I am trying to read an sqlite3 db into memory for further processing using python like so:
con = sqlite3.connect(':memory:')
print('Reading sqlite file into memory... ', end='', flush=True)
src_con.backup(con) # <---- This line seems to hang, SOMETIMES
print('Completed')
src_con.close()
cur = con.cursor()
While the code works fine most of the times, occasionally I observe a hang in the line src_con.backup(con)
.
This db is dumped by a process that I dont own on a shared network disk.
Here are my observations based on the advice I have found elsewhere on the internet:
fuser filename.db
does not show any processes from my user accountsqlite3 filename.db "pragma integrity_check;"
returnsError: database is locked
- the md5sum of the
filename.db
(the db that hangs) and its copyfilename2.db
(doesn't hang) are identical. So is the OS locking the db - because the lock info is not in the DB file itself? - This locked DB appears to occur when the process creating it did not exit cleanly.
Copying the db out (into say, filename2.db
) and reading it is a workaround - but I want to understand whats going on and why - and if there is a way to read the locked DB in read-only mode.