← All guides

Supabase Realtime Not Working? A Checklist From Subscription to RLS

SupabaseLovableBolt

You added live updates to your app. A chat list, an order status, a dashboard counter. The code subscribes, nothing throws, and then someone edits a row and the screen stays the same until you refresh.

Supabase Realtime fails quietly. A missing setting, a policy that hides the row, or a filter that never matches all look identical from the browser: no event and no error. This guide walks through the checks in an order that splits the problem in half each time. It is written for apps that use supabase-js in the frontend, including apps built in Lovable or Bolt. The examples use Postgres Changes (the postgres_changes listener), and a later section covers Broadcast. More Supabase help: /fix/supabase.

Step 1: find out whether the channel is subscribed at all

Two different failures hide behind “Realtime is not working”. In one, the channel never connects. In the other, it connects and no events come through. Find out which one you have before changing anything.

The subscribe() method takes an optional callback that receives a status and, when something fails, an error (Supabase: subscribe reference). If your code calls .subscribe() with no arguments, add one:

const channel = supabase
  .channel('orders-live')
  .on(
    'postgres_changes',
    { event: '*', schema: 'public', table: 'orders' },
    (payload) => console.log('change', payload)
  )
  .subscribe((status, err) => {
    console.log('realtime status:', status)
    if (err) console.error(err)
  })

Open the browser console and read what it prints (Supabase: Postgres Changes troubleshooting):

  • SUBSCRIBED: the WebSocket is up and the channel joined. This says nothing about whether this user may see the rows. Go to Step 2.
  • CHANNEL_ERROR: read the error object. Supabase suggests logging the whole thing, because its cause field can hold the real reason.
  • TIMED_OUT: a connection problem. See the section on tokens and connections below.
  • CLOSED: the channel was shut down.

If you never get SUBSCRIBED, check these first (Supabase: Realtime messages not arriving; Supabase: Realtime settings):

  • The project is paused. A paused project serves nothing, Realtime included. See Supabase project paused.
  • The Realtime service is switched off. Enable Realtime service sits in the dashboard’s Realtime settings. While it is off, new connections get a 403 and joins return RealtimeDisabledForTenant.
  • Public channels are not allowed. If Allow public access to channels is off, every channel must be created with config: { private: true }. Channels without it are refused with PrivateOnly.
  • A plan limit was hit. The join can be refused with too_many_connections, too_many_joins or too_many_channels. The Free plan allows 200 concurrent connections and 100 channels per connection (Supabase: Realtime limits).
  • A proxy blocks WebSockets. A reverse proxy in front of your app has to pass the Upgrade and Connection headers through, or the handshake never finishes.

Step 2: check that the table is in the supabase_realtime publication

Realtime only sees tables that belong to a Postgres publication called supabase_realtime. Creating a table does not add it (Supabase: Postgres Changes troubleshooting). When an AI builder creates a new table for your feature, check this before anything else.

Run this in the SQL Editor:

select schemaname, tablename
from pg_publication_tables
where pubname = 'supabase_realtime';

If your table is not listed, add it:

alter publication supabase_realtime add table public.orders;

You can also open Database → Publications in the dashboard, pick supabase_realtime, and switch the table on (Supabase: Postgres Changes).

Then do a quick test that removes every other variable: subscribe with event: '*', no filter, and insert a row from the SQL Editor. If even that never fires on a SUBSCRIBED channel, the cause is the publication or RLS, not your filter syntax (Supabase: Realtime messages not arriving).

Step 3: check whether RLS hides the row from this user

Supabase’s own troubleshooting article ranks Row Level Security as the most common cause of missing events (Supabase: Postgres Changes troubleshooting). For INSERT and UPDATE, Postgres Changes only delivers a row to a subscriber whose role could select it (Supabase: Realtime messages not arriving). That is why Realtime “works” with RLS switched off and goes silent when you switch it on: RLS on, no select policy, no rows visible, no events.

