.SQLITE
SQLite database file
Introduction
SQLite is a complete SQL database held in a single file, read and written by a small library built into the program that uses it. D. Richard Hipp released it in 2000. It ships inside every major web browser and phone operating system, so SQLite files are among the most common files in the world.
The file format has been stable and backwards compatible since SQLite 3.0 in 2004.
Programs name these files freely: .sqlite, .sqlite3 and
.db are common, and many applications use their own extension.
Software
- DB Browser for SQLite (Windows, macOS, Linux)
- The sqlite3 command-line shell (Windows, macOS, Linux)
- SQLiteStudio (Windows, macOS, Linux)
- DBeaver (Windows, macOS, Linux)
- Datasette, which publishes a database as a website
- Python, whose
sqlite3module is built in
Structure
The file is divided into pages of equal size, a power of two from 512 to 65,536 bytes.
Page 1 starts with a 100-byte header, beginning with the 16 bytes
SQLite format 3 and a zero byte. All numbers in the header are
big-endian.
| Offset | Size | Holds |
|---|---|---|
0 | 16 | the header string |
16 | 2 | page size in bytes; the value 1 means 65,536 |
18, 19 | 1, 1 | write and read versions: 1 for the rollback journal, 2 for write-ahead logging |
28 | 4 | size of the database in pages |
32, 36 | 4, 4 | first free-list page and the number of free pages |
56 | 4 | text encoding: 1 UTF-8, 2 UTF-16LE, 3 UTF-16BE |
60, 68 | 4, 4 | user version and application ID, set by the program |
96 | 4 | the SQLite version that last wrote the file |
Every table and every index is a B-tree of pages. The rest of page 1 is the root of the
schema table, sqlite_schema, which lists every table, index and view with
its SQL and the page number of its root. Unused pages sit on a free list. While a
database is open in write-ahead logging mode, changes may also be held in the
-wal and -shm files beside it.
0Page 1 the 100-byte header, then the schema table’s root1 page…Pages 2 onwards B-tree pages for tables and indexes, overflow and free pages1 page each