The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
docs: add Realtime bring your own db docs
Wen Bo Xiefd165a7b1480
diff --git a/apps/docs/components/Navigation/Navigation.constants.ts b/apps/docs/components/Navigation/Navigation.constants.tsindex beb5bdc962d..96799eb177d 100644--- a/apps/docs/components/Navigation/Navigation.constants.ts+++ b/apps/docs/components/Navigation/Navigation.constants.ts@@ -276,6 +276,11 @@ export const menuItems: NavMenu = {url: '/guides/realtime/subscribing-to-database-changes',items: [],},+ {+ name: 'Bring Your Own Database',+ url: '/guides/realtime/bring-your-own-database',+ items: [],+ },{name: 'Using Realtime with Next.js',url: '/guides/realtime/realtime-with-nextjs',diff --git a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.tsindex 971acd0c1bf..14f72d845cc 100644--- a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts+++ b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts@@ -603,6 +603,11 @@ export const realtime = {name: 'Subscribing to Database Changes',url: '/guides/realtime/subscribing-to-database-changes',},+ {+ name: 'Bring Your Own Database',+ url: '/guides/realtime/bring-your-own-database',+ items: [],+ },{name: 'Using Realtime with Next.js',url: '/guides/realtime/realtime-with-nextjs',diff --git a/apps/docs/pages/guides/realtime/bring-your-own-database.mdx b/apps/docs/pages/guides/realtime/bring-your-own-database.mdxnew file mode 100644index 00000000000..57600f9cf2c--- /dev/null+++ b/apps/docs/pages/guides/realtime/bring-your-own-database.mdx@@ -0,0 +1,107 @@+import Layout from '~/layouts/DefaultGuideLayout'++export const meta = {+ id: 'bring-your-own-database',+ title: 'Bring Your Own Database',+ description: 'Bring your own Postgres database to subscribe to Realtime changes',+ sidebar_label: 'Bring Your Own Database',+}++Realtime Database Changes works with any Postgres database that has logical replication enabled and the [wal2json](https://github.com/eulerto/wal2json) extension installed.++<Admonition type="note">++After setting up your database for Realtime, [submit a support ticket](https://app.supabase.com/support/new) if you want to use your database with hosted Supabase Realtime.++</Admonition>++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.++## Realtime Database Setup++### `supabase_realtime` Publication++Create `supabase_realtime` publication and add tables you want Realtime to listen to:++```sql+create publication supabase_realtime with (publish = 'insert, update, delete');++alter publication supabase_realtime add table messages, users;+```++<Admonition type="tip">++If the payload contains a `401 Unauthorized` then you will need to grant `select` privileges to the table for the database role you want to authorize to receive database changes:++```sql+grant select on table messages to anon;+```++</Admonition>++### `realtime` Schema++Create a `realtime` schema:++```sql+create schema realtime;+```++### `supabase_realtime_admin` Role++Create a `supabase_realtime_admin` database role and grant it replication permissions:++```sql+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:++```sql+grant rds_replication to supabase_realtime_admin;+```++### `supabase_realtime_admin` Privileges++Grant `supabase_realtime_admin` privileges for `realtime` schema and all related Realtime objects:++```sql+grant all on schema realtime to supabase_realtime_admin;+grant all on all tables in schema realtime to supabase_realtime_admin;+grant all on all sequences in schema realtime to supabase_realtime_admin;+grant all on all routines in schema realtime to supabase_realtime_admin;+```++### `authenticated` Role++Create an `authenticated` role:++```sql+create role authenticated nologin noinherit;+```++<Admonition type="note">++This role is hardcoded into Realtime migrations so it's required for the time being.++</Admonition>++export const Page = ({ children }) => <Layout meta={meta} children={children} />++export default Pagediff --git a/apps/docs/pages/guides/self-hosting/realtime/config.mdx b/apps/docs/pages/guides/self-hosting/realtime/config.mdxindex a52dc2c111a..f576951b201 100644--- a/apps/docs/pages/guides/self-hosting/realtime/config.mdx+++ b/apps/docs/pages/guides/self-hosting/realtime/config.mdx@@ -11,6 +11,8 @@ export const meta = {<div>{spec.info.description}</div>+See [this guide](/docs/guides/realtime/bring-your-own-database) if you want to configure your database to work with Realtime.+<div>{spec.info.tags.map(tag => {return (