Operations¶
Running burrowDB day to day: health, scaling, backups, upgrades, schema changes, outages and metrics.
Health endpoints¶
Every process answers these on its HTTP port (8090 by default):
| Path | Answers |
|---|---|
/livez |
200 while the process runs: {"status":"ok","role":"api"} |
/readyz |
200 when the replica should get traffic, 503 with a reason otherwise: draining, database unavailable, cannot read migrations, or pending migrations: ... |
/api/health |
PocketBase's health check |
/metrics |
Prometheus text format (see Metrics) |
A worker (BURROW_ROLE=worker) answers only these four paths and returns 404 for everything else.
Scaling¶
API replicas are stateless; add as many as PostgreSQL and pgbouncer can take.
burrow up local --replicas 4 # Compose
burrow up k8s --kube-context CTX --values v.yaml --replicas 4 # Helm: api.replicas
On Kubernetes, api.autoscaling.enabled turns on a HorizontalPodAutoscaler.
Workers run the cron jobs. One is enough. More than one is safe: each cron tick runs on exactly one
process in the cluster, through a lease row in _burrowCronLeases. With three workers we saw each
per-minute job run exactly once per minute.
Connections. Every replica opens a pool to pgbouncer plus one direct connection for LISTEN. Keep
pgbouncer replicas x max_db_connections + replicas + headroom under PostgreSQL's max_connections.
Files must be on S3-compatible storage when there is more than one API replica. Otherwise an upload
lands on one replica's disk and the others cannot serve it. burrow doctor checks this.
Backups and restore¶
Backups use the PocketBase Backups API, so the dashboard, burrow backup and scheduled backups all work.
A backup zip holds:
burrow_backup.json: format, database names and creation time.data.pgdumpandauxiliary.pgdump:pg_dump --format=customof the data and logs databases.storage/: uploaded files, only when files are on local disk (not S3).
pg_dump streams into the zip; nothing is staged on the replica's disk. Only one backup or restore runs
in the cluster at a time (a PostgreSQL advisory lock).
burrow backup create before-upgrade.zip
burrow backup list
burrow backup download before-upgrade.zip -O before-upgrade.zip
Scheduled backups: BURROW_BACKUPS_CRON (Compose and Helm default 0 3 * * *) and
BURROW_BACKUPS_MAX_KEEP (Helm default 7). Set BURROW_BACKUPS_S3_BUCKET to keep them on S3; the Helm
chart does this for you. With more than one replica, keep backups on S3 so any replica can restore them.
Restore:
The restore loads each dump into a new database, then swaps it in: the live database stops taking
connections, its sessions end, it is renamed to <name>_pre_restore_<time>, and the restored database
takes its name. Every replica reconnects by name and reloads its caches.
The previous database is kept so you can inspect or recover it. Nothing prunes these copies: list them
with SELECT datname FROM pg_database WHERE datname LIKE '%\_pre\_restore\_%' and drop old ones yourself
(DROP DATABASE ...), or set BURROW_RESTORE_DROP_PREVIOUS=true to drop each one automatically. If the
final rename fails, the original database is renamed back and the install stays on its old data; if even
that fails, both copies are kept (<name>_pre_restore_<time> and <name>_restoring_<id>) for a manual fix.
Restore needs the database user to be allowed to create databases. Backup and restore were tested on every replica of a local stack.
Backup and console security¶
- Run burrowDB as a role that is not a PostgreSQL superuser. Give it
CREATEDB(for restores and the first start) and ownership of its two databases, nothing more. The superuser SQL console and a restore run statements as that role: a restore replays the SQL in the uploaded archive (pg_restoreruns with--no-owner --no-privileges --exit-on-error, which drops ownership and grants but not the statements themselves), so with a superuser role a crafted backup or a console user could read server files or run programs on the database host. pg_dumpandpg_restoreget the password throughPGPASSWORD, not on their command line. Backup zips on local disk are created owner-only (0600) and temporary restore directories 0700; a backup holds every password hash and the settings, so keep the backups bucket private too.- The SQL console (dashboard and
POST /api/sql, superusers only) runs every statement in a transaction: reads in aREAD ONLYone, everything withSET LOCAL statement_timeout(BURROW_SQL_CONSOLE_TIMEOUT, default30s, at most3m), so no setting stays on a pooled connection. It refusesCOPY,DO,LOAD,ALTER SYSTEM, creating extensions, languages or functions, role and database management,GRANT/REVOKE, session-levelSET/RESET, and the functions that read server files or open other connections (pg_read_file,pg_ls_dir,lo_import,dblink,query_to_xmland similar). This list is defence in depth; the role above is the boundary. BURROW_SQL_CONSOLE=readonlylimits the console to reads;BURROW_SQL_CONSOLE=offturns it off.
Upgrades¶
On Kubernetes, burrow up k8s (or helm upgrade) rolls the API pods one at a time
(maxUnavailable: 0, maxSurge: 1). Every new pod runs burrow migrate in an init container first.
The migrate step takes a PostgreSQL advisory lock, so only one pod applies migrations; the others wait
(up to 10 minutes) and find nothing left to do.
During a rolling update old and new replicas run side by side. Keep migrations additive within a release: add columns and collections, do not drop or rename what the old version still reads. Remove old fields in a later release.
On Compose, burrow up local runs the migrate service before api and worker start.
Before an upgrade, take a backup.
Schema changes and pgbouncer¶
pgbouncer runs in transaction mode, and burrowDB caches prepared statement descriptions per connection. After a schema change, some cached descriptions may be stale. burrowDB handles this in two ways:
- A query that fails because a cached description is stale is retried once, outside transactions.
- When
burrow migrateapplied new migrations, it sendsRECONNECTto each pgbouncer listed inBURROW_PGBOUNCER_ADMIN_URLS, so their server connections are replaced. The Compose stack and the Helm chart set this for you.
Changes made in the dashboard are broadcast to every replica, which reload their collections and reset idle database connections.
Graceful shutdown and draining¶
On SIGTERM a replica reports /readyz as draining (503), then the HTTP server waits up to
BURROW_SHUTDOWN_TIMEOUT for in-flight requests and realtime streams. The default is PocketBase's
1 second. Behind rolling updates, raise it (for example 25s) and keep it below the pod's termination
grace period. On Kubernetes, set it with extraEnv.
You can also take a replica out of rotation without stopping it: create the drain file
(BURROW_DRAIN_FILE, default /tmp/burrow-drain) and /readyz returns 503 until you remove it.
The Helm chart's preStop hook sleeps api.preStopSleepSeconds (10) so the Service stops sending
traffic before SIGTERM arrives.
Measured on the local stack under steady load: killing an API replica, 2,419 of 2,419 requests answered 200; a graceful stop, 2,175 of 2,175. On kind, a rolling restart of the API and pgbouncer, 27,221 of 27,221.
Database outages¶
When PostgreSQL or pgbouncer is unreachable, burrowDB answers 503 instead of 500, so clients and load
balancers can retry. Record list and view reads retry for up to BURROW_READ_RETRY_BUDGET (3 s) before
giving up. /readyz reports database unavailable.
Measured on the local stack under steady load: a pgbouncer restart, 3,649 of 3,649 requests answered 200; a PostgreSQL restart, 4,001 of 4,001.
A write that fails with 503 may still have committed before the connection dropped. Retry reads and idempotent requests freely; before re-sending a create, check whether it landed (for example by a client-chosen record id, which makes the retry safe).
Realtime across replicas¶
Each replica LISTENs on PostgreSQL for the events other replicas send it. NOTIFY is not queued for a
connection that is not listening, so events sent while a replica's LISTEN connection is down are lost.
When the connection comes back, the replica closes its local realtime (SSE) connections; the SDKs reconnect
and should refetch, as they do after any reconnect. Delivery is therefore at most once per connection:
treat realtime as a signal to refresh, not as a log of every change.
LISTEN and the backup lock need a session on the database itself. Set BURROW_POSTGRES_DIRECT_URL
whenever BURROW_POSTGRES_URL points at pgbouncer in transaction mode; a replica logs a warning at start
when the realtime bridge is on and no direct URL is set. A replica running role all with files on local
disk also warns when it finds other replicas on the same database.
Metrics¶
GET /metrics on every process, on the main HTTP port:
| Metric | What |
|---|---|
burrow_info{role,version} |
Always 1 |
burrow_ready |
1 when /readyz would answer 200 |
burrow_cron_ticks_total{outcome="ran\|skipped\|error"} |
Cron ticks this process ran, skipped (another process held the lease) or failed |
burrow_realtime_clients |
Realtime (SSE) clients connected to this replica |
burrow_db_connections{state="open\|in_use\|idle"} |
The replica's database pool |
burrow_db_wait_total, burrow_db_wait_seconds_total |
Waits for a free pool connection |
/metrics has no authentication. Do not expose it to the internet; keep it on the internal network or
block the path at your ingress. The Helm chart adds a headless <release>-metrics Service for scraping.
Logs¶
Request and app logs go to the logs database (burrow_aux), as in PocketBase.
Old logs are removed by the built-in __pbLogsCleanup__ job every 6 hours, following the log retention
in the settings.