Re: Add a GUC variable that control logical replication

From: Craig Ringer <craig(at)2ndquadrant(dot)com>
To: Quan Zongliang <zongliang(dot)quan(at)postgresdata(dot)com>
Cc: Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Add a GUC variable that control logical replication
Date: 2019-11-10 09:20:24
Message-ID: CAMsr+YEAWHmJ_gezDQm6mFHeB_cdabEprXBBGj2ShvAGYyvweg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, 18 Sep 2019 at 16:39, Quan Zongliang <
zongliang(dot)quan(at)postgresdata(dot)com> wrote:

>
> Sybase has a feature to turn off replication at the session level: set
> replication = off, which can be temporarily turned off when there is a
> maintenance action on the table. Our users also want this feature.
> I add a new flag bit in xinfo, control it with a session-level variable,
> when set to true, this flag is written when the transaction is
> committed, and when the logic is decoded it abandons the transaction
> like aborted transactions. Since PostgreSQL has two types of
> replication, I call the variable "logical_replication" to avoid
> confusion and default value is true.
>

There's something related to this already. You can set the replication
origin for the transaction to the special value DoNotReplicateId
(replication origin id 65535). This will suppress replication of the
transaction, at least for output plugins that're aware of replication
origins.

This isn't presently exposed to SQL, it's there for the use of logical
replication extensions. It's possible to expose it with a pretty trivial C
function in an extension.

I think it's a bit of a hack TBH, it's something I perpetrated sometime in
the 9.4 series when we needed a way to suppress replication of individual
transactions. It originated out of core, so the original design was
constrained in how it worked, and maybe it would've actually made more
sense to use an xlinfo flag. Probably not worth changing now though.

Be extremely careful though. If you're hiding things from logical
replication you can get all sorts of confusing and exciting results. I very
strongly suggest you make anything like this superuser-only.

--
Craig Ringer http://www.2ndQuadrant.com/
2ndQuadrant - PostgreSQL Solutions for the Enterprise

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Craig Ringer 2019-11-10 09:35:36 Re: Allow superuser to grant passwordless connection rights on postgres_fdw
Previous Message Craig Ringer 2019-11-10 09:09:04 Re: tableam vs. TOAST