Forums

sqlite3 databases locked

Hey guys,

All of my apps databases are suddenly locked. Just randomly started happening today.

Not sure if this is a common issue - i have seen one thread about it from a couple of years ago - https://www.pythonanywhere.com/forums/topic/143/

Is anyone else experiencing this issue? Another app of mine with a very similar setup is unaffected by this, so it seems it could be specific to my app.

Any help is much appreciated!

Hi there, when you say the databases are "locked", what are the symptoms?

Sorry - i've lost the error tickets. From my understanding our app encountered an OperationalError each time we tried to write something to one of our databases. "OperationalError: database is locked..." or something along the lines of that. Sorry I can't give you any more info because the problem is no longer persisting.

One change we have made involved adding a line of code to the db.py file that included db.execute('PRAGMA journal_mode=WAL') - which may have fixed things. If you know what this would have done I'd love to know!

Apparently we only needed it for a single run, so now this line has been removed and the app seems to be functioning properly.

Very strange! It looks like the other issue back in 2012 was related to a wider set of system issues (IIRC we'd made some changes to our core infrastructure and were still ironing out the bugs) but that's not applicable now. Perhaps something that was accessing one of the DBs crashed keeping the lock, and the PRAGMA change cleared that down?

BTW we definitely recommend you consider MySQL or Postgres for any high-volume DB access. SQLite is a great database, but because our filesystem is based on NFS, it can have problems on PythonAnywhere once volume gets high.