Self-hostingConfiguration

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

SQLitePostgreSQL
Image taglatest, vX.Y.Zpostgres, vX.Y.Z-postgres
SetupNone: data stored in a Docker volumeExternal PostgreSQL service required
Best forPersonal use, low traffic, quick setupProduction, teams, high volume
ConcurrencySingle writerFully concurrent
Backupsqlite3 .backup, or the whole /data volumepg_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:latest
Shell

DATABASE_URL defaults to sqlite:///data/rustrak.db. Mount a volume at /data to 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:
YAML

DATABASE_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.db
Shell

Always 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"'
Shell

Use sqlite3 .backup rather than cp. 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;"
Shell

If 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;"
Shell

Check 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:postgres
Shell

Docker 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:
YAML

The /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=require
Shell

Connection pool tuning

DATABASE_MAX_CONNECTIONS=10   # Default
DATABASE_MIN_CONNECTIONS=1    # Default

# High traffic
DATABASE_MAX_CONNECTIONS=25
DATABASE_MIN_CONNECTIONS=5
Shell

Reclaiming 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; spans locked 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 429 with Retry-After: 10 and X-Sentry-Rate-Limits naming only their categories (transaction;span while spans is rewritten, transaction for transactions, log_item for logs). 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 logs
Shell

Without --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.sql
Shell

Image tags reference

TagBackendArch
latestSQLiteamd64, arm64
vX.Y.ZSQLiteamd64, arm64
postgresPostgreSQLamd64, arm64
vX.Y.Z-postgresPostgreSQLamd64, arm64
nextSQLite, latest pre-releaseamd64, arm64
next-postgresPostgreSQL, latest pre-releaseamd64, arm64

Migrations

Migrations run automatically on startup. Both backends have their own migration set:

apps/server/migrations/
├── postgres/   # PostgreSQL migrations
└── sqlite/     # SQLite migrations

If you see a migration error, ensure your DATABASE_URL scheme (sqlite:// or postgres://) matches the image tag you are using.

Esc

Type to search guides, configuration and the API.