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.
This is the file format of SQLite version 3. It arrived with SQLite 3.0.0 on 18 June
2004 as a new design, not a revision of SQLite 2’s, and every release since, up to
3.54.1 in October 2026, writes it. It has never been broken: each change since 3.0.0
only adds to it, so a file from 2004 still opens in today’s SQLite, and an older
SQLite 3 library reads a newer file unless it uses something added later, such as
write-ahead logging or schema format 4. Programs name these files freely:
.sqlite, .sqlite3, .db, .db3 and
.sqlitedb are common, and many applications use their own extension. See
all the SQLite formats.
A database file dropped on any page of this site opens in the explorer, which shows what every page is, opens each b-tree page into its header, cells and records, and shows the schema and the rows of every table.
Structure
The file is a run of pages of one size, a power of two from 512 to 65,536 bytes, numbered from 1. Page 1 starts with the 100-byte database header. Every number in the file that is not a varint is big-endian. A page’s job is not written on it, except on b-tree pages, which carry a type byte; the others are known from what points to them.
0Database headerSQLite format 3, the page size, the text encoding, the freelist and the other settings100 bytes100Schema table root the rest of page 1: a b-tree page listing every table, index, view and triggerrest of page 1…B-tree pages one b-tree for each table and index, of cells holding records1 page each…Overflow pages the rest of any cell too large for its page, in a chain1 page each…Freelist pages unused pages, kept for reuse1 page each…Pointer-map pages only in auto-vacuum files: the parent of every page1 page each
Reading a database
- Read the 100-byte header. Check the header string, take the page size from offset 16, the reserved space from offset 20 and the text encoding from offset 56.
- Page N starts at byte (N − 1) × page size. The usable size of a page is the page size minus the reserved space.
- Page 1 is the root of the schema table. Read its b-tree: each row gives an object’s type, name, table, root page and SQL.
- For each table or index, read its b-tree from the root page. Interior pages point to child pages; leaf pages hold the cells.
- Decode each cell’s payload as a record, following its overflow chain if it has one.
What has changed since 3.0.0
Versions that only add share a format; a version that changes existing structures is a separate format. Every change to the SQLite 3 file since 3.0.0 has been of the first kind, so this is one format from 2004 to today:
| Change | Version | Why it only adds |
|---|---|---|
| Auto-vacuum: pointer-map pages and the largest root page at header offset 52 | 3.1.0 (January 2005) | A new kind of page that no b-tree points to. Offset 52 was zero before, and zero still means no pointer maps. |
| Schema format 2: rows may hold fewer values than the table has columns | 3.1.3 (February 2005) | Records keep their layout; a missing value takes the column’s default. |
| Schema format 3: added columns may have non-NULL defaults | 3.1.4 (March 2005) | The same, with other defaults. |
| Schema format 4: DESC indexes, and serial types 8 and 9 for the integers 0 and 1 | 3.3.0 (January 2006) | Two new serial type values. A DESC index stores its entries in the other order, but every entry decodes the same way. |
| Incremental vacuum, header offset 64 | 3.4.0 (June 2007) | A field that was zero before. |
| Write-ahead logging: header bytes 18 and 19 set to 2 | 3.7.0 (July 2010) | A new value of an existing field. The file’s layout does not change; the changes wait in the separate -wal file. Older libraries refuse such a file, which is what the read version is for. |
| The in-header database size (offset 28) and version-valid-for number (offset 92) kept up to date | 3.7.0 (July 2010) | Fields older versions left alone. The size counts only when offset 24 equals offset 92, which keeps older files right. |
| 65,536-byte pages: the value 1 at offset 16 | 3.7.1 (August 2010) | A new value; no smaller page size changes. |
| WITHOUT ROWID tables | 3.8.2 (December 2013) | A table kept in an index b-tree, a structure that already existed. |
| Generated columns | 3.31.0 (January 2020) | Schema only; VIRTUAL columns are not stored. |
| STRICT tables | 3.37.0 (November 2021) | Schema only; records do not change. |
The nearest to a break is schema format 4, which changes the order of the entries in a DESC index. It is the order, not the layout or the decoding: a reader that does not know it still reads every page, cell and record correctly.
Files beside the database
While a program writes to a database, SQLite keeps other files next to it in the same folder, named after the database. They are formats of their own; see Journal modes.
- SQLite rollback journal (-journal) – the original content of the pages a transaction changes, used in rollback mode
- SQLite write-ahead log (-wal) – the changed pages themselves, appended until they are copied back, used in WAL mode
Telling it apart
The file starts with the 16 bytes 53 51 4C 69 74 65 20 66 6F 72 6D 61 74 20 33
00: SQLite format 3 and a zero byte.
The explorer’s parser for this format checks two things: those 16 bytes, and a page
size at offset 16 that is a power of two from 512 to 32,768, or 1 for 65,536. A file
that fails either check is turned down. Everything else it reports as a problem but
still shows. A file that starts with ** This file contains an SQLite is
an SQLite 2 database, which SQLite 3 cannot
open.
Also used for
- Windows thumbnail cache (Thumbs.db) – Windows thumbnail caches: a folder's hidden Thumbs.db (a Compound File of small pictures) and the per-user thumbcache_*.db files of Windows Vista and later.
Variants
- SQLite 3 database – SQLite 3.0.0 (2004) to today: b-tree pages, typed values, UTF-8 or UTF-16 text
- SQLite 2 database – SQLite 2.6 to 2.8 (2002 to 2005): 1,024-byte pages, every value text
Links
Software
- DB Browser for SQLite – free program to browse, edit and query SQLite databases (Windows, macOS, Linux)
- The sqlite3 command-line shell – SQLite’s own tool for running SQL against a database file (Windows, macOS, Linux)
- SQLiteStudio – free SQLite database manager (Windows, macOS, Linux)
- DBeaver – database tool that connects to SQLite and many other databases (Windows, macOS, Linux)
- Datasette – publishes an SQLite database as a website and JSON API
- sqlite3_analyzer – SQLite’s tool that reports how the pages of a database are used (Windows, macOS, Linux)
Developers
- SQLite – the SQLite library itself (C)
- sqlite3 – Python’s built-in SQLite module (Python)
- better-sqlite3 – fast synchronous SQLite binding (Node.js)
- SQLite JDBC – JDBC driver with SQLite built in (Java)
- rusqlite – SQLite binding (Rust)
- sql.js – SQLite compiled to WebAssembly, for browsers and Node.js (JavaScript)
- Microsoft.Data.Sqlite – Microsoft’s SQLite provider (.NET)
Reference
- Database File Format – SQLite’s own description of the file, the journal and the write-ahead log
- The Schema Table – SQLite’s page on sqlite_schema and its other names
- Release history – every SQLite release and what it changed
- History of SQLite releases – the date of every release
- SQLite Version 3 Overview – SQLite’s page on what changed from SQLite 2