Test it from the app itself, signed in as the same user who is subscribing:

const { data, error } = await supabase
  .from('orders')
  .select('*')
  .eq('id', changedRowId)

console.log({ data, error })

An empty data array means a policy is blocking that row for that user. Don’t test in the SQL Editor as postgres, because that role bypasses RLS.

The fix is a select policy that matches who should see the rows. For a table where each user sees their own orders:

create policy "Users can read their own orders"
on public.orders
for select
to authenticated
using ( (select auth.uid()) = user_id );

If policies are new to you, Supabase RLS policies explained covers how using works, and new row violates row-level security policy covers the insert side.

Two extra traps:

  • Updates that move a row out of view. The policy has to pass for the row as it was before the change and as it is after. If a policy only shows rows where status = 'active' and an update sets it to archived, that event may not arrive (Supabase: Postgres Changes troubleshooting).
  • Tables outside public. Postgres Changes works on public without extra setup. For another schema, give the role from the subscriber’s token select on the table (authenticated for signed-in users, anon for signed-out ones), and keep RLS on so the grant does not open the whole table (Supabase: Postgres Changes). There is no dashboard switch for the grant.
grant select on table app.orders to authenticated;

Step 4: DELETE events and the old row follow different rules

DELETE events and the payload.old record have three rules of their own, all set out in the Postgres Changes docs (Supabase: Postgres Changes).

RLS does not apply to DELETE. Postgres cannot check whether a user could read a row that no longer exists, so delete events are not filtered by your policies (Supabase: Realtime messages not arriving). Plan for that: a subscriber can learn that a row was deleted even if it could never read that row.

Filtered DELETE subscriptions need replica identity full. A listener such as { event: 'DELETE', filter: 'room_id=eq.42' } only works if the table’s replica identity is set to full. Without it, Postgres doesn’t keep the room_id of the deleted row in the change record.

alter table public.messages replica identity full;

The old row is mostly empty by default. On UPDATE and DELETE, the default replica identity sends only the primary key in payload.old. Setting replica identity to full adds the previous values, except on tables with RLS enabled. There, payload.old still holds only the primary key, even with full (Supabase: Postgres Changes troubleshooting).

That last point breaks any code that compares payload.old.status with payload.new.status to decide whether something changed. When payload.old.status is undefined, the comparison is true on every update. On a protected table, keep the value you need in client state, or re-read the row, instead of trusting payload.old.

One more limit belongs here. Postgres change payloads are capped at 1,024 KB. Past that cap, the new and old records only carry fields whose value is 64 bytes or smaller, so large text or JSON columns can go missing from the payload (Supabase: Realtime limits).

Step 5: check filters, names and column types

When the channel is subscribed, the table is in the publication and RLS allows the row, compare the subscription settings against the row that changed (Supabase: Postgres Changes troubleshooting):

  • Table and schema. The name must match exactly, including case, and schema must be the one the table lives in.
  • Event. INSERT, UPDATE, DELETE or *. A listener for INSERT won’t fire on an update.
  • Filter syntax. A filter is a single string in the form column=operator.value, such as room_id=eq.42. Writing room_id = 42 is wrong.
  • Supported operators. The Postgres Changes docs list eq, neq, lt, lte, gt, gte, in (up to 100 values), like, ilike, match, imatch, is and isdistinct. A not. prefix negates any of them. Conditions separated by commas are combined with AND, and OR is not supported (Supabase: Postgres Changes).
  • Column types. The comparison operators use Postgres’s own comparison for the column’s type, so lt on a text column compares text, not numbers. like and match need a text column, and is.true or is.false need a boolean one.
  • Special characters. Values containing a comma, a parenthesis, a double quote or a backslash must be wrapped in double quotes, as in name=eq."Doe, Jane". In JavaScript, the postgresChangesFilter() helper adds the quotes for you.
  • Channel name. Any string works except realtime.

Step 6: check who the client is when it subscribes

