close

[Solved] OperationalError: database is locked

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error OperationalError: database is locked in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How OperationalError: database is locked Error Occurs?

Today I get the following error OperationalError: database is locked in python.

How To Solve OperationalError: database is locked Error ?

  1. How To Solve OperationalError: database is locked Error ?

    To Solve OperationalError: database is locked Error In my case, It was because I open the database from SQLite Browser. When I close it from the browser, the problem is gone.

  2. OperationalError: database is locked

    To Solve OperationalError: database is locked Error In my case, It was because I open the database from SQLite Browser. When I close it from the browser, the problem is gone.

Solution 1

As others have told, there is another process that is using the SQLite file and has not closed the connection. In case you are using Linux, you can see which processes are using the file (for example db.sqlite3) using the fuser command as follows:

$ sudo fuser -v db.sqlite3
                     USER        PID ACCESS COMMAND
/path/to/db.sqlite3:
                     user        955 F....  apache2

If you want to stop the processes to release the lock, use fuser -k which sends the KILL signal to all processes accessing the file:

sudo fuser -k db.sqlite3

Note that this is dangerous as it might stop the web server process in a production server.

Thanks to @cz-game for pointing out fuser!

Solution 2

In my case, It was because I open the database from SQLite Browser. When I close it from the browser, the problem is gone.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read

Leave a Comment