Re: logical decoding and replication of sequences, take 2
Tomas Vondra <tomas.vondra@enterprisedb.com>
From: Tomas Vondra <tomas.vondra@enterprisedb.com>
To: Masahiko Sawada <sawada.mshk@gmail.com>,
Amit Kapila <amit.kapila16@gmail.com>
Cc: John Naylor <john.naylor@enterprisedb.com>,
vignesh C <vignesh21@gmail.com>, Andres Freund <andres@anarazel.de>,
Robert Haas <robertmhaas@gmail.com>,
PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>,
Heikki Linnakangas <heikki.linnakangas@iki.fi>
Date: 2023-04-02T17:46:57Z
Lists: pgsql-hackers
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Migrate logical slots to the new node during an upgrade.
- 29d0a77fa660 17.0 cited
-
Make test_decoding ddl.out shorter
- d6677b93c79b 17.0 landed
- c5c5832600e9 14.9 landed
- b1dc946eee3d 16.0 landed
- 3bb8b9342f8a 15.4 landed
-
Fix snapshot handling in logicalmsg_decode
- 949ac32e1267 15.3 landed
- 8b9cbd42b61f 14.8 landed
- 4df581fa0f4b 13.11 landed
- 497f863f0598 12.15 landed
- 8de91ebf2ac1 11.20 landed
- 7fe1aa991b62 16.0 landed
-
doc: Adjust a few more references to "postmaster"
- 17e72ec45d31 16.0 cited
-
Revert "Logical decoding of sequences"
- 2c7ea57e56ca 15.0 cited
Attachments
- 0001-Logical-decoding-of-sequences-20230402.patch (text/x-patch) patch 0001
- 0002-Add-decoding-of-sequences-to-test_decoding-20230402.patch (text/x-patch) patch 0002
- 0003-Add-decoding-of-sequences-to-built-in-repli-20230402.patch (text/x-patch) patch 0003
- 0004-add-interlock-with-ALTER-SEQUENCE-20230402.patch (text/x-patch) patch 0004
- 0005-Support-LOCK-for-sequences-instead-of-funct-20230402.patch (text/x-patch) patch 0005
- 0006-Reconstruct-the-right-state-from-the-on-dis-20230402.patch (text/x-patch) patch 0006
- 0007-protocol-changes-20230402.patch (text/x-patch) patch 0007
On 3/30/23 05:15, Masahiko Sawada wrote: > > ... > >>> >>> Perhaps it'd be reasonable to tie the "protocol version" to subscriber >>> capabilities, so that a protocol version guarantees what message types >>> the subscriber understands. So we could increment the protocol version, >>> check it in pgoutput_startup and then error-out in the sequence callback >>> if the subscriber version is too old. >>> >>> That'd be nicer in the sense that we'd generate nicer error message on >>> the publisher, not an "unknown message type" on the subscriber. >>> >> >> Agreed. So, we can probably formalize this rule such that whenever in >> a newer version publisher we want to send additional information which >> the old version subscriber won't be able to handle, the error should >> be raised at the publisher by using protocol version number. > > +1 > OK, I took a stab at this, see the attached 0007 patch which bumps the protocol version, and allows the subscriber to specify "sequences" when starting the replication, similar to what we do for the two-phase stuff. The patch essentially adds 'sequences' to the replication start command, depending on the server version, but it can be overridden by "sequences" subscription option. The patch is pretty small, but I wonder how much smarter this should be ... I think there are about 4 cases that we need to consider 1) there are no sequences in the publication -> OK 2) publication with sequences, subscriber knows how to apply (and specifies "sequences on" either automatically or explicitly) -> OK 3) publication with sequences, subscriber explicitly disabled them by specifying "sequences off" in startup -> OK 4) publication with sequences, subscriber without sequence support (e.g. older Postgres release) -> PROBLEM (?) The reason why I think (4) may be a problem is that my opinion is we shouldn't silently drop stuff that is meant to be part of the publication. That is, if someone creates a publication and adds a sequence to it, he wants to replicate the sequence. But the current behavior is the old subscriber connects, doesn't specify the 'sequences on' so the publisher disables that and then simply ignores sequence increments during decoding. I think we might want to detect this and error out instead of just skipping the change, but that needs to happen later, only when the publication actually has any sequences ... I don't want to over-think / over-engineer this, though, so I wonder what are your opinions on this? There's a couple XXX comments in the code, mostly about stuff I left out when copying the two-phase stuff. For example, we store two-phase stuff in the replication slot itself - I don't think we need to do that for sequences, though. Another thing what to do about ALTER SUBSCRIPTION - at the moment it's not possible to change the "sequences" option, but maybe we should allow that? But then we'd need to re-sync all the sequences, somehow ... Aside from that, I've also added 0005, which does the sync interlock in a slightly different way - instead of a custom function for locking sequence, it allows LOCK on sequences. Peter Eisentraut suggested doing it like this, it's simpler, and I can't see what issues it might cause. The patch should update LOCK documentation, I haven't done that yet. Ultimately it should all be merged into 0003, of course. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company