Realtime checks rows as the role in the access token the client sends. A signed-in user’s token carries authenticated. A client with only the public key is anon (Supabase: Realtime messages not arriving). Your select policy has to cover whichever role is actually subscribing.

What can go wrong:

  • Subscribing before the session is ready. If the channel opens before your app has restored the signed-in session, it can join as anon, and an authenticated-only policy hides every row. Open the channel after the session is known, and subscribe again after sign-in or sign-out.
  • An expired or incomplete token. Realtime rejects a token that is expired or lacks the role and exp claims, with InvalidJWTToken (Supabase: Realtime error codes). For private channels, Realtime caches a client’s access when it joins and refreshes it only when a new token is sent. If no new token arrives, the client is disconnected when the token expires (Supabase: Realtime authorization).
  • Your own JWTs. If you sign custom tokens, set the token on the Realtime client after creating the Supabase client and before joining a channel (Supabase: Postgres Changes). The service_role key must never be in browser code, because it bypasses RLS.

Two connection issues also look like a broken subscription:

  • Backgrounded tabs. Browsers slow down timers in inactive tabs. The Realtime client can then miss its heartbeats, and the server drops the socket without any error in your app. Supabase recommends creating the client with realtime: { worker: true } and a heartbeatCallback that reconnects when the status is disconnected (Supabase: silent disconnections in background apps).
  • TIMED_OUT from server code. When Realtime runs in Node.js, Supabase links TIMED_OUT to newer supabase-js versions running on Node.js older than v22. Upgrading Node.js to a current LTS release is the first fix it lists (Supabase: TIMED_OUT errors).

Step 7: clean up channels in React

In React and Next.js, a component that opens a channel in useEffect and never removes it leaves the old channel running after a re-render or a route change. You then get duplicate events, events for the previous room, or a channel still filtered on an old id (Supabase: Postgres Changes troubleshooting). Leftover channels also count toward the limit of 100 channels per connection (Supabase: Realtime limits).

Return a cleanup function that calls removeChannel, which unsubscribes and tears the channel down (Supabase: removeChannel reference):

useEffect(() => {
  if (!roomId) return

  const channel = supabase
    .channel(`room-${roomId}`)
    .on(
      'postgres_changes',
      {
        event: 'INSERT',
        schema: 'public',
        table: 'messages',
        filter: `room_id=eq.${roomId}`,
      },
      (payload) => setMessages((prev) => [...prev, payload.new])
    )
    .subscribe()

  return () => {
    supabase.removeChannel(channel)
  }
}, [roomId])

In development with Strict Mode, React mounts each effect, cleans it up, and mounts it again (React: useEffect). With a correct cleanup that is harmless. Without one, you end up with two subscriptions in development even when production has one.

One timing gap matters in tests. Supabase confirms a short window after SUBSCRIBED shows up on the client during which the server is not yet streaming changes, so a write made immediately after subscribing can be missed. Its troubleshooting article shows how to wait for the system message for postgres_changes before writing (Supabase: Postgres Changes troubleshooting).

Even with everything right, Realtime does not promise to deliver every event. Network drops and reconnects can lose one. When losing an update would hurt, use each event as a cue to re-fetch, and re-fetch after a reconnect, rather than treating the event stream as the record (Supabase: Postgres Changes troubleshooting).

Broadcast or Postgres Changes: which one you need

Supabase offers two ways to stream database changes (Supabase: subscribing to database changes):

  • Postgres Changes needs less setup: add the table to the publication and subscribe. It checks every event against every subscriber, so one change with 100 subscribers means 100 authorization checks. Changes are also processed on one thread to keep them in order, so a larger compute size does little for throughput (Supabase: Postgres Changes).
  • Broadcast is what Supabase recommends for scale and security. A trigger calls realtime.broadcast_changes(), and clients listen on a private channel. It needs RLS policies on realtime.messages, and the client calls supabase.realtime.setAuth() before joining.

