--- 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. ```sql create publication publication_name for all tables; ``` ### Create a Publication which listens to individual tables ```sql create publication publication_name for table table_one, table_two; ``` ### Add tables to an existing publication ```sql alter publication publication_name add table table_name; ``` ### Listens to inserts only ```sql create publication publication_name for all tables with (publish = 'insert'); ``` ### Listens to updates only ```sql create publication publication_name for all tables with (publish = 'update'); ``` ### Listens to deletions only ```sql create publication publication_name for all tables with (publish = 'delete'); ``` ### Remove a Publication ```sql 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. ```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; ```