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. Its file format is documented in full by the SQLite project.
Versions that only add to the file share a format; a version that changes structures
already in it is a separate format. By that rule there are two SQLite database formats
in use. SQLite 3, from 2004 to today, has only ever added, so every SQLite 3 file is
one format. SQLite 2, from 2001 to 2005, changed its layout several times before
settling in 2.6.0; its files from 2.6.0 to 2.8.17 are the second format. Both are
often named .db or .sqlite, and SQLite 3 cannot open an
SQLite 2 file.
A database dropped on any page of this site opens in the explorer, which shows the kind of every page, opens each page into its cells and records, and shows the schema and the rows of every table. The explorer also opens the write-ahead log and the rollback journal that SQLite keeps beside a database.
Variations
| Format | Variation | About | Open |
|---|---|---|---|
.SQLITE | SQLite 3 database | A whole SQL database in one file: pages of b-trees, typed values, UTF-8 or UTF-16 text. | Open |
.SQLITE | SQLite 2 database | SQLite 2.6 to 2.8’s file: 1,024-byte pages in the machine’s byte order, every value text. | Open |
SQLite 3
The format of SQLite 3.0.0 (18 June 2004) and every release since, up to 3.54.1. It was a new design: SQLite’s notes for 3.0.0 call it a “new file format that is 25% to 35% smaller for typical use”. Pages of 512 to 65,536 bytes hold a b-tree for each table and index; values are stored as integers, floating-point numbers, text or BLOBs, and text is UTF-8 or UTF-16. Everything added since, from auto-vacuum to write-ahead logging and STRICT tables, only adds.
The file starts with the 16 bytes SQLite format 3 and a zero
byte.
SQLite 2
The format of SQLite 2.6.0 (18 July 2002) to 2.8.17 (19 December 2005), the last SQLite 2. Its b-tree is a different design, its pages are a fixed 1,024 bytes, its numbers are in the byte order of the computer that wrote the file, and every value is stored as text. SQLite 3 cannot open it; it has to be dumped as SQL and loaded again.
The file starts with the text ** This file contains an SQLite 2.1 database
** and a zero byte, the same text in every version from 2.1.0 on.
Older SQLite 2 files
SQLite 2.0.0 to 2.5.6, from September 2001 to July 2002, wrote three earlier layouts: 2.0’s, with a different cell header; 2.1’s, with different rowid keys; and 2.2 to 2.5’s, with different index keys. By the rule above each is a separate format. They share every structure with SQLite 2 apart from those details, so they are documented on one page, Older layouts, and the explorer reads them. Each lasted a few months, and SQLite 2.6.0 and later convert such a file the first time they open it, “automatically and irreversibly”.
SQLite 1.0: a different format
SQLite 1.0 (August 2000) is not a version of the SQLite database file: it has no single
database file, and what it writes is a different format, GDBM, which has a page of its own.
Its
storage layer was the GDBM library,
and a database was a directory holding one GDBM file for each table and each index,
named after it with .tbl added: the name is lower-cased, and any
character other than a letter, digit, -, _ or
. becomes +. The file sqlite_master.tbl plays
the part of the schema table. Temporary files are named
_temp_table_ or _temp_file_ and a random suffix.
Each entry of a GDBM file is a key and data of any length:
- A table’s key is the row’s 32-bit number, in the machine’s byte order and chosen at random. Its data is a record: one 32-bit offset in the machine’s byte order for each field, then the fields. An offset of 0 means NULL; any other is where the field’s text starts, and it is ended by a zero byte, numbers included.
- An index’s key is the indexed fields’ text joined by tab characters and ended by a zero byte. Its data lists the matching rows: one 32-bit row number, or for several, a count, the row numbers and spare slots of zero.
Drop the database’s folder on the explorer and it lists the schema, every table’s
rows and every index’s entries; drop one .tbl file, which is a GDBM
file, and it shows the GDBM header, directory, buckets, free-space lists and records
with this layout over them. The GDBM structures and the layout are described on the
GDBM page. SQLite 2.0 replaced this
layout with a b-tree in one file, and could not read it.
Versions
The releases that matter to the file, with the format each writes. Dates are from SQLite’s release history. SQLite 2.8 releases continued beside SQLite 3 until December 2005.
| Version | Released | What changed in the file | Format |
|---|---|---|---|
| 1.0 | 17 August 2000 | the first SQLite: a directory of GDBM files | SQLite 1.0 |
| 2.0.0 | 28 September 2001 | the first SQLite 2 file | older SQLite 2 |
| 2.1.0 | 12 November 2001 | the “2.1” header text; new cell and key layouts | older SQLite 2 |
| 2.2.0 | 22 December 2001 | file format 1: INTEGER PRIMARY KEY as the b-tree key | older SQLite 2 |
| 2.4.0 | 11 March 2002 | file format 2: rowids in insertion order; freelist trunk pages | older SQLite 2 |
| 2.6.0 | 18 July 2002 | file format 3: new index keys | SQLite 2 |
| 2.6.3 | 13 August 2002 | reads files of either byte order | SQLite 2 |
| 2.7.0 | 25 August 2002 | file format 4: numbers in text columns indexed as text | SQLite 2 |
| 2.8.0 | 16 February 2003 | a new journal format; the safety level in the header | SQLite 2 |
| 3.0.0 | 18 June 2004 | the new SQLite 3 format (an alpha release) | SQLite 3 |
| 3.0.8 | 12 October 2004 | – | SQLite 3 |
| 3.1.0 | 21 January 2005 | auto-vacuum, with pointer-map pages | SQLite 3 |
| 3.1.3 | 20 February 2005 | reads schema format 2 | SQLite 3 |
| 3.1.4 | 11 March 2005 | reads schema format 3 | SQLite 3 |
| 3.2.0 | 21 March 2005 | ALTER TABLE ADD COLUMN | SQLite 3 |
| 2.8.17 | 19 December 2005 | the last SQLite 2 | SQLite 2 |
| 3.3.0 | 11 January 2006 | schema format 4, the default for new files | SQLite 3 |
| 3.3.7 | 12 August 2006 | the default schema format goes back to 1 | SQLite 3 |
| 3.4.0 | 18 June 2007 | incremental vacuum | SQLite 3 |
| 3.6.0 | 16 July 2008 | reads freelist trunk pages with their last six entries in use | SQLite 3 |
| 3.7.0 | 21 July 2010 | write-ahead logging; the in-header database size | SQLite 3 |
| 3.7.1 | 23 August 2010 | 65,536-byte pages | SQLite 3 |
| 3.7.10 | 16 January 2012 | the default schema format becomes 4 | SQLite 3 |
| 3.8.2 | 6 December 2013 | WITHOUT ROWID tables | SQLite 3 |
| 3.31.0 | 22 January 2020 | generated columns | SQLite 3 |
| 3.37.0 | 27 November 2021 | STRICT tables | SQLite 3 |
| 3.45.0 | 15 January 2024 | – | SQLite 3 |
| 3.50.0 | 29 May 2025 | – | SQLite 3 |
| 3.51.0 | 4 November 2025 | – | SQLite 3 |
| 3.53.0 | 9 April 2026 | – | SQLite 3 |
| 3.54.0 | 9 October 2026 | – | SQLite 3 |
| 3.54.1 | 16 October 2026 | the latest release in November 2026 | SQLite 3 |
The header of every SQLite 3 file records the version that last wrote it, at offset 96. SQLite 2 files record only their file format number.
Files beside the database
While a program writes to an SQLite 3 database, SQLite keeps other files next to it, named after it. They are formats of their own:
- SQLite rollback journal (-journal) – the original content of the pages a transaction changes, kept to roll it back after a crash
- SQLite write-ahead log (-wal) – the pages a transaction changed, kept until a checkpoint copies them into the database
A database in write-ahead log mode also has a -shm file, the WAL index,
which SQLite rebuilds from the log when it is needed; see
Journal modes.
Not described
Not part of the format: SQLite 1.x is a different format from the SQLite 2 and 3 database files this page covers. It kept its data in GDBM files, a folder of them, with no database file of SQLite’s own, and SQLite 2.0 could not read it. It has its own page and its own record, GDBM database, and what is still unknown about it is listed there, not here.
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.
Links
Software
- DB Browser for SQLite – free program to browse, edit and query SQLite 3 databases (Windows, macOS, Linux)
- The sqlite3 command-line shell – SQLite’s own tool for running SQL against a database file (Windows, macOS, Linux)
Developers
- SQLite – the SQLite library itself (C)
Reference
- Database File Format – SQLite’s description of the SQLite 3 file, the journal and the write-ahead log
- SQLite Version 3 Overview – SQLite’s page on the changes from SQLite 2
- Release history – every SQLite release and what it changed
- History of SQLite releases – the date of every release
- SQLite 2.8.17 source – the last SQLite 2, with its file format document