---
name: supabase-debug-with-logs
description: Debug a Supabase problem, such as API errors, auth failures, slow queries, edge function crashes or realtime and storage issues, from project logs and advisors, then propose a fix. Use when the user reports that something in their Supabase app is failing, slow or returning errors.
---

# Debug a Supabase problem from logs

## Steps

1. Pin down the symptom: which feature, the error message or status code, and roughly when.
2. Pick the log service that matches: `api` for PostgREST and gateway errors, `postgres`, `auth`, `storage`, `realtime` or `edge-function`. Read recent entries with `get_logs`, or run a filtered query over a time window with `query_logs`.
3. Read the schema context with `list_tables` when the error names a table or column.
4. Common causes to check:
   - 401 or 403, or empty results: RLS policies blocking the role. Inspect them with a read-only `execute_sql` on `pg_policies`.
   - 500 from PostgREST: a database error, which appears in the postgres logs.
   - Slow requests: missing indexes. `get_advisors` with the performance type flags them.
   - Edge function errors: read the function with `get_edge_function` alongside its logs.
5. Confirm with a read-only query when you can, such as `explain` on the slow query.

## Report

Cause, the evidence (log lines, policy or plan), and the fix as SQL or code. Any fix that changes the database or a function waits for the user's approval and follows the schema-change steps.
