Search code examples
linuxsqlitedebiannfs

Locked sqlite IN THE WHOLE SYSTEM


i got a big problem in my system. Some how, the entire sqlite sistem become locked. I am not talking about a single database, i am talking about every database in the system.

ladb08@newcastle:~$ touch new.sqlite3
ladb08@newcastle:~$ sqlite3 new.sqlite3 
SQLite version 3.7.3
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .tables
Error: database is locked
sqlite> 

Even firefox cant open properly because of the same problem. I got no idea of why this happened. This server is a debian server, and it is used by my team to develop some site with rails. We centralize the stuff in a external git repo so everyone work with his own user, and with his own copy of the stuff.

Another test:

ladb08@newcastle:~/agendador/db$ lsof test.sqlite3 
ladb08@newcastle:~/agendador/db$ fuser test.sqlite3 
ladb08@newcastle:~/agendador/db$ strace -e fcntl sqlite3 test.sqlite3 .tables
fcntl(3, F_GETFD) = 0
fcntl(3, F_SETFD, FD_CLOEXEC) = 0
fcntl(4, F_GETFD) = 0x1 (flags FD_CLOEXEC)
fcntl(3, F_SETLK, {type=F_RDLCK, whence=SEEK_SET, start=1073741824, len=1}) = -1 ENOLCK (No locks available)
Error: database is locked

No one is using the database. And the same occurs to empty new ones.

===========================================================================

More info:

root@newcastle:~# cd /home/ladb08/agendador/db/            
root@newcastle:/home/ladb08/agendador/db# sqlite3 test.sqlite3
SQLite version 3.7.3
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .tables
Error: database is locked
sqlite> .exit

The problem, as usual.

root@newcastle:~# cd /root           
root@newcastle:~# cp /home/ladb08/agendador/db/test.sqlite3 ./
root@newcastle:~# sqlite3 test.sqlite3
SQLite version 3.7.3
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .tables
agendamentos              prefeituras               tipo_atendimentos      
bloqueios                 profissionais             tipo_situacoes         
cidadaos                  schema_migrations         tmibges                
escalas                   tcbos                     tufibges               
orgaos                    tconselhos             
orgaos_tipo_atendimentos  tipo_acoes             

Outside the nfs partition, no problem with the same file.

root@newcastle:~# mount
(...)
rootfs on / type rootfs (rw)
urquell.home2:/home2/home-newcastle on /home type nfs (rw,v3,addr=10.17.116.3)
fusectl on /sys/fs/fuse/connections type fusectl (rw)

Solution

  • The error code ENOLCK is returned when the kernel runs out of memory for locks (unlikely in your case) or when a locking operation over a remote file system like NFS failed.

    Apparently, your file server is configured to not support file locking.
    (Whether that would be a good idea is debatable.)