Files
supabase/apps/docs/content/guides/database/postgres/setup-replication-external.mdx
Miranda Limonczenko 1479013fd8 docs(guides): rework five how-to pages to the how-to template (#53650)
Closes DOCS-1614

## Problem
This PR is to apply the template to top-five low-hanging fruit pages --
ones that nearly match the template already and do not need to break out
new topics.

This PR also tests the template to see that it is working as expected.

## Solution

Apply the How-to Template to 5 how-to pages.


## Preview links

| Site | Live | Preview | Search for |
| --- | --- | --- | --- |
| Docs |
[/docs/guides/storage/analytics/creating-analytics-buckets](https://supabase.com/docs/guides/storage/analytics/creating-analytics-buckets)
|
[/docs/guides/storage/analytics/creating-analytics-buckets](https://docs-git-docs-howto-rework-easy-pages-supabase.vercel.app/docs/guides/storage/analytics/creating-analytics-buckets)
| Create an analytics bucket |
| Docs |
[/docs/guides/functions/debugging-tools](https://supabase.com/docs/guides/functions/debugging-tools)
|
[/docs/guides/functions/debugging-tools](https://docs-git-docs-howto-rework-easy-pages-supabase.vercel.app/docs/guides/functions/debugging-tools)
| Debug Edge Functions locally |
| Docs |
[/docs/guides/queues/consuming-messages-with-edge-functions](https://supabase.com/docs/guides/queues/consuming-messages-with-edge-functions)
|
[/docs/guides/queues/consuming-messages-with-edge-functions](https://docs-git-docs-howto-rework-easy-pages-supabase.vercel.app/docs/guides/queues/consuming-messages-with-edge-functions)
| Consume queue messages |
| Docs |
[/docs/guides/database/postgres/setup-replication-external](https://supabase.com/docs/guides/database/postgres/setup-replication-external)
|
[/docs/guides/database/postgres/setup-replication-external](https://docs-git-docs-howto-rework-easy-pages-supabase.vercel.app/docs/guides/database/postgres/setup-replication-external)
| Replicate to an external Postgres |
| Docs |
[/docs/guides/security/rotate-leaked-api-keys](https://supabase.com/docs/guides/security/rotate-leaked-api-keys)
|
[/docs/guides/security/rotate-leaked-api-keys](https://docs-git-docs-howto-rework-easy-pages-supabase.vercel.app/docs/guides/security/rotate-leaked-api-keys)
| Rotate a leaked API key |

## Review instructions

1. Open the live and preview links for each page side by side.
2. Check that each page opens with a value statement and ends with Next
steps.
3. Check that the code blocks and the Dashboard steps match the live
page.
4. On the debugging page, check that the steps run in order across the
two phases.
5. On the replication page, check that the code blocks and notes render
under the right steps and the numbering runs 1 to 5.
6. On the rotate page, check that the "Retire the compromised key" link
in Prerequisites still jumps to its heading.

## Checklist

Check all before review:

- [x] I have read
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
- [x] If I wrote a new docs topic or edited an existing topic, I used
the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs
[style
guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide)
2026-11-19 15:01:05 -08:00

90 lines
3.1 KiB
Plaintext

---
title: 'Replicate to an external Postgres'
description: 'Set up logical replication from your Supabase database to a Postgres database outside Supabase: create a publication and a slot, subscribe, then add tables.'
footerHelpType: 'postgres'
---
Replicate changes from your Supabase database to a Postgres database outside Supabase, using logical replication with a publication and a subscription.
## Prerequisites
For this example, you need:
- A [Supabase project](/dashboard/new/_)
- A [Postgres database](https://www.postgresql.org/download/) (running v10 or later)
## Procedure
You run commands on both of these databases to publish changes from the Supabase database to the external database.
1. Create a `publication` on the **Supabase database**:
```sql
CREATE PUBLICATION example_pub;
```
2. Also on the **Supabase database**, create a `replication slot`:
```sql
select pg_create_logical_replication_slot('example_slot', 'pgoutput');
```
3. Connect to your **external database** and subscribe to the `publication`:
<Admonition type="caution">
This needs a **direct** connection (not a Connection Pooler) to your database and you can find the connection info in the [**Connect** panel](/dashboard/project/_?showConnect=true) in the `Direct connection` section.
You also need to ensure that IPv6 is supported by your replication destination (or you can enable the [IPv4 add-on](/docs/guides/platform/ipv4-address))
If you would prefer not to use the `postgres` user, then you can run `CREATE ROLE <user> WITH REPLICATION;` using the `postgres` user.
</Admonition>
```sql
CREATE SUBSCRIPTION example_sub
CONNECTION 'host=db.oaguxblfdassqxvvwtfe.supabase.co user=postgres password=YOUR_PASS dbname=postgres'
PUBLICATION example_pub
WITH (copy_data = true, create_slot=false, slot_name=example_slot);
```
<Admonition type="note">
For projects running Postgres 17 or later, it is possible to subscribe to a [Read
Replica](/docs/guides/platform/read-replicas) by using your Read Replica's connection string.
</Admonition>
<Admonition type="note">
`create_slot` is set to `false` because `slot_name` is provided and the slot was already created in Step 2.
To copy data from before the slot was created, set `copy_data` to `true`.
</Admonition>
4. Back on the **Supabase database**, add all the tables that you want replicated to the publication:
```sql
ALTER PUBLICATION example_pub ADD TABLE example_table;
```
5. Check the replication status using `pg_stat_replication`
```sql
select * from pg_stat_replication;
```
<Admonition type="note">
You can add more tables to the initial publication, but you need to run a REFRESH on the subscribing database.
See [ALTER PUBLICATION](https://www.postgresql.org/docs/current/sql-alterpublication.html).
</Admonition>
## Next steps
To go further with replication, see these pages:
- [Read Replicas](/docs/guides/platform/read-replicas): subscribe to a Read Replica instead of the primary on Postgres 17 or later.
- [IPv4 add-on](/docs/guides/platform/ipv4-address): connect from a replication destination that doesn't support IPv6.