Setting up the AI Advisor
Updated
The AI Advisor sends a statement, its captured event details and its execution plan to a language model of your choice, and shows a diagnosis plus concrete recommendations. Nothing is sent until you ask, and only to the provider you configure.
1. Choose a provider
Open Tools ▸ AI Settings:
- Provider / model: Anthropic Claude, OpenAI, Google Gemini, DeepSeek, Kimi, Qwen, any OpenAI-compatible endpoint (LM Studio, vLLM, …), Ollama Cloud or a local Ollama.
- Enter your API key where the provider needs one. Keys are stored obfuscated in
ai.jsonin the app’s configuration folder (on Linux with file mode 0600, readable only by your user). - Refresh list fetches the provider’s live model list. Test connection sends a one-word prompt.
2. Database tools (MCP)
While it works, the model can inspect the live database through a PostgreSQL Model Context Protocol server, started for each question with the trace’s connection string:
- Postgres MCP Pro (default, run with
uvx): schemas and objects, EXPLAIN with hypothetical indexes whenhypopgis installed, index and workload analysis,pg_stat_statementsand health checks. - mcp-postgres-server (run with
npx). - A custom command.
The default access mode is read-only. Built-in read-only tools (schemas, tables, column statistics, indexes, settings, EXPLAIN and ad-hoc SELECT) are always available as well, so the advisor works even without uvx or npx.
3. Ask
Select a statement in a trace and open the Execution Plan tab, then click Ask AI Advisor (or Profiler ▸ Ask AI Advisor). While it runs, a “Working on it” bar shows the current step. If the model returns no answer, times out or the provider is overloaded, the run is restarted automatically, up to the Retries on transient failures setting.
4. Review and apply
The advisor returns a diagnosis and a table of recommendations: create, drop or alter an index, rewrite the query, update statistics, change configuration, or vacuum. Each has the SQL, a rollback statement, an impact and a risk rating.
- Apply… shows the SQL for editing and confirmation, then executes it on the traced server.
- Roll back… runs the rollback statement.
- Copy SQL, and Explain this query for rewrites.
After a change is applied, the plan is re-run and the status line compares cost and execution time before and after. Follow-up questions keep the conversation context.
The model never executes DDL or DML itself. Every change goes through the Apply dialog.
Privacy
PgFlow-ai has no telemetry. The advisor talks directly to the provider you chose, using your key, and only when you ask a question. To keep everything on your own hardware, use a local Ollama or another self-hosted OpenAI-compatible endpoint.