Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12141

Is it possible to create publication and replication slot in the same transaction?

$
0
0

I try to create PostgreSQL replication slot by the next command:

DO $$BEGINIF NOT EXISTS (SELECT 1 FROM pg_catalog.pg_publication WHERE pubname = 'trade_events_pub') THEN    CREATE PUBLICATION trade_events_pub FOR TABLE         public.trade_events;END IF;IF NOT EXISTS (SELECT 1 from pg_catalog.pg_replication_slots WHERE slot_name = 'trade_events_slot') THEN    PERFORM pg_create_logical_replication_slot('trade_events_slot', 'pgoutput');END IF;END;$$ LANGUAGE plpgsql;

I get the error:

[25001] ERROR: cannot create logical replication slot in transaction that has performed writes Where: SQL statement "SELECT pg_create_logical_replication_slot('trade_events_slot', 'pgoutput')" PL/pgSQL function inline_code_block line 15 at PERFORM

If I try to run command CREATE PUBLICATION and PERFORM pg_create_logical_replication_slot in separate transactions it works fine.

I use PostgreSQL 15.3


Viewing all articles
Browse latest Browse all 12141

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>