On Sun, Mar 14, 2010 at 5:18 PM, Jay A. Kreibich <j...@kreibi.ch> wrote: > On Sun, Mar 14, 2010 at 07:19:59PM -0400, Matthew L. Creech scratched on the > wall: >> I have a SQLite database with one large table, and I'd like to shrink >> the size of that table to free up space in the filesystem. My problem >> is that the database is (for example) 100 MB, and I have 80 MB of free >> filesystem space. I figured that I could DELETE, say, half of the >> records from the table, then VACUUM, and the VACUUM would >> [temporarily] need ~50 MB of free space for the journal (since that's >> how much real data there is). >> >> Instead, I'm finding that it needs a full 100 MB for the journal, even >> though once the VACUUM succeeds the resulting DB is only 50 MB. As a >> result, I'm stuck unable to shrink the database, since VACUUM fails >> with a disk I/O error (out of space), seemingly no matter many entries >> I remove ahead of time. I know the space is being freed, since >> "PRAGMA freelist_count" shows the expected numbers. So presumably >> this is just an artifact of the way VACUUM is implemented internally. > > Are you sure it is the journal file that is growing too large? > > VACUUM works by making a logical copy of the database from the > original database into a temp database. This restructures the > database and recovers space. The temp database is then copied back > to the original database using low-level page copy. This low-level > copy then truncates the original database file, recovering > filesystem space. > > This also means the total space required to VACUUM a database is: > [old database size] + [new database size] + [journal file] > > While I have not tested this, I was under the impression that the > journal file is very very small, as no modifications are made to the > database, other than the final low-level copy (which is not a > journaled operation).
AFAICT, the operation to copy the pages back _is_ journaled, and the journal will get any pages which are overwritten in the front of the main database. If the initial database has half of the pages used, it seems like the journal could range from almost nothing (if the used pages were mostly at the end) to almost half the database size (if the used pages were mostly at the front), so to be safe one would need 2x the final database size available. I could be mis-reading the code. -scott _______________________________________________ sqlite-users mailing list firstname.lastname@example.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users