On Wed, Nov 18, 2009 at 08:31:24PM -0000, Matt scratched on the wall:
> Hello,
> 
> Given a sqlite database file I would like to create two lists: one of
> bytes which are in use and one of bytes which are "free".
> What would be the most efficient way to do this?

  You have to define "free."  Blocks of bytes are managed in pages.
  There are free pages, and then there is free space within a page.
  Free pages can be re-used for nearly anything.  Free space within a
  page is a lot harder to recover, and can only be used for specific
  things, depending on how the page is allocated.  "Free" space within
  pages is just a fact of life, not unlike block allocations in a
  filesystem.

  PRAGMA page_count will return the total number of pages in a
  database file.  PRAGMA freelist_count will return the number of free
  pages.  PRAGMA page_size will return the number of bytes per page.

  You can expect a VACUUM to shrink a database file at least
  freelist_count * page_size bytes.  Maybe a bit more if it can recover
  some of the intra-page free space.

   -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