Log inSign up

Running SQLite reliably on a Linux server

Install the command line shell with sudo apt install sqlite3 or sudo dnf install sqlite, then turn on write-ahead logging once per database with PRAGMA journal_mode=WAL; so readers and a writer can work at the same time. Have every connection set a busy timeout, keep the database on local disk in a directory the app can write to, and back it up with .backup or VACUUM INTO, never with a plain file copy of a busy database.

Topic: Go, Ruby, Java and other runtimes · Tested on: Ubuntu 24.04 and 22.04, Debian 12 and 13, Rocky Linux 9, AlmaLinux 9 · Updated 2026-12-03

When is SQLite the right database for a server app?

SQLite fits whenever one server owns the data and writes come in at a modest, steady pace. It is a library, not a daemon: your application opens a file and reads and writes it directly, so there is no service to tune, no network port to secure and no separate user accounts. Personal tools, small SaaS backends, bots, dashboards and read-heavy websites run well on it, and reads in particular are very fast because they never leave the process.

Pick a server database instead when several machines must write to the same data, when you expect many concurrent writers, or when you need roles and per-user permissions inside the database. In those cases see the PostgreSQL guide. Moving later is possible, so starting small with SQLite is a reasonable choice.

How do you install the sqlite3 shell?

The library is already present on every image because the package managers use it; what you usually add is the interactive shell.

# Ubuntu and Debian
sudo apt update
sudo apt install -y sqlite3

# Rocky Linux and AlmaLinux 9
sudo dnf install -y sqlite

sqlite3 --version

Versions differ by release: roughly 3.45 on Ubuntu 24.04, 3.37 on Ubuntu 22.04, 3.40 on Debian 12, 3.46 on Debian 13 and 3.34 on Rocky and Alma 9. Everything on this page works on all of them unless a section says otherwise. Language bindings report the library version they use, which can differ from the shell:

python3 -c "import sqlite3; print(sqlite3.sqlite_version)"

How do you create a database and work in the shell?

Open a file path with sqlite3; the file is created on the first write. Dot commands control the shell itself, and plain SQL ends with a semicolon.

mkdir -p ~/data
sqlite3 ~/data/app.db
.mode box
.headers on
CREATE TABLE notes (id INTEGER PRIMARY KEY, body TEXT NOT NULL, created_at TEXT DEFAULT CURRENT_TIMESTAMP);
INSERT INTO notes (body) VALUES ('first note'), ('second note');
SELECT * FROM notes;
.tables
.schema notes
.quit

You can also run one statement from a script: sqlite3 ~/data/app.db "SELECT count(*) FROM notes;". Older shells, such as the one on Rocky 9, lack .mode box; use .mode column there.

Why and how do you enable WAL mode?

Write-ahead logging lets readers keep reading while a writer commits, which is exactly what a web app needs. In the default rollback mode a write locks out readers for its duration. WAL is a property of the database file, so you set it once and it stays:

sqlite3 ~/data/app.db "PRAGMA journal_mode=WAL;"

The command prints wal on success. From then on you will see two companion files next to the database, app.db-wal and app.db-shm. They are part of the database: never delete them while anything has it open, and copy all three together if you ever move a stopped database.

Other settings apply per connection, so put them in your application where it opens the database:

PRAGMA busy_timeout = 5000;
PRAGMA synchronous = NORMAL;
PRAGMA foreign_keys = ON;

The busy timeout makes a connection wait up to five seconds for a lock instead of failing at once with database is locked. synchronous=NORMAL is safe in WAL mode and much faster than the default; a power loss can lose the last commits but not corrupt the file. Foreign key checks are off by default for historical reasons.

Where should the database file live?

Keep it on the local SSD or NVMe disk, in a directory owned by the user your app runs as. SQLite needs write permission on the directory, not only the file, because it creates the WAL and journal files next to it. A permission error that mentions a read-only database usually means the directory is not writable.

sudo mkdir -p /var/lib/myapp
sudo chown myapp:myapp /var/lib/myapp
sudo chmod 750 /var/lib/myapp
ls -ld /var/lib/myapp

Do not put SQLite files on network file systems such as NFS or SSHFS; file locking there is unreliable and corruption follows. For services managed by systemd, StateDirectory=myapp creates the directory with the right owner automatically, as described in systemd services.

