Skip to content

Installing PocketBase as a Go backend on Ubuntu

Run PocketBase — single binary, embedded SQLite, realtime — as a systemd service on Ubuntu with Nginx in front, backups, and the operational gotchas the README skips.

PocketBase is a single Go binary that ships an embedded SQLite database, a REST + realtime API, an admin UI, and file storage — everything a small backend needs in 30 MB of executable. The install is “download the binary and run it”; the operational part — systemd unit, Nginx in front, backups that work for SQLite under load, log retention — is what this article covers. Aimed at operators running PocketBase for production frontends (Svelte, Vue, React, Flutter) on a single VM.

How to verify

A correctly running PocketBase deployment shows:

curl -sI https://api.example.org/api/health | head -1
# HTTP/2 200

systemctl status pocketbase
# Active: active (running) since ...

ss -lntp | grep ':8090'
# 127.0.0.1:8090   pocketbase

ls -la /var/lib/pocketbase/pb_data/
# -rw------- 1 pocketbase pocketbase  data.db
# -rw------- 1 pocketbase pocketbase  data.db-shm
# -rw------- 1 pocketbase pocketbase  data.db-wal
# drwx------ 2 pocketbase pocketbase  storage/

sqlite3 /var/lib/pocketbase/pb_data/data.db "PRAGMA journal_mode;"
# wal

If journal_mode is delete instead of wal, PocketBase has not finished starting or the data directory was bootstrapped externally — restart and recheck.

What’s happening

PocketBase is one Go binary that bundles four things: an HTTP server (uses net/http, no external web framework), an embedded SQLite database (via modernc.org’s sqlite driver, no CGO required), an admin SPA built into the binary’s assets, and a realtime subscription layer over Server-Sent Events. The data directory (default pb_data/) holds the SQLite file (data.db), the WAL files, an auxiliary.db for housekeeping, a storage/ tree for uploaded files, and a backups/ directory if you’ve used the built-in backup feature.

SQLite is the database, not a development convenience. WAL mode and synchronous=NORMAL are turned on by default — that gets you many-reader/single-writer concurrency, good throughput on a single instance, and a clear backup story (the .backup SQLite command + WAL checkpoint). PocketBase does not scale to multi-instance. If you need that, you’ve outgrown PocketBase.

Schema is managed through the admin UI or migration files in pb_migrations/. The Go API (pocketbase.app.Dao()) lets you embed custom routes and hooks for anything the admin can’t model. Realtime subscriptions are per-collection: clients open /api/realtime (SSE) and subscribe to a record by id or to ”*” for the whole collection.

The procedure

  1. Create a service user and directory.

    sudo useradd --system --home /var/lib/pocketbase --shell /usr/sbin/nologin pocketbase
    sudo mkdir -p /var/lib/pocketbase/pb_data /opt/pocketbase
    sudo chown -R pocketbase:pocketbase /var/lib/pocketbase
  2. Download the binary. Always pin a version and verify the checksum from the GitHub release.

    VERSION=0.22.21
    cd /tmp
    wget -q https://github.com/pocketbase/pocketbase/releases/download/v${VERSION}/pocketbase_${VERSION}_linux_amd64.zip
    wget -q https://github.com/pocketbase/pocketbase/releases/download/v${VERSION}/pocketbase_${VERSION}_checksums.txt
    sha256sum -c pocketbase_${VERSION}_checksums.txt --ignore-missing
    unzip -o pocketbase_${VERSION}_linux_amd64.zip pocketbase
    sudo mv pocketbase /opt/pocketbase/pocketbase
    sudo chown root:root /opt/pocketbase/pocketbase
    sudo chmod 755 /opt/pocketbase/pocketbase
  3. Write the systemd unit at /etc/systemd/system/pocketbase.service:

    [Unit]
    Description=PocketBase
    After=network.target
    
    [Service]
    Type=simple
    User=pocketbase
    Group=pocketbase
    WorkingDirectory=/var/lib/pocketbase
    ExecStart=/opt/pocketbase/pocketbase serve \
      --http=127.0.0.1:8090 --dir=/var/lib/pocketbase/pb_data
    Restart=always
    RestartSec=5
    ProtectSystem=strict
    ProtectHome=true
    PrivateTmp=true
    NoNewPrivileges=true
    ReadWritePaths=/var/lib/pocketbase
    LimitNOFILE=65536
    
    [Install]
    WantedBy=multi-user.target

    Then:

    sudo systemctl daemon-reload
    sudo systemctl enable --now pocketbase
  4. Bootstrap the admin. First-run shows the admin signup at /_/. On a fresh box, create the admin via the CLI so it doesn’t sit accessible:

    sudo -u pocketbase /opt/pocketbase/pocketbase --dir=/var/lib/pocketbase/pb_data \
      superuser upsert admin@example.org "$(openssl rand -hex 16 | tee /root/.pb-admin-pass)"
    sudo chmod 600 /root/.pb-admin-pass
  5. Reverse proxy with Nginx.

    server {
      listen 443 ssl http2;
      server_name api.example.org;
      ssl_certificate /etc/letsencrypt/live/api.example.org/fullchain.pem;
      ssl_certificate_key /etc/letsencrypt/live/api.example.org/privkey.pem;
      client_max_body_size 200m;
      location / {
        proxy_pass http://127.0.0.1:8090;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_buffering off;
        proxy_read_timeout 600s;
      }
    }

    proxy_buffering off and the long read timeout are required for the SSE realtime endpoint.

  6. Set up nightly backups. PocketBase has a built-in Settings > Backup schedule that drops a zip in pb_data/backups/. Mirror that off the host:

    echo '15 2 * * * pocketbase /usr/bin/rclone copy /var/lib/pocketbase/pb_data/backups remote:pocketbase-backups/' \
      | sudo tee /etc/cron.d/pocketbase-backup

    A SQLite-aware approach: drop the rclone job and instead do sqlite3 data.db ".backup /var/backups/pb-$(date +%F).db", which works while PocketBase is running because it uses the SQLite backup API.

  7. Pin S3 for uploaded files (optional). From the admin > Settings > Files, point storage at an S3-compatible bucket. PocketBase keeps the metadata in SQLite and pushes the blob to the bucket. Configure lifecycle on the bucket to keep storage costs bounded.

Common pitfalls

  • The default admin signup at /_/ is open until someone creates an admin — restrict access at the proxy if you don’t bootstrap the admin via CLI before going live.
  • SQLite WAL files (-wal, -shm) must be on the same filesystem as data.db — never split the data directory across volumes.
  • Realtime SSE breaks behind any proxy that buffers (Cloudflare’s default config, some CDN setups). Either disable buffering on that path or accept that realtime won’t work.
  • pb_data/storage/ grows with uploads; without S3, this is your disk consumption. Track it.
  • A sqlite3 data.db .backup while a long writer is running will block until the writer commits — schedule backups during quiet hours or instrument them with a timeout.

For products that lean on PocketBase as their backend, Stack Harbor operates the host — systemd unit hardened, SQLite backups verified by restore, S3 lifecycle on uploads, realtime endpoint instrumented end-to-end — so the product team only sees the admin and the API. That model lives under managed operations, and related single-binary patterns live in the knowledge base.