Realtime

Bring Your Own Database

Realtime Database Changes works with any Postgres database that has logical replication enabled and the wal2json extension installed.

The following steps will make sure that your database is properly set up to work with Realtime.

wal2json Extension

Realtime relies on the wal2json Postgres extension to format database changes to JSON which are then sent to Realtime subscribers.

Postgres databases managed by AWS RDS and Google Cloud SQL should already have wal2json installed. Please check to make sure this is indeed the case with your Postgres database.

Logical replication configuration

Realtime relies on Postgres' logical replication functionality to get database changes. Please enable logical replication on your database and configure the following settings:

  • max_replication_slots: we recommend 10 because Realtime requires a few slots plus the slots you'll need for your non-Realtime logical replication needs.
  • max_slot_wal_keep_size: we recommend 1024 (MB) so Realtime can attempt to deliver more database changes stored in Postgres.

See Compute Add-ons for the recommended max_replication_slots at different instance sizes based on the values we use for our own cloud offering.

Realtime database setup

supabase_realtime Publication

Create supabase_realtime publication and add tables you want Realtime to listen to:


_10
create publication supabase_realtime with (publish = 'insert, update, delete');
_10
_10
alter publication supabase_realtime add table messages, users;

realtime Schema

Create a realtime schema:


_10
create schema realtime;

supabase_realtime_admin Role

Create a supabase_realtime_admin database role and grant it replication permissions:


_10
create role supabase_realtime_admin with noinherit login password 'secure-password';

Make sure to grant supabase_realtime_admin role with replication permissions. This step will vary based on your database provider.

For example, if your database is managed by AWS RDS then you can run:


_10
grant rds_replication to supabase_realtime_admin;

supabase_realtime_admin Privileges

Grant supabase_realtime_admin privileges for realtime schema and all related Realtime objects:


_10
grant all on schema realtime to supabase_realtime_admin;
_10
grant all on all tables in schema realtime to supabase_realtime_admin;
_10
grant all on all sequences in schema realtime to supabase_realtime_admin;
_10
grant all on all routines in schema realtime to supabase_realtime_admin;

authenticated Role

Create an authenticated role:


_10
create role authenticated nologin noinherit;