Overview
Postgres Changes allows you to subscribe to real-time changes in your PostgreSQL database. When a row is inserted, updated, or deleted, Realtime broadcasts the change to all subscribed clients.Postgres Changes uses PostgreSQL’s replication functionality. Changes are captured from the Write-Ahead Log (WAL) and broadcast to connected clients.
Enable Realtime
Before subscribing to changes, you need to enable Realtime for your tables:Via Dashboard
- Go to the Database page in your Supabase Dashboard
- Click on “Replication” in the sidebar
- Toggle Realtime for the tables you want to watch
Via SQL
Basic Usage
Listen to All Changes
Subscribe to all events (INSERT, UPDATE, DELETE) on a table:Listen to Specific Events
Subscribe only to INSERT events:INSERT- New rows insertedUPDATE- Existing rows updatedDELETE- Rows deleted*- All events
Filter by Column Values
Listen to changes only when specific column values match:eq- Equalsneq- Not equalslt- Less thanlte- Less than or equalgt- Greater thangte- Greater than or equal
Payload Structure
The payload object contains information about the change:Event Type Differences
INSERT:new contains the inserted row, old is empty
new and old contain data
old contains the deleted row, new is empty
Advanced Patterns
Multiple Table Subscriptions
Listen to changes across multiple tables using one channel:Real-time Dashboard Example
Automatically update a dashboard when metrics change:Live Query Pattern
Combine initial fetch with real-time updates:Authorization with RLS
Postgres Changes respects Row Level Security policies. Clients only receive changes for rows they have permission to see.Enable RLS
Performance Tips
Limit the Number of Subscriptions
Each subscription creates overhead. Combine related subscriptions when possible:Use Column Filters
Filter at the database level rather than in your application:Clean Up Subscriptions
Always unsubscribe when done:Troubleshooting
No Changes Received
- Check if Realtime is enabled for the table in the Dashboard
- Verify RLS policies aren’t blocking changes
- Confirm subscription status:
Changes Delayed
- Realtime uses PostgreSQL’s logical replication, which has minimal latency (typically < 100ms)
- Network conditions affect delivery time
- Check your project’s health in the Dashboard
Next Steps
Broadcast
Send ephemeral messages between clients
Presence
Track online users in real-time
