title: How do I prevent SQLite database locks?
body: <p>From sqlite FAQ I've known that:</p>
  
  <blockquote>
    <p>Multiple processes can have the same database open at the same time.
    Multiple processes can be doing a SELECT at the same time. But only
    one process can be making changes to the database at any moment in
    time, however.</p>
  </blockquote>
  
  <p>So, as far as I understand I can:
  1) Read db from multiple threads (SELECT)
  2) Read db from multiple threads (SELECT) and write from single thread (CREATE, INSERT, DELETE)</p>
  
  <p>But, I read about <a href="http://www.sqlite.org/wal.html"><strong>Write-Ahead Logging</strong></a> that  provides more concurrency as <em>readers do not block writers and a writer does not block readers</em>. Reading and writing can proceed concurrently.</p>
  
  <p>Finally, I've got completely muddled when I found <a href="http://www.sqlite.org/cvstrac/wiki?p=DatabaseIsLocked&amp;t=1292363538">it</a>, when specified:</p>
  
  <blockquote>
    <p>Here are other reasons for getting an SQLITE_LOCKED error:</p>
    
    <ul>
    <li>Trying to CREATE or DROP a table or index while a SELECT statement is
    still pending. </li>
    <li>Trying to write to a table while a SELECT is active on that same table. </li>
    <li>Trying to do two SELECT on the same table at the same time in a
    multithread application, if sqlite is not set to do so. </li>
    <li>fcntl(3,F_SETLK call on DB file fails. This could be caused by an NFS locking
    issue, for example. One solution for this issue, is to mv the DB away,
    and copy it back so that it has a new Inode value</li>
    </ul>
  </blockquote>
  
  <p>So, I would like to clarify for myself, when I should to avoid the locks? Can I read and write at the same time from two different threads? Thanks.</p>