Skip to main content
Version: v5.6.1

opschain admin database analyze

Included from Basic tier

Runs statistics maintenance now — a POST to /api/admin/database/analyze. On PostgreSQL that is a per-table ANALYZE; on SQLite, PRAGMA optimize. By default the run covers the configured churn set (the same tables the scheduled lane maintains, from config.yaml's database.maintenance block); --table narrows it. The command prints the server's JSON response describing the run.

Statistics staleness shows up as bad query plans, not errors — run this when admin database status shows a hot table whose LAST ANALYZE is old or never, or after a bulk import the scheduled interval has not caught up with.

Flags​

FlagMeaning
--server <url>Server base URL (default: the active context / OPSCHAIN_SERVER).
--auth-token <token>Admin bearer token override (default: your opschain login session, then $OPSCHAIN_ADMIN_TOKEN, then the token stored by opschain admin login).
--table <name>Limit the run to this table (repeatable; default: the configured churn set).

Output is the response document itself — JSON, or YAML under -o yaml.

Exit codes​

CodeMeaning
0The run was accepted and reported.
1Request failed, non-2xx response, or the token was rejected.
2Usage error — no server or no credential resolvable.

Named errors​

  • a server is required — pass --server <url>, set OPSCHAIN_SERVER, or 'opschain context use <name>' — exit 2.
  • this command needs a login or an admin token — run 'opschain login', pass --auth-token, set OPSCHAIN_ADMIN_TOKEN, or store one with 'opschain admin login' — exit 2.
  • the server rejected the credential — run 'opschain login' again, or check the admin token — HTTP 401 (exit 1).

Examples​

opschain admin database analyze
opschain admin database analyze --table steps --table runs

See also​

  • opschain docs cli/admin-database-status — what needs analyzing, and the run record afterwards.
  • opschain docs cli/admin-database-vacuum — when dead tuples, not stale statistics, are the problem.