How do you back up a live SQLite database?

Use the online backup command or VACUUM INTO; both produce a consistent snapshot while the app keeps running. A plain cp of an active database can capture a half-written state and miss data still in the WAL file.

sqlite3 /var/lib/myapp/app.db ".backup '/var/backups/myapp/app-$(date +%F).db'"
sqlite3 /var/lib/myapp/app.db "VACUUM INTO '/var/backups/myapp/app-compact.db'"

.backup copies pages as they are; VACUUM INTO writes a compacted, defragmented copy and needs version 3.27 or newer, which every supported image has. Verify a backup before trusting it:

sqlite3 /var/backups/myapp/app-$(date +%F).db "PRAGMA integrity_check;"

It should print ok. Schedule the backup in a small script with a cron job or a timer, compress old copies, delete the oldest ones, and send them off the server with a tool such as rclone. The BitcoinVPS daily backup add-on is a useful second layer, but an app-level copy lets you restore one database without rolling back the whole disk.

How do you get a newer SQLite version?

For the shell alone, use the precompiled Linux tools from the sqlite.org download page; for a newer library inside your application, the usual path is a language package that bundles its own SQLite, since replacing the system library can break the package manager. Copy the link to the current sqlite-tools-linux-x64 zip from the download page:

sudo apt install -y unzip        # or: sudo dnf install -y unzip
SQLITE_ZIP_URL="paste-the-sqlite-tools-linux-x64-link"
mkdir -p ~/sqlite-new && cd ~/sqlite-new
curl -fsSL -o tools.zip "$SQLITE_ZIP_URL"
unzip -o tools.zip
sudo install -m 0755 sqlite3 /usr/local/bin/sqlite3
hash -r
sqlite3 --version

/usr/local/bin comes before /usr/bin on PATH, so the new shell wins while the system copy stays in place for the package manager. Recent tool bundles also contain sqlite3_rsync, available from version 3.47, which copies a live database to another path or host efficiently. Examples of bundled builds are the better-sqlite3 package for Node.js and the pysqlite3-binary wheel for Python.

How do you keep queries fast and fix common errors?

Indexes and fresh statistics solve most slow queries. Ask SQLite how it plans to run a query and add an index on columns used in WHERE and JOIN clauses:

EXPLAIN QUERY PLAN SELECT * FROM notes WHERE created_at > '2026-01-01';
CREATE INDEX idx_notes_created ON notes(created_at);
PRAGMA optimize;

A line with SCAN means a full table read; SEARCH ... USING INDEX is what you want. Run PRAGMA optimize occasionally, for example when the app closes a long-lived connection.

  • database is locked: missing busy timeout, or a long transaction holds the write lock; keep write transactions short.
  • attempt to write a readonly database: the directory or file belongs to another user.
  • WAL file keeps growing: a reader never finishes, so checkpoints cannot complete; close idle connections or run PRAGMA wal_checkpoint(TRUNCATE);.
  • disk I/O error: the disk is full; check with df -h.

Plans that fit this guide

Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.

All prices
PlanFits becauseSizeMonthlyOrder from
A1-1small apps with a SQLite file1 vCPU, 1 GB RAM, 25 GB NVMe$3.60/mo$43.20 for 12 months
A2-2busier sites with more cache in RAM2 vCPU, 2 GB RAM, 60 GB NVMe$10.80/mo$64.80 for 6 months

Questions about SQLite on a server

How big can a SQLite database get?

The format allows files far larger than any VPS disk. In practice the limit is your disk size and backup time, and databases of many gigabytes work fine.

Can several processes use the same SQLite file?

Yes, on the same machine. Many readers and one writer at a time work well in WAL mode; other writers wait for the busy timeout.

Is SQLite safe for a production website?

Yes for single-server sites with moderate write traffic, provided you use WAL mode, a busy timeout and tested backups.

How do I export a SQLite database to SQL text?

Run sqlite3 app.db .dump > app.sql. The file recreates the schema and data and is easy to diff or import elsewhere.

Does SQLite need a firewall rule?

No. It has no network listener; only processes on the server that can read the file can use it.