The Postgres Changes docs point to Broadcast once you expect roughly 3,000 or more clients listening to the same table’s changes at once.

If you switch to Broadcast and messages stop arriving, the checklist changes (Supabase: Realtime messages not arriving):

  • A private channel needs a select policy on realtime.messages to receive and an insert policy to send, scoped to extension = 'broadcast'. Without the select policy, sending succeeds and nothing is received.
  • The topic string must match exactly on every side.
  • The private flag in realtime.send() or realtime.broadcast_changes() must match the client’s config.private. Two channels that share a topic but differ in the private flag are treated as separate channels (Supabase: Realtime concepts).
  • A WarnSendingBroadcastMessage warning in the Postgres logs means the insert into realtime.messages failed. That table is split into daily partitions, and a day’s partition is only created after the first WebSocket client connects.

Local development

The local stack from supabase start runs its own database, so dashboard changes on your hosted project don’t reach it, and the reverse is also true.

  • Realtime has to be enabled in config.toml. The [realtime] section has enabled = true by default. If someone set it to false, no local channel will connect (Supabase: CLI config).
  • Put the publication change in a migration. supabase db reset rebuilds the local database from your migrations and seed file (Supabase: database migrations). A table you switched on in local Studio drops out of the publication after a reset unless a migration adds it. Write the alter publication supabase_realtime add table ... line in a versioned migration so local, staging and production all get it.
  • Check generated diffs. If you use declarative schemas, the newer pg-delta diff engine includes publications. The legacy migra engine does not capture alter publication ... add table, so add that statement by hand (Supabase: declarative database schemas).

A prompt for your AI builder

If you want Lovable or Bolt to do the checking, give it a narrow brief rather than “fix realtime”:

Realtime events for the orders table are not arriving. Do not rewrite the feature.
1. Add a status callback to the .subscribe() call that logs status and err.
2. Show me the SQL to list tables in the supabase_realtime publication, and a
   migration that adds public.orders if it is missing.
3. Show me the current SELECT policies on public.orders and which role they apply to.
4. Make sure the channel is created only after the auth session is loaded,
   and that the useEffect cleanup calls supabase.removeChannel(channel).
Do not disable RLS and do not use the service_role key in client code.

Run the SQL yourself and read the results before you accept a change. If the events are still lost after this checklist, the problem sits where RLS, the publication and the client code meet, and a senior engineer can trace where the events are lost; see Supabase help on inahei.pro.

FAQ

Why do INSERT events arrive but not DELETE?

Check the listener first. A filtered DELETE listener, such as one with room_id=eq.42, only receives events when the table’s replica identity is full (Supabase: Postgres Changes). Also confirm the listener’s event is DELETE or *. RLS is not the reason, because it is not applied to DELETE events.

Why does Realtime work with RLS off but stop when I turn it on?

With RLS on, Postgres Changes only sends a subscriber the rows its role can select. Add a select policy for the role that subscribes, authenticated or anon, and check that the client is signed in before it joins the channel (Supabase: Realtime messages not arriving).

How do I get the old row’s values on UPDATE or DELETE?

Set the table’s replica identity to full. On tables with RLS enabled, payload.old carries nothing but the primary key, so keep the previous value in your app’s state or re-read the row (Supabase: Postgres Changes troubleshooting).

Why does it work in preview but not after publishing?

Compare what each one is connected to. On Lovable’s built-in backend, a draft can have its own backend with a copy of your structure and example data, while the live app uses your live database (Lovable: drafts). The published site also keeps serving the last version you published until you publish again (Lovable: publish). For an app deployed elsewhere, check that the host’s environment variables point at the same Supabase project you tested against. Then run Step 2 and Step 3 against the database the live app uses.

Comments

Add a comment

Generated for you. Click to type your own.

Required. Never shown on the page. Privacy policy.

Basic markdown: **bold**, *italic*, `code`, lists, quotes, and fenced code blocks. HTML shows as plain text.

Your draft stays on this device until you post.