Skip to content

Database growth

Symptom. Database storage keeps climbing, a storage alert fires, or backups take longer and longer. Most growth is expected and bounded by retention; this runbook finds the part that is not.

Size per table, with partitions added up under their parent:

SELECT coalesce(parent.relname, c.relname) AS table_name,
pg_size_pretty(sum(pg_total_relation_size(c.oid))) AS total,
count(*) AS parts
FROM pg_class c
LEFT JOIN pg_inherits i ON i.inhrelid = c.oid
LEFT JOIN pg_class parent ON parent.oid = i.inhparent
WHERE c.relkind = 'r' AND c.relnamespace = 'public'::regnamespace
GROUP BY 1
ORDER BY sum(pg_total_relation_size(c.oid)) DESC
LIMIT 20;

Run it again a day later and compare. Then follow the table that grows.

2. Events and dispatch jobs: old partitions not dropped

Section titled “2. Events and dispatch jobs: old partitions not dropped”

msg_events, msg_events_read, msg_dispatch_jobs, msg_dispatch_jobs_read, msg_dispatch_job_attempts and the scheduled-job history are partitioned by month and should never hold more than the retention plus a month (90 days plus one month, 30 days plus one month for scheduled jobs, by default).

SELECT parent.relname, min(c.relname), max(c.relname), count(*)
FROM pg_inherits i JOIN pg_class c ON c.oid = i.inhrelid
JOIN pg_class parent ON parent.oid = i.inhparent
WHERE parent.relname LIKE 'msg_%'
GROUP BY parent.relname;

If the oldest partition is older than it should be, the partition manager is not running:

  • No process runs the stream processor (FC_STREAM_PROCESSOR_ENABLED=true), or FC_STREAM_PARTITION_MANAGER_ENABLED=false was set.
  • With standby, no replica leads the stream election (see leader failover).
  • Its passes fail: look for partition manager pass failed or drop failed in the stream processor’s log. A drop waits for a lock on the partition; long-running queries against old months (reports, exports) can block it.

It runs when the stream processor starts (if that process leads, or runs without standby) and then every FC_STREAM_PARTITION_TICK_HOURS (24) on the leader. There is no manual trigger; dropping an old partition by hand (DROP TABLE msg_events_2026_01, for example) is safe once its month is past the retention.

If the partitions are within retention but simply large, the volume is real. Options:

  • Shorten the retention with FC_STREAM_PARTITION_RETENTION_DAYS. The next pass drops the older months, whatever their jobs’ status, so resolve failed jobs you still care about first, and keep FC_DISPATCH_JOB_MAX_WINDOW_DAYS at or below it.
  • Look at payload and response sizes. Each matching subscription stores its own copy of the event payload in its dispatch job, and each attempt stores up to 64 KiB of the consumer’s response. Consumers that answer with large bodies, or events with large payloads fanned out to many subscriptions, multiply storage.
Table family Kept If it grows past that
Ingestion metrics, failures, test requests, traces, job keys (ing_*) 30 days, 1 day, 7 days, 7 days The hourly sweep deletes at most FC_INGESTION_RETENTION_MAX_CHUNKS (500) × 10,000 rows per table per run, about 1,400 records a second of steady traffic. Raise it for a larger fleet
Function trace records (fng_trace_log) FC_FUNCTIONS_TRACE_RETENTION_DAYS (30) A sweep deletes up to FC_FUNCTIONS_TRACE_PRUNE_MAX_ROWS (5,000,000) per run, every FC_FUNCTIONS_TRACE_PRUNE_INTERVAL_MINUTES (60). Check that trace windows are not left on “until switched off” for busy functions
Auth state (including expired email PINs, trusted devices and reset tokens, and reset-approval requests 90 days after they end), rate-limit counters, field-worker sign-ins, dispatch-job idempotency keys Minutes to 90 days These sweeps run on every process with the platform API. If they grow, check that such a process is running and look for purge failed warnings

aud_logs is never pruned by the platform: every administrative change and every audit entry an application writes stays. Decide on a retention period with whoever owns compliance, export what you must keep, then delete in batches, oldest first, at a quiet time:

SET lock_timeout = '5s';
-- repeat until it deletes nothing
DELETE FROM aud_logs
WHERE id IN (SELECT id FROM aud_logs
WHERE performed_at < now() - interval '2 years'
ORDER BY performed_at
LIMIT 5000);

The performed_at index makes each batch cheap. Pause between batches on a busy database, and let autovacuum catch up before reclaiming space.

  • queue_messages (the Postgres broker) holds dispatch pointers until the router acknowledges them. A large, growing table means the router is not consuming: see stuck dispatch jobs. Malformed messages are moved to queue_messages_failed, which nothing empties; inspect and delete them.
  • outbox_messages (when the platform’s outbox processor relays it) loses rows as they are sent. Rows that stay are refused or held: see requeue and redrive.

Growth can be dead space or write-ahead log rather than data.

  • Dead tuples. Dispatch-job status changes and the Postgres broker’s queue churn rows constantly. Check pg_stat_user_tables (n_dead_tup, last_autovacuum) for those tables; if autovacuum falls behind, make it more aggressive for them rather than running VACUUM FULL, which locks the table. Dropping partitions leaves no bloat; deleting rows does.
  • WAL. An inactive replication slot (a replica or a change-data-capture tool that went away) keeps every WAL segment since it stopped. Check pg_replication_slots for slots that are not active, and drop the ones nobody uses.