Storage Format Guide
Database File Structure
Page size: power of 2, 512-65536 bytes. Default 4096.
Database Header (First 100 Bytes)
All multi-byte integers: big-endian.
Page Types
B-tree Structure
Two B-tree types:
- Table B-tree: 64-bit rowid keys, stores row data
- Index B-tree: Arbitrary keys (index columns + rowid)
Page 1 always root of sqlite_schema table.
Cell Format
Table Leaf Cell
Table Interior Cell
Index Cells
Similar but key is arbitrary (columns + rowid), not just rowid.
Record Format (Payload)
Serial types:
Overflow Pages
When payload exceeds threshold, excess stored in overflow chain:
Last page has next_page=0.
Freelist
Linked list of trunk pages, each containing leaf page numbers:
Turso Implementation
Key files:
core/storage/sqlite3_ondisk.rs- On-disk format,PageTypeenumcore/storage/btree.rs- B-tree operations (large file)core/storage/pager.rs- Page managementcore/storage/buffer_pool.rs- Page caching


