# Performance monitor

Performance monitor is a read-only agent. It inspects query statistics, blocking sessions, and Performance Advisor findings, then proposes the next change for a person to apply.

A query health agent that looks for slow queries, lock waits, and performance advisor findings.

```mermaid
flowchart TD
  Schedule([Once per hour]) --> Inspect[get_advisors and execute_sql]
  Inspect --> Signals["Slow queries, lock waits, advisor findings"]
  Signals --> Review{Needs a change?}
  Review -->|Yes| Report[Finding and verification plan]
  Review -->|No| Silent[Stay silent]
```

## What it watches

- Slow or regressing queries
- Lock waits and long-running sessions
- Unindexed foreign keys and other Performance Advisor findings

It uses `get_advisors` and read-only `execute_sql` on project-scoped [Supabase MCP](https://supabase.com/docs/guides/ai-tools/mcp). It does not create indexes, rewrite queries, or cancel sessions.

## When it watches

Run it once per hour on a schedule.

Run it on demand after a latency regression or a schema change.

## What it will output

Performance monitor reports slow or regressing queries, lock waits, and Performance Advisor findings, with a verification plan. It can recommend that a person cancel a session. It does not cancel the session or create indexes.

When the agent finds an issue, it reports in the harness. Send that report wherever you already triage work. Use the connections your harness already has. For example, Codex can open a Linear issue.

Keep the Supabase project read-only. Filing a ticket is work in the harness, not a change to the project.

If you want that routing on every scheduled run, add it to the prompt.

## Set up the agent

**Prompt**

```text
You are "Performance monitor", a Postgres performance agent for a Supabase project.
Reach the project only through Supabase MCP in read-only mode.

Run once per hour. On each check:
1. Call get_advisors with type performance.
2. Call execute_sql to inspect pg_stat_activity for sessions active longer
   than 30 seconds and any session waiting on a lock.
3. Identify blocking vs blocked PIDs. Recommend pg_cancel_backend or
   pg_terminate_backend and explain the blast radius. Do not run either.
4. Report query regressions and missing-index findings with a verification plan.

Do not change the project, create indexes, or cancel sessions.

REFERENCE
https://supabase.com/docs/guides/observability/detecting.md#performance
```

**Claude**

Create a Claude routine that runs Performance monitor once per hour.

1. Connect the [Supabase MCP server](/docs/guides/ai-tools/mcp) with `project_ref` and `read_only=true`.
2. Open [Claude routines](https://claude.ai/code/routines) or run `/schedule` in Claude Code.
3. Name it Performance monitor. Paste the prompt. Set the schedule to once per hour.

[Claude docs](https://code.claude.com/docs/en/routines)

**Codex**

Create a Codex scheduled task that runs Performance monitor once per hour.

1. Connect the [Supabase MCP server](/docs/guides/ai-tools/mcp) with `project_ref` and `read_only=true`.
2. Open **Scheduled** in the ChatGPT desktop app, or ask Codex to create a standalone scheduled task.
3. Name it Performance monitor. Paste the prompt. Set the schedule to once per hour. Each run should start a new chat.

[Codex docs](https://developers.openai.com/codex/app/automations)

**Cursor**

Create a Cursor automation that runs Performance monitor once per hour.

1. Connect the [Supabase MCP server](/docs/guides/ai-tools/mcp) with `project_ref` and `read_only=true`.
2. Create an automation in the Agents Window, at [cursor.com/automations](https://cursor.com/automations), or with the `/automate` skill.
3. Name it Performance monitor. Use a scheduled trigger (once per hour, cron `0 * * * *`). Paste the prompt. Keep the agent read-only, with no repository.

[Cursor docs](https://cursor.com/docs/cloud-agent/automations)
