An SQLite 3 database is a run of pages, all the same size. Every byte of the file belongs to exactly one page, and each page has one job: part of a b-tree, part of an overflow chain, a free page, a pointer map, or the lock-byte page. Only b-tree pages say what they are; a reader learns what every other page is from what points to it.
Page numbers
Pages are numbered from 1. With a page size of P bytes, page N starts at byte (N − 1) × P, so page 1 is at offset 0 and holds the database header in its first 100 bytes. Page numbers are 32-bit, and 0 means “no page” wherever a page number is stored.
The file holds whole pages. A file whose length is not a multiple of the page size is damaged or was copied while it was being written; the explorer shows the bytes after the last whole page as an incomplete page. The number of pages is the file’s length divided by the page size, unless the in-header database size is valid and smaller.
| Page size | Files examined for this site |
|---|---|
| 1,024 | 49 |
| 2,048 | 2 |
| 4,096 | 134 |
| 32,768 | 4 |
No file used 512, 8,192, 16,384 or 65,536 bytes, though all are allowed.
Kinds of page
| Kind | How a reader knows it | Described in |
|---|---|---|
| Table interior, table leaf, index interior, index leaf | A type byte at the start of the page header (5, 13, 2, 10), and the b-tree that reaches it | B-tree pages |
| Overflow page | A cell or an earlier overflow page points to it | Overflow pages |
| Freelist trunk page | The header, or an earlier trunk, points to it | Freelist |
| Freelist leaf page | A trunk page lists it | Freelist |
| Pointer-map page | Its position, in a file whose header offset 52 is not zero | Pointer-map pages |
| Lock-byte page | Its position: the page holding byte 1,073,741,824 | below |
The explorer learns every page’s kind in one pass:
- the lock-byte page and the pointer-map pages, whose places follow from the header;
- the schema table’s b-tree from page 1, whose rows give the root page of every table and index; then each of those b-trees, page by page, following each cell’s overflow chain;
- the freelist: each trunk page and the leaf pages it lists.
A page reached twice, or a pointer to a page that is not in the file, is reported as a problem.
The lock-byte page
The page that holds bytes 1,073,741,824 to 1,073,742,335, the 512 bytes starting at the 1 GiB mark. Only a database larger than 1 GiB has one. SQLite never reads or writes it: the operating-system layer may use those bytes for file locks. It exists because Windows 95 offered only mandatory locks, which stop other processes reading the locked bytes, so the locks were put on bytes that hold no data.
Its page number is 1,073,741,824 ÷ page size + 1. With 4,096-byte pages it is page 262,145; with 1,024-byte pages, page 1,048,577.
The reserved region
When the header’s reserved space at offset 20 is not zero, that many bytes at the end of every page are set aside for extensions, such as encryption. Every structure on the page works within the usable size, the page size minus the reserved space. The lock-byte page has no reserved region, since nothing is stored on it.
Unused pages
A page that none of the passes above reaches. This is the explorer’s own term, not SQLite’s. In a healthy file there are none: every page is part of a b-tree, an overflow chain or the freelist, or is a pointer-map or lock-byte page. Pages past a valid in-header database size are not part of the database; SQLite ignores them, and the explorer shows them as past the database size.