📄 SKILL.md

← Vault

name: supabase-realtime-publication-debug

description: "Debug Supabase Realtime: frontend subscribes but never receives updates. Root cause: table not in supabase_realtime publication."

category: supabase

tags: [supabase, realtime, postgres, publication, websocket]


Supabase Realtime — Tabela Não Recebe Updates Despite Subscription

Symptom

Frontend has Supabase realtime subscription configured:

`typescript

supabase.channel('all-realtime')

.on('postgres_changes', { event: 'UPDATE', schema: 'public', table: 'tasks' }, handler)

.subscribe()

`

The subscription connects fine, but UPDATE/INSERT/DELETE events from the database never reach the frontend. No errors, no indication of what's wrong.

Root Cause

Supabase Realtime requires explicit inclusion of each table in the supabase_realtime PostgreSQL publication. This is NOT automatic — it's a separate publication layer that the Supabase Dashboard's Replication UI manages, but if a table is missing from the publication, realtime events are silently dropped.

Diagnostic SQL

Run on the Supabase Postgres database (via psql or Docker exec):

`sql

-- Check which tables are in the supabase_realtime publication

SELECT tablename

FROM pg_publication_tables

WHERE pubname = 'supabase_realtime';

-- Check if a specific table is missing

SELECT count(*)

FROM pg_publication_tables

WHERE pubname = 'supabase_realtime' AND tablename = 'tasks';

-- Returns 0 = table is NOT in the publication (problem!)

-- Returns 1 = table is in the publication (OK)

`

Fix

`sql

-- Add the missing table to the publication

ALTER PUBLICATION supabase_realtime ADD TABLE tasks;

`

To add ALL tables at once (useful after migrations create new tables):

`sql

-- Add specific tables

ALTER PUBLICATION supabase_realtime ADD TABLE tasks;

ALTER PUBLICATION supabase_realtime ADD TABLE message_log;

ALTER PUBLICATION supabase_realtime ADD TABLE message_replies;

ALTER PUBLICATION supabase_realtime ADD TABLE incoming_messages;

`

How to Run on VPS

`bash

Docker-based Supabase Postgres

docker exec deploy-vps-db-1 psql -U postgres -d postgres -c "ALTER PUBLICATION supabase_realtime ADD TABLE tasks;"

List tables currently in publication

docker exec deploy-vps-db-1 psql -U postgres -d postgres -t -c "SELECT tablename FROM pg_publication_tables WHERE pubname = 'supabase_realtime';"

`

Verify After Fix

`sql

-- Should return 1 for each table you expect to use realtime

SELECT tablename FROM pg_publication_tables WHERE pubname = 'supabase_realtime';

`

Gotchas