supabase-incident-runbook
Execute Supabase incident response: dashboard health checks, connection pool status, pg_stat_activity queries, RLS debugging, Edge Function logs, storage health, and escalation. Use when responding to Supabase outages, investigating production errors, debugging connection issues, or preparing evidence for Supabase support escalation. Trigger: "supabase incident", "supabase outage", "supabase down", "supabase on-call", "supabase emergency", "supabase broken", "supabase connection issues".
What this skill does
# Supabase Incident Runbook
## Overview
When a Supabase-backed application experiences failures, you need a structured response: verify the Supabase platform status, check your connection pool, inspect `pg_stat_activity` for stuck queries, debug RLS policies that silently filter data, review Edge Function execution logs, verify storage bucket health, and escalate to Supabase support with a complete evidence bundle. This runbook covers every layer from the SDK client through the database to platform services.
**When to use:** Production errors involving Supabase, degraded API response times, connection pool exhaustion, silent data filtering from RLS, Edge Function cold start failures, or storage upload/download errors.
## Prerequisites
- Supabase project with dashboard access at [supabase.com/dashboard](https://supabase.com/dashboard)
- `@supabase/supabase-js` v2+ installed in your project
- Supabase CLI installed for Edge Function log access
- Direct database connection string (for `psql` diagnostics)
- Access to [status.supabase.com](https://status.supabase.com) for platform health
## Instructions
### Step 1: Triage — Platform vs. Application
Determine whether the issue is a Supabase platform incident or an application-level bug. Check platform status first, then verify your SDK client connectivity.
**Check Supabase platform status:**
```bash
# Check official status page
curl -sf https://status.supabase.com/api/v2/status.json | jq '{
indicator: .status.indicator,
description: .status.description
}'
# Expected: { "indicator": "none", "description": "All Systems Operational" }
# Check for active incidents
curl -sf https://status.supabase.com/api/v2/incidents/unresolved.json | jq '.incidents[] | {
name: .name,
status: .status,
impact: .impact,
created_at: .created_at
}'
```
**Verify SDK client connectivity from your application:**
```typescript
import { createClient } from '@supabase/supabase-js';
const supabase = createClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!
);
// Quick health check — select 1 from a small table
async function healthCheck(): Promise<{
status: 'healthy' | 'degraded' | 'down';
latencyMs: number;
error?: string;
}> {
const start = performance.now();
try {
const { data, error } = await supabase
.from('_health_check')
.select('id')
.limit(1)
.maybeSingle();
const latencyMs = Math.round(performance.now() - start);
if (error) {
return { status: 'degraded', latencyMs, error: error.message };
}
return {
status: latencyMs > 2000 ? 'degraded' : 'healthy',
latencyMs,
};
} catch (err) {
return {
status: 'down',
latencyMs: Math.round(performance.now() - start),
error: err instanceof Error ? err.message : 'Unknown error',
};
}
}
// Create a minimal health check table (run once)
// CREATE TABLE _health_check (id int PRIMARY KEY DEFAULT 1);
// INSERT INTO _health_check VALUES (1);
// ALTER TABLE _health_check ENABLE ROW LEVEL SECURITY;
// CREATE POLICY "allow_anon_read" ON _health_check FOR SELECT USING (true);
```
**Decision tree:**
```
Is status.supabase.com showing an incident?
├─ YES → Supabase platform issue
│ ├─ Enable fallback/cache layer
│ ├─ Monitor status page for resolution
│ └─ Skip to Step 3 for connection pool protection
└─ NO → Application-level issue
├─ Does healthCheck() return 'healthy'?
│ ├─ YES → Issue is in your queries/RLS/Edge Functions → Step 2
│ └─ NO → Connection or auth issue → Step 2 + Step 3
└─ Check error codes: 401=auth, 429=rate limit, 500=server error
```
### Step 2: Database Diagnostics with pg_stat_activity
Connect directly to the database to inspect active connections, find stuck queries, and detect connection leaks. These queries run via `psql` or the Supabase SQL Editor.
**Connection pool status:**
```sql
-- Current connections grouped by state
SELECT state, count(*) AS connections,
max(extract(epoch FROM age(now(), state_change)))::int AS max_idle_seconds
FROM pg_stat_activity
WHERE datname = current_database()
GROUP BY state
ORDER BY connections DESC;
-- Expected healthy output:
-- state | connections | max_idle_seconds
-- idle | 3 | 12
-- active | 1 | 0
-- | 2 | (null) ← background workers
-- WARNING: If idle > 20 or idle_in_transaction > 0, you have a leak
```
**Find long-running and stuck queries:**
```sql
-- Queries running longer than 10 seconds
SELECT pid, usename, state,
age(now(), query_start)::text AS duration,
wait_event_type, wait_event,
left(query, 120) AS query_preview
FROM pg_stat_activity
WHERE state = 'active'
AND query NOT LIKE '%pg_stat_activity%'
AND age(now(), query_start) > interval '10 seconds'
ORDER BY query_start;
-- Idle-in-transaction connections (connection leak indicator)
SELECT pid, usename,
age(now(), state_change)::text AS idle_duration,
left(query, 100) AS last_query
FROM pg_stat_activity
WHERE state = 'idle in transaction'
ORDER BY state_change;
-- Kill a specific stuck query (use with caution)
-- SELECT pg_cancel_backend(<pid>); -- graceful cancel
-- SELECT pg_terminate_backend(<pid>); -- force kill
```
**Check connection limits:**
```sql
-- Are we near the connection limit?
SELECT
max_conn,
used,
max_conn - used AS available,
round(100.0 * used / max_conn, 1) AS pct_used
FROM (SELECT count(*) AS used FROM pg_stat_activity) t,
(SELECT setting::int AS max_conn FROM pg_settings WHERE name = 'max_connections') s;
-- If pct_used > 80%, you need connection pooling via Supavisor
-- Dashboard → Project Settings → Database → Connection Pooling
```
**Application-side connection monitoring:**
```typescript
import { createClient } from '@supabase/supabase-js';
const supabase = createClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.SUPABASE_SERVICE_ROLE_KEY!,
{ auth: { autoRefreshToken: false, persistSession: false } }
);
// Monitor connection health from the application
async function getConnectionStats() {
const { data, error } = await supabase.rpc('get_connection_stats');
if (error) throw error;
return data;
}
// Create this function in your database:
// CREATE OR REPLACE FUNCTION get_connection_stats()
// RETURNS json AS $$
// SELECT json_build_object(
// 'active', (SELECT count(*) FROM pg_stat_activity WHERE state = 'active'),
// 'idle', (SELECT count(*) FROM pg_stat_activity WHERE state = 'idle'),
// 'idle_in_tx', (SELECT count(*) FROM pg_stat_activity WHERE state = 'idle in transaction'),
// 'total', (SELECT count(*) FROM pg_stat_activity WHERE datname = current_database()),
// 'max', (SELECT setting::int FROM pg_settings WHERE name = 'max_connections')
// );
// $$ LANGUAGE sql SECURITY DEFINER;
```
### Step 3: RLS Debugging, Edge Functions, and Storage
Debug silent data filtering from Row Level Security policies, inspect Edge Function execution, and verify storage bucket health.
**RLS policy debugging:**
```sql
-- List all RLS policies on a table
SELECT policyname, cmd, permissive,
pg_get_expr(qual, polrelid) AS using_expression,
pg_get_expr(with_check, polrelid) AS with_check_expression
FROM pg_policy
JOIN pg_class ON pg_class.oid = polrelid
WHERE relname = 'your_table_name';
-- Test as a specific user (simulates their JWT in SQL Editor)
SET request.jwt.claim.sub = 'target-user-uuid';
SET request.jwt.claim.role = 'authenticated';
-- Run the query that's failing
SELECT * FROM your_table_name WHERE user_id = 'target-user-uuid';
-- If empty but data exists → RLS is filtering incorrectly
-- Verify what auth.uid() resolves to
SELECT auth.uid();
SELECT auth.jwt();
-- Compare with service role (bypasses RLS)
-- Use service_role key in createClient to confirm data exists
-- Reset after testing
RESET request.jwt.claim.sub;
RESET request.jwt.claim.role;
```
**RLS debugging from theRelated in Data & Analytics
clawarr-suite
IncludedComprehensive management for self-hosted media stacks (Sonarr, Radarr, Lidarr, Readarr, Prowlarr, Bazarr, Overseerr, Plex, Tautulli, SABnzbd, Recyclarr, Unpackerr, Notifiarr, Maintainerr, Kometa, FlareSolverr). Deep library exploration, analytics, dashboard generation, content management, request handling, subtitle management, indexer control, download monitoring, quality profile sync, library cleanup automation, notification routing, collection/overlay management, and media tracker integration (Trakt, Letterboxd, Simkl).
querying-soql
IncludedSOQL query generation, optimization, and analysis with 100-point scoring. Use this skill when the user needs SOQL/SOSL authoring or optimization: natural-language-to-query generation, relationship queries, aggregates, query-plan analysis, and performance or safety improvements for Salesforce queries. TRIGGER when: user writes, optimizes, or debugs SOQL/SOSL queries, touches .soql files, or asks about relationship queries, aggregates, or query performance. DO NOT TRIGGER when: bulk data operations (use handling-sf-data), Apex DML logic (use generating-apex), or report/dashboard queries.
app-store-optimization
IncludedApp Store Optimization (ASO) toolkit for researching keywords, analyzing competitor rankings, generating metadata suggestions, and improving app visibility on Apple App Store and Google Play Store. Use when the user asks about ASO, app store rankings, app metadata, app titles and descriptions, app store listings, app visibility, or mobile app marketing on iOS or Android. Supports keyword research and scoring, competitor keyword analysis, metadata optimization, A/B test planning, launch checklists, and tracking ranking changes.
habit-flow
IncludedAI-powered atomic habit tracker with natural language logging, streak tracking, smart reminders, and coaching. Use for creating habits, logging completions naturally ("I meditated today"), viewing progress, and getting personalized coaching.
app-store-optimization
IncludedApp Store Optimization (ASO) toolkit for researching keywords, analyzing competitor rankings, generating metadata suggestions, and improving app visibility on Apple App Store and Google Play Store. Use when the user asks about ASO, app store rankings, app metadata, app titles and descriptions, app store listings, app visibility, or mobile app marketing on iOS or Android. Supports keyword research and scoring, competitor keyword analysis, metadata optimization, A/B test planning, launch checklists, and tracking ranking changes.
visualizing-data
IncludedBuilds dashboards, reports, and data-driven interfaces requiring charts, graphs, or visual analytics. Provides systematic framework for selecting appropriate visualizations based on data characteristics and analytical purpose. Includes 24+ visualization types organized by purpose (trends, comparisons, distributions, relationships, flows, hierarchies, geospatial), accessibility patterns (WCAG 2.1 AA compliance), colorblind-safe palettes, and performance optimization strategies. Use when creating visualizations, choosing chart types, displaying data graphically, or designing data interfaces.