How do I unlock a SQLite database?

前端 未结 30 1421
栀梦
栀梦 2020-11-22 15:56
sqlite> DELETE FROM mails WHERE (`id` = 71);
SQL error: database is locked

How do I unlock the database so this will work?

30条回答
  •  忘了有多久
    2020-11-22 16:29

    An old question, with a lot of answers, here's the steps I've recently followed reading the answers above, but in my case the problem was due to cifs resource sharing. This case is not reported previously, so hope it helps someone.

    • Check no connections are left open in your java code.
    • Check no other processes are using your SQLite db file with lsof.
    • Check the user owner of your running jvm process has r/w permissions over the file.
    • Try to force the lock mode on the connection opening with

      final SQLiteConfig config = new SQLiteConfig();
      
      config.setReadOnly(false);
      
      config.setLockingMode(LockingMode.NORMAL);
      
      connection = DriverManager.getConnection(url, config.toProperties());
      

    If your using your SQLite db file over a NFS shared folder, check this point of the SQLite faq, and review your mounting configuration options to make sure your avoiding locks, as described here:

    //myserver /mymount cifs username=*****,password=*****,iocharset=utf8,sec=ntlm,file,nolock,file_mode=0700,dir_mode=0700,uid=0500,gid=0500 0 0
    

提交回复
热议问题