title: Sqlite3 Disk I/O error encountered after a while, but worked after using copy of db
body: <p>I'm using an sqlite3 database to record data every second. The interface to it is provided by Flask-SQLAlchemy. </p>
  
  <p>This can work fine for a couple of months, but eventually (as the .db file approaches 8 GB), an error prevents any more data from being written to the database:<br>
  <code>Failed to commit: (sqlite3.OperationalError) disk I/O error</code></p>
  
  <p>The journal file does not seem to be the issue here - if I restart the application and use the pragma <code>journal_mode=TRUNCATE</code>, the journal file is created but the <code>disk I/O error</code> persists.</p>
  
  <p>Here's the .dbinfo (obtained from sqlite3.exe):</p>
  
  <pre><code>database page size:  1024
  write format:        1
  read format:         1
  reserved bytes:      0
  file change counter: 5200490
  database page count: 7927331
  freelist page count: 0
  schema cookie:       12
  schema format:       4
  default cache size:  0
  autovacuum top root: 0
  incremental vacuum:  0
  text encoding:       1 (utf8)
  user version:        0
  application id:      0
  software version:    3008011
  number of tables:    6
  number of indexes:   7
  number of triggers:  0
  number of views:     0
  schema size:         5630
  data version         2
  </code></pre>
  
  <p>However this worked:</p>
  
  <ol>
  <li>I made a copy of the .db file (call app.db and copy.db).</li>
  <li>I renamed app.db to orig.db</li>
  <li>I renamed copy.db to app.db (so effectively, I swapped it so that the copy becomes the app).</li>
  </ol>
  
  <p>When I started my application again, it was able to write to the app.db file once more! So I could write to a copy I made of the database.</p>
  
  <p>The drive is an SSD (Samsung 850 EVO mSATA)> I wonder if that's got something to do with it? Does anyone have any ideas on how I can prevent it from happening again?</p>
  
  <p>EDIT: I've used the sqlite3.exe CLI to execute an INSERT INTO command manually, and this actually completed successfully (and wrote to the disk). However, when I re-ran my Flask-SQLAlchemy interface to write to it, it still came up with the disk I/O error.</p>