How to create logical replication slot with NOEXPORT_SNAPSHOT in jdbc - Mailing list pgsql-general

From Igor Polishchuk
Subject How to create logical replication slot with NOEXPORT_SNAPSHOT in jdbc
Date
Msg-id CAEcs1Y6EWC7AAULU5nHYsfkHUsXppMDrTszp1ho60f9WDnopcQ@mail.gmail.com
Whole thread Raw
Responses Re: How to create logical replication slot with NOEXPORT_SNAPSHOT injdbc  (Peter Eisentraut <peter.eisentraut@2ndquadrant.com>)
List pgsql-general

Hello Everybody.
We are trying to use logical decoding for detecting database changes.
However, when we create a replication slot, the data processing pauses if there are still transactions running from before the slot creation. If I understand correctly, the slot is waiting for creating a consistent snapshot and is blocked by the long transactions.
In our application, we don't need it, as we only want to see if some tables were modified. Is it possible to create a  logical replication slot with  NOEXPORT_SNAPSHOT option using jdbc?
This is a feature of  feature of the Streaming Replication Protocol described in https://www.postgresql.org/docs/current/static/logicaldecoding-explanation.html#id-1.8.14.8.5

It is just not clear how to pass this option. We are using Postgres 10.4, jbc

This is a groovy method for creating the replication slot:

    @CompileStatic(TypeCheckingMode.SKIP)
    private void createReplicationSlot( PGConnection replConnection) {

        def slotName = getSlotName()
        Sql sql = new Sql(dataSource)

        def exists = sql.firstRow("select * from pg_replication_slots where slot_name = '${slotName}'".toString())

        if (exists)
            log.info "replication slot ${slotName} detected and ${exists?.active ? 'active' : 'not active'}"
        else
            log.info "replication slot ${slotName} not detected"

        if (!exists) {
            replConnection.getReplicationAPI()
                    .createReplicationSlot()
                    .logical()
                    .withSlotName(slotName)
                    .withOutputPlugin("wal2json")
                    .make();

            log.info "created replication slot ${slotName}"
        }



--
Thanks
Igor Polishchuk

pgsql-general by date:

Previous
From: Christopher Browne
Date:
Subject: Re: User documentation vs Official Docs
Next
From: "Jonathan S. Katz"
Date:
Subject: Re: User documentation vs Official Docs