Files
supabase/apps/temp-docs/docs/reference/postgres/publications.mdx
2022-04-26 14:17:19 +02:00

210 lines
2.9 KiB
Plaintext

---
id: publications
title: "Publications"
slug: publications
custom_edit_url: https://github.com/supabase/supabase/edit/master/web/spec/postgres.yml
---
import Tabs from '@theme/Tabs';
import TabsPanel from '@theme/TabsPanel';
Publications are a way of grouping changes generated from a table or a group of tables.
These changes can then be sent to other systems (usually another Postgres database).
## Examples
### Create a Publication
This publication will contain all changes to all tables.
<Tabs
defaultActiveId="sql"
groupId="reference/postgres"
values={[{ label: 'SQL', value: 'sql' }]}>
<TabsPanel id="sql" label="sql">
```sql
create publication publication_name
for all tables;
```
</TabsPanel>
</Tabs>
### Create a Publication which listens to individual tables
<Tabs
defaultActiveId="sql"
groupId="reference/postgres"
values={[{ label: 'SQL', value: 'sql' }]}>
<TabsPanel id="sql" label="sql">
```sql
create publication publication_name
for table table_one, table_two;
```
</TabsPanel>
</Tabs>
### Add tables to an existing publication
<Tabs
defaultActiveId="sql"
groupId="reference/postgres"
values={[{ label: 'SQL', value: 'sql' }]}>
<TabsPanel id="sql" label="sql">
```sql
alter publication publication_name
add table table_name;
```
</TabsPanel>
</Tabs>
### Listens to inserts only
<Tabs
defaultActiveId="sql"
groupId="reference/postgres"
values={[{ label: 'SQL', value: 'sql' }]}>
<TabsPanel id="sql" label="sql">
```sql
create publication publication_name
for all tables
with (publish = 'insert');
```
</TabsPanel>
</Tabs>
### Listens to updates only
<Tabs
defaultActiveId="sql"
groupId="reference/postgres"
values={[{ label: 'SQL', value: 'sql' }]}>
<TabsPanel id="sql" label="sql">
```sql
create publication publication_name
for all tables
with (publish = 'update');
```
</TabsPanel>
</Tabs>
### Listens to deletions only
<Tabs
defaultActiveId="sql"
groupId="reference/postgres"
values={[{ label: 'SQL', value: 'sql' }]}>
<TabsPanel id="sql" label="sql">
```sql
create publication publication_name
for all tables
with (publish = 'delete');
```
</TabsPanel>
</Tabs>
### Remove a Publication
<Tabs
defaultActiveId="sql"
groupId="reference/postgres"
values={[{ label: 'SQL', value: 'sql' }]}>
<TabsPanel id="sql" label="sql">
```sql
drop publication if exists publication_name;
```
</TabsPanel>
</Tabs>
### Recreate a Publication
If you are planning to re-create a publication, it's best to do it in a transaction to ensure the operation succeeds.
<Tabs
defaultActiveId="sql"
groupId="reference/postgres"
values={[{ label: 'SQL', value: 'sql' }]}>
<TabsPanel id="sql" label="sql">
```sql
begin;
-- remove the realtime publication
drop publication if exists publication_name;
-- re-create the publication but don't enable it for any tables
create publication publication_name;
commit;
```
</TabsPanel>
</Tabs>