A database in one file

What SQLite is

Understand how an embedded database differs from a database server and why one ordinary file can hold a complete relational database.

SQLite is a relational database engine embedded inside the program that uses it. There is no separate server process to install, configure, or keep running.

Compare that with PostgreSQL or MySQL. Those are database servers: a separate program runs all the time, your application connects to it over a network socket, and it authenticates with a username and password. Someone has to install it, start it, patch it, and back it up.

SQLite removes all of that. It’s a library compiled into your application. When your code runs a query, the SQLite code inside your own process reads and writes the database directly. No network, no credentials, no daemon.

One file is the whole database

A database normally lives in one file. Your application opens that file and SQLite reads and writes it directly while still giving you tables, SQL, indexes, constraints, and transactions.

You can see this yourself. This shell command opens (and on first write, creates) a database:

sqlite3 notes.db

Inside the shell, plain SQL works exactly as you’d expect from any relational database:

SELECT sqlite_version();
-- 3.43.2

Everything you create inside it — every table, index, and row — ends up in that single notes.db file. Copy the file to another machine and you copied the database. Delete the file and the database is gone.

This is radically different from a server database, where the data lives inside a directory tree managed by the server and you interact with it only through connections.

Where you already use it

That small operational footprint is the main reason SQLite appears in local tools, desktop and mobile apps, tests, caches, and many web applications.

Your phone runs dozens of SQLite databases right now: browsers store history in it, messaging apps store conversations in it, macOS uses it throughout the system. It’s likely the most widely deployed database engine in the world.

One expectation to reset before you continue: “no server” does not mean “not a real database”. SQLite is ACID-compliant and tested obsessively. What it doesn’t do is accept connections from other machines. If a query needs to travel over a network, something else has to carry it. That boundary, and when it matters, is exactly what the next lesson covers.

Lesson completed

Take this course offline

Get every free book, course edition, and software download.

Get the download library →