// PART 05
Database
PostgreSQL is the system of record: every business table, every session, every metric counter. The installer component is tables, pinned in botserver/3rdparty.toml at PostgreSQL 18.6.1 (x86_64 and arm64 tarballs, checksums enforced).
Install, start, verify
./botserver install tables # local mode (host process)
./botserver install tables --container --tenant mycompany # Incus instance mycompany-tables
./botserver status tables
sudo incus exec mycompany-tables -- pg_isready -U postgres # container mode
Credentials and endpoint live in Vault at secret/gbo/tables (host, port,
database, username, password, url); DATABASE_URL is the environment
fallback. The schema is owned by Diesel migrations (see Migrations) — 211
migration directories under botserver/migrations/ at the time of writing,
tracked in __diesel_schema_migrations.
Health and size checks
# Size by table — the fastest way to spot growth
psql -h localhost -U postgres -d botserver -c "SELECT relname, pg_size_pretty(pg_total_relation_size(relid)) AS size
FROM pg_catalog.pg_statio_user_tables
ORDER BY pg_total_relation_size(relid) DESC LIMIT 10;"
# Operational counters are prunable, product data is not
psql -h localhost -U postgres -d botserver -c "DELETE FROM ops_request_metrics WHERE bucket < NOW() - INTERVAL '7 days';"
psql -h localhost -U postgres -d botserver -c "VACUUM (ANALYZE) message_history;"
Schema design conventions
The shipped schema is written for large tenants. Domain values are SMALLINT
enums (2 bytes) rather than VARCHAR status strings; the generated schema
reference documents every table and column (python3 scripts/gen_schema_reference.py). Representative families:
| Enum | Values |
|---|---|
| Channel | 0 web · 1 whatsapp · 2 telegram · 3 msteams · 4 slack · 5 email · 6 sms · 7 voice · 8 instagram · 9 api |
| Message role | 1 user · 2 assistant · 3 system · 4 tool · 9 episodic · 10 compact |
Operational guidance that follows from the design: keep tenant data on
branch_id-scoped indexes, use EXPLAIN (ANALYZE, BUFFERS) before adding an
index, prefer partial indexes for active rows, and set aggressive autovacuum
on high-churn tables (message_history, user_sessions). Every Vibe project
kind additionally owns a dedicated database (bot_{branch}_{bot}, with a
_dev twin) — those are created and dropped by the platform, never by hand.
What the database must never be asked to do
- It is not a queue for humans:
agent_runs,handoff_queueandemail_offline_queueare drained by the server; reap stuckrunningrows with the runbook, do not delete product rows. - It is not encrypted at rest by the platform: no TDE, no LUKS mapping in the shipped image — provide disk-level encryption at the storage layer if your compliance posture requires it.
- Restores always go to a scratch database first (see Backup and restore).