On Thu, Mar 25, 2010 at 10:56:40PM +0800, Tim scratched on the wall:
> 
> I have a 32MB hard disk. My OS is about 17MB and my application's size is
> about 3MB. So there is only 10MB for program data.
> 
> My database is about 4.74MB. When I perform following sql query in a
> transaction
> 
> sqlite3_exec(m_sqlite3, "delete from table", 0, 0, &errmsg);
> 
> I got the error "database or disk is full". I guess when do the transaction,
> the database was duplicated, and it caused no free disk space.

  The database is not duplicated, but a journal file is going to be
  created that needs to hold a copy of every page the delete command
  touches.  If this is the main table in that database, that will be
  most of the database.  This will happen if the delete is inside an
  explicit transaction or not.

  That's just the first of your problems, however.  Even if the delete
  command worked, the database file would not get any smaller.  To
  actually recover the disk space you need to VACUUM the database.
  That does copy the database, plus creating a journal file, so it
  requires up to 2x the size of the database in freespace-- although in
  your case the copy would be much smaller, so you might get away with 
  ~1x the free space.

  The *safest* way to get past the delete is to delete a small number of
  rows at a time.  The journal file will grow roughly in step with the
  number of deleted rows.  So if you delete 10% of the rows at a time
  (as different transactions) you may be able to get by on more limited
  space.  In the end, the database size will remain the same however.
  You'll still need to VACUUM to make the database smaller, and you
  still won't have room to do that.  You will have room to add new
  rows, however.

  The *easiest* way to get around this is to turn off journaling.  The
  delete should take no extra disk space and the vacuum should only
  need enough free space to hold the a copy of the new database.  Of
  course, if anything goes wrong or you run out of space anyways,
  your original database is toast.  Make sure you back it up first.

  http://www.sqlite.org/pragma.html#pragma_journal_mode


   -j

-- 
Jay A. Kreibich < J A Y  @  K R E I B I.C H >

"Our opponent is an alien starship packed with atomic bombs.  We have
 a protractor."   "I'll go home and see if I can scrounge up a ruler
 and a piece of string."  --from Anathem by Neal Stephenson
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to