Configuration
All configuration is supplied through environment variables prefixed with
QUERYINSIGHTS_. Only one is strictly required; everything else has a sensible
default or unlocks an optional capability.
Never hard-code secrets. Provide API keys and database passwords through a secret manager or your platform's environment configuration — not in source control or shell history.
Core
| Variable | Required | Default | Description |
|---|---|---|---|
QUERYINSIGHTS_DB_URL | Yes | — | Connection string for the QueryInsights metastore (PostgreSQL). |
QUERYINSIGHTS_LISTEN_ADDRESS | No | 0.0.0.0:2427 | Address the webhook service listens on. |
QUERYINSIGHTS_ENGINE_ADDRESS | No | localhost:50051 | Engine gRPC address used by the poller, webhook, and dashboard. |
QUERYINSIGHTS_DASHBOARD_ADDRESS | No | :3001 | Address the dashboard API listens on. |
LLM
| Variable | Required | Default | Description |
|---|---|---|---|
QUERYINSIGHTS_OPENAI_API_KEY | No | — | Enables OpenAI recommendations. |
QUERYINSIGHTS_ANTHROPIC_API_KEY | No | — | Enables Anthropic (Claude) recommendations. |
QUERYINSIGHTS_LLM_MODEL | No | gpt-4o-mini | Chat model for recommendations. Also selects the provider (see below). |
QUERYINSIGHTS_LLM_BASE_URL | No | — | Custom base URL for the LLM client — point it at a gateway such as LiteLLM or Portkey. |
How the provider is chosen
The engine picks a backend from the model name:
- Model name contains
claudeandQUERYINSIGHTS_ANTHROPIC_API_KEYis set → Anthropic. - Model name contains
claudebut onlyQUERYINSIGHTS_OPENAI_API_KEYis set → OpenAI-compatible client (use this when a gateway fronts Claude behind an OpenAI-compatible API, e.g. a model name likevertex/claude-opus-4). - Otherwise → OpenAI.
If no matching API key is configured, the engine starts without recommendation features; ingestion and the dashboard still work.
Metadata sources
| Variable | Required | Default | Description |
|---|---|---|---|
QUERYINSIGHTS_TRINO_URL | No | — | Trino coordinator URL, used to fetch table DDL for Trino recommendations. |
QUERYINSIGHTS_COCKROACH_INSTANCES | No | — | JSON array of CockroachDB instances to poll and read schema from. |
QUERYINSIGHTS_POSTGRES_INSTANCES | No | — | JSON array of PostgreSQL instances to poll and read schema from. |
Recommendation tuning
| Variable | Required | Default | Description |
|---|---|---|---|
QUERYINSIGHTS_REC_MAX_ATTEMPTS | No | 3 | Failed per-query recommendation attempts before a pattern is permanently skipped. |
QUERYINSIGHTS_DDL_MAX_FAILURES | No | 3 | Consecutive SHOW CREATE TABLE failures for a table before schema fetching is abandoned. |
QUERYINSIGHTS_STATS_CACHE_TTL_SECS | No | 1800 | How long rendered table-statistics blocks are cached before re-fetching. |
QUERYINSIGHTS_WORKLOAD_INTERVAL_MIN | No | 10080 | Minutes between periodic workload-insight runs. Set to 0 to disable the ticker. |
QUERYINSIGHTS_WORKLOAD_TOP_TABLES | No | 10 | Number of hottest tables included in each workload profile. |
QUERYINSIGHTS_WORKLOAD_TOP_QUERIES_PER_TABLE | No | 5 | Top normalized patterns per table included in the workload prompt. |
Describing database instances
Both QUERYINSIGHTS_COCKROACH_INSTANCES and QUERYINSIGHTS_POSTGRES_INSTANCES
take a JSON array of objects with the same shape:
[
{
"name": "production",
"dsn": "postgres://queryinsights:REPLACE_WITH_PASSWORD@db.internal:5432/appdb?sslmode=require",
"sampling_rate": 0.5,
"poll_interval_seconds": 10
}
]
| Field | Type | Description |
|---|---|---|
name | string | A label for the instance; shown in the dashboard and stored with every captured query. |
dsn | string | Connection string. The user in this DSN needs both statement-stats access and schema-read access. |
sampling_rate | number | Fraction of captured queries to keep, 0.0–1.0 (1.0 = keep everything). Values outside this range fall back to 1.0. |
poll_interval_seconds | number | How often to poll the statistics table. Defaults to 10 when unset or non-positive. |
You can configure multiple instances, and both engines at once — the poller starts one goroutine per instance.
The same DSN user is used by the poller (to read statistics) and by the engine (to read table DDL). Follow the least-privilege setup in Onboarding PostgreSQL and Onboarding CockroachDB to create that user safely.
Example
export QUERYINSIGHTS_DB_URL="postgres://queryinsights:REPLACE_WITH_PASSWORD@localhost:5432/metastore?sslmode=disable"
export QUERYINSIGHTS_LLM_MODEL="gpt-4o-mini"
export QUERYINSIGHTS_OPENAI_API_KEY="REPLACE_WITH_OPENAI_API_KEY"
export QUERYINSIGHTS_POSTGRES_INSTANCES='[
{"name":"prod","dsn":"postgres://queryinsights:REPLACE_WITH_PASSWORD@db.internal:5432/appdb?sslmode=require","sampling_rate":1.0,"poll_interval_seconds":10}
]'
Keep the real values in a secret store and inject them at runtime.