Publications

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.

create publication publication_name
for all tables;

Create a Publication which listens to individual tables

create publication publication_name
for table table_one, table_two;

Add tables to an existing publication

alter publication publication_name
add table table_name;

Listens to inserts only

create publication publication_name
for all tables
with (publish = 'insert');

Listens to updates only

create publication publication_name
for all tables
with (publish = 'update');

Listens to deletions only

create publication publication_name
for all tables
with (publish = 'delete');

Remove a Publication

drop publication if exists publication_name;

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.

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;