Database Backends
Run Rustrak on SQLite or PostgreSQL. Compare the two Docker images, when to pick each, and how to configure the database connection.
Rustrak supports two database backends compiled as separate Docker images. Both images include the dashboard; they differ only in where data is stored.
Comparison
| SQLite | PostgreSQL | |
|---|---|---|
| Image tag | latest, vX.Y.Z | postgres, vX.Y.Z-postgres |
| Setup | None: data stored in a Docker volume | External PostgreSQL service required |
| Best for | Personal use, low traffic, quick setup | Production, teams, high volume |
| Concurrency | Single writer | Fully concurrent |
| Backup | sqlite3 .backup, or the whole /data volume | pg_dump |
SQLite (default)
The latest image uses SQLite. No external service needed.
Docker run
docker run -d \
--name rustrak \
-p 8080:8080 \
-v rustrak_data:/data \
-e SESSION_SECRET_KEY=$(openssl rand -hex 32) \
-e CREATE_SUPERUSER=admin@example.com:changeme123 \
rustrak/rustrak-server:latestShell
DATABASE_URLdefaults tosqlite:///data/rustrak.db. Mount a volume at/datato persist data.
Docker Compose
services:
server:
image: rustrak/rustrak-server:latest
ports:
- "8080:8080"
volumes:
- rustrak_data:/data
environment:
# DATABASE_URL defaults to sqlite:///data/rustrak.db, no need to set it
- SESSION_SECRET_KEY=${SESSION_SECRET_KEY:?generate one with openssl rand -hex 32}
- CREATE_SUPERUSER=${CREATE_SUPERUSER}
restart: unless-stopped
volumes:
rustrak_data:YAMLDATABASE_URL format
# Named Docker volume (recommended)
DATABASE_URL=sqlite:///data/rustrak.db
# Absolute path on host (bind mount)
DATABASE_URL=sqlite:///var/lib/rustrak/rustrak.dbShellAlways use a Docker volume or bind mount. If you use a path inside the container without a mount, data will be lost when the container is removed.
Backup
# Use SQLite's online backup API (safe while server is running)
docker run --rm \
-v rustrak_data:/data \
-v $(pwd)/backups:/backups \
alpine sh -c 'apk add -q sqlite && sqlite3 /data/rustrak.db ".backup /backups/rustrak-$(date +%Y%m%d).db"'ShellUse
sqlite3 .backuprather thancp. A plain file copy while the server is running may capture an inconsistent state if a write is in progress.
Durability
Rustrak opens SQLite in WAL mode with synchronous=NORMAL, the pairing SQLite
recommends for this journal mode. Commits are atomic and survive a crash of the
Rustrak process itself. What they do not survive is an operating-system crash or
a power loss: the last few seconds of committed events can be rolled back,
because the write-ahead log is not flushed to disk on every commit.
That trade is deliberate. It removes one disk flush per commit from the digest path, and for a stream of error events losing the newest few is a far smaller cost than making every write wait on the disk.
If your deployment cannot accept it, use PostgreSQL.
Reclaiming disk space
Deleting data, by retention or a cleanup, frees pages inside
the database file. Rustrak creates SQLite databases with
auto_vacuum = INCREMENTAL, and after each cleanup it hands the freed pages
back to the filesystem a few megabytes at a time, so the file shrinks.
A database created by an earlier version has SQLite’s default,
auto_vacuum = NONE. Its freed pages are reused for new data, so with retention
on the file stops growing, but it never shrinks. Rustrak says so in its log at
startup, and Settings → Storage shows how much space is held and a
Compact database button that converts it once.
This only concerns databases from earlier versions. A database created by the current version never shows the warning or the button, and one compacted once stops showing them for good.
Compacting runs VACUUM, which rewrites only the data still in the file:
- It needs free disk about twice the data (one copy in SQLite’s temporary file, one in the write-ahead log). The button refuses when the disk next to the database is short of that.
- It takes a few seconds per GB of data, and no writes land while it runs. Error events are kept on disk and processed afterwards; logs, traces and sessions that arrive meanwhile are lost. Run it at a quiet time.
To do it by hand instead, stop Rustrak and run:
sqlite3 /path/to/rustrak.db "PRAGMA auto_vacuum = INCREMENTAL; VACUUM;"ShellIf the disk is short of room, make the copy with SQLite’s own backup, which
also takes what is still in the write-ahead log (copying rustrak.db alone can
miss it after a crash), compact the copy there and move it back in place of the
original and its -wal and -shm files:
sqlite3 /path/to/rustrak.db ".backup /mnt/roomy/rustrak.db"
sqlite3 /mnt/roomy/rustrak.db "PRAGMA auto_vacuum = INCREMENTAL; VACUUM;"ShellCheck the result with
sqlite3 /path/to/rustrak.db "PRAGMA auto_vacuum;", which answers 2.
Limitations
SQLite has one writer at a time. It suits up to about 1,000 events an hour reliably; above that, use PostgreSQL.
Whichever backend you choose, run one Rustrak process per database.
PostgreSQL
Use the :postgres image tag when you need PostgreSQL.
Docker run
docker run -d \
--name rustrak \
-p 8080:8080 \
-v rustrak_data:/data \
-e DATABASE_URL=postgres://user:password@db-host:5432/rustrak \
-e SESSION_SECRET_KEY=$(openssl rand -hex 32) \
-e CREATE_SUPERUSER=admin@example.com:changeme123 \
rustrak/rustrak-server:postgresShellDocker Compose
services:
postgres:
image: postgres:16-alpine
environment:
POSTGRES_USER: rustrak
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?generate one with openssl rand -hex 16}
POSTGRES_DB: rustrak
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U rustrak -d rustrak"]
interval: 5s
timeout: 5s
retries: 5
restart: unless-stopped
server:
image: rustrak/rustrak-server:postgres
ports:
- "8080:8080"
environment:
- DATABASE_URL=postgres://rustrak:${POSTGRES_PASSWORD}@postgres:5432/rustrak
- SESSION_SECRET_KEY=${SESSION_SECRET_KEY:?generate one with openssl rand -hex 32}
- CREATE_SUPERUSER=${CREATE_SUPERUSER}
volumes:
# Uploaded source maps. The database lives in PostgreSQL.
- rustrak_data:/data
depends_on:
postgres:
condition: service_healthy
restart: unless-stopped
volumes:
postgres_data:
rustrak_data:YAMLThe /data volume holds uploaded source maps, which stay on disk rather than
in the database.
DATABASE_URL format
# Basic
DATABASE_URL=postgres://username:password@host:5432/database
# With SSL (recommended for production)
DATABASE_URL=postgres://username:password@host:5432/database?sslmode=requireShellConnection pool tuning
DATABASE_MAX_CONNECTIONS=10 # Default
DATABASE_MIN_CONNECTIONS=1 # Default
# High traffic
DATABASE_MAX_CONNECTIONS=25
DATABASE_MIN_CONNECTIONS=5ShellReclaiming disk space on PostgreSQL
PostgreSQL never hands the space of deleted rows back to the operating system
by itself. Autovacuum marks it free and new rows reuse it, so with
retention on, the tables stop growing; but a 100 GB database
stays 100 GB on disk after a cleanup, mostly free space inside. Plain VACUUM
only cuts empty pages off the end of a table, and retention empties its
oldest pages, at the start
(VACUUM).
Getting that space back means rewriting the tables. Settings → Storage →
Compact tables does it with VACUUM FULL, one table at a time, for the four
tables retention deletes from (events, transactions, spans, logs),
smallest first, so the space each one gives back is there for the next. The
dialog lists each table’s size; afterwards the job reports each table’s size
before and after and how long it took (compacted in
GET /api/storage/cleanup/status).
When. After a cleanup has deleted a large share of the data and you need the disk back: typically once, after upgrading to a version that stores payloads compressed, when your retention period has passed and the old, larger rows are gone. With retention on, the tables then stay at their size by reuse alone; compacting again only helps after you shorten retention or delete a lot by hand. Rustrak never compacts on a schedule.
What it costs.
- Each table is locked for its whole rewrite (
ACCESS EXCLUSIVE), which takes a few seconds per GB the table keeps (measured: 1.1 GB of tables, 80% deleted, compacted to 0.2 GB in 1.3 s;spanslocked for 0.9 s). Meanwhile:- Error events keep being accepted. They are written to disk first and stored once their table is done, so none is lost.
- Transactions, spans and logs sent while their table is rewritten are
turned away and lost. They are written while the SDK’s request is open,
so instead of waiting on the lock (and taking every database connection
with them), they get
429withRetry-After: 10andX-Sentry-Rate-Limitsnaming only their categories (transaction;spanwhilespansis rewritten,transactionfortransactions,log_itemforlogs). SDKs pause those categories for 10 s and keep sending errors; an envelope that also carries an error still has its error stored. - Dashboard pages showing the table being rewritten fail with a temporary error until it is done; the rest of the dashboard works.
- Free disk on the database server of about the largest table’s size: the new copy is written before the old one is removed. The rewrite is written to the WAL too, so allow about as much again if the WAL is on the same disk, and more if replication or archiving is holding WAL back. Rustrak cannot see the database server’s disk, so check it first. If the disk fills, the rewrite fails and the table is left exactly as it was.
- A table some other query is using gets 5 seconds to be released; past that, the compaction stops, says which table, and leaves it as it was. Tables already compacted stay compacted; run it again at a quieter time.
Run it at a quiet time. To compact while the tables stay in use, use pg_repack, an extension installed on the database server and run as a superuser (Rustrak’s tables all have the primary key it needs). It locks each table only briefly, at the start and at the end. It needs about twice the size of the tables and their indexes free while it works, and the extension created in Rustrak’s database first:
psql -h db-host -U postgres -d rustrak -c 'CREATE EXTENSION pg_repack'
pg_repack -h db-host -U postgres -d rustrak --no-kill-backend \
-t spans -t transactions -t events -t logsShellWithout --no-kill-backend, pg_repack cancels the queries still holding a
table after its 60-second wait for the lock. With it, that table is skipped
instead: run the command again for it later.
PostgreSQL 19 adds REPACK (CONCURRENTLY), which does the same without an
extension.
Backup
# Dump
pg_dump -h localhost -U rustrak rustrak > backup_$(date +%Y%m%d).sql
# Restore
psql -h localhost -U rustrak rustrak < backup.sqlShellImage tags reference
| Tag | Backend | Arch |
|---|---|---|
latest | SQLite | amd64, arm64 |
vX.Y.Z | SQLite | amd64, arm64 |
postgres | PostgreSQL | amd64, arm64 |
vX.Y.Z-postgres | PostgreSQL | amd64, arm64 |
next | SQLite, latest pre-release | amd64, arm64 |
next-postgres | PostgreSQL, latest pre-release | amd64, arm64 |
Migrations
Migrations run automatically on startup. Both backends have their own migration set:
apps/server/migrations/
├── postgres/ # PostgreSQL migrations
└── sqlite/ # SQLite migrationsIf you see a migration error, ensure your DATABASE_URL scheme (sqlite:// or postgres://) matches the image tag you are using.