Re: logical decoding and replication of sequences, take 2
Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
From: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
To: Tomas Vondra <tomas.vondra@enterprisedb.com>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>, Masahiko Sawada <sawada.mshk@gmail.com>,
Amit Kapila <amit.kapila16@gmail.com>, Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Date: 2023-06-13T13:34:05Z
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
- 0005-add-interlock-with-ALTER-SEQUENCE-20230613.patch (text/x-patch) patch 0005
- 0001-Logical-decoding-of-sequences-20230613.patch (text/x-patch) patch 0001
- 0003-Add-decoding-of-sequences-to-test_decoding-20230613.patch (text/x-patch) patch 0003
- 0004-Add-decoding-of-sequences-to-built-in-repli-20230613.patch (text/x-patch) patch 0004
- 0002-make-test_decoding-ddl.out-shorter-20230613.patch (text/x-patch) patch 0002
- 0007-Reconstruct-the-right-state-from-the-on-dis-20230613.patch (text/x-patch) patch 0007
- 0008-protocol-changes-20230613.patch (text/x-patch) patch 0008
- 0006-Support-LOCK-for-sequences-instead-of-funct-20230613.patch (text/x-patch) patch 0006
Patch set needs a rebase, PFA rebased patch-set. The conflict was in commit "Add decoding of sequences to built-in replication", in files tablesync.c and 002_pg_dump.pl. On Thu, May 18, 2023 at 7:53 PM Ashutosh Bapat <ashutosh.bapat.oss@gmail.com> wrote: > > Hi, > Sorry for jumping late in this thread. > > I started experimenting with the functionality. Maybe something that > was already discussed earlier. Given that the thread is being > discussed for so long and has gone several changes, revalidating the > functionality is useful. > > I considered following aspects: > Changes to the sequence on subscriber > ----------------------------------------------------- > 1. Since this is logical decoding, logical replica is writable. So the > logically replicated sequence can be manipulated on the subscriber as > well. This implementation consolidates the changes on subscriber and > publisher rather than replicating the publisher state as is. That's > good. See example command sequence below > a. publisher calls nextval() - this sets the sequence state on > publisher as (1, 32, t) which is replicated to the subscriber. > b. subscriber calls nextval() once - this sets the sequence state on > subscriber as (34, 32, t) > c. subscriber calls nextval() 32 times - on-disk state of sequence > doesn't change on subscriber > d. subscriber calls nextval() 33 times - this sets the sequence state > on subscriber as (99, 0, t) > e. publisher calls nextval() 32 times - this sets the sequence state > on publisher as (33, 0, t) > > The on-disk state on publisher at the end of e. is replicated to the > subscriber but subscriber doesn't apply it. The state there is still > (99, 0, t). I think this is closer to how logical replication of > sequence should look like. This is aso good enough as long as we > expect the replication of sequences to be used for failover and > switchover. > > But it might not help if we want to consolidate the INSERTs that use > nextvals(). If we were to treat sequences as accumulating the > increments, we might be able to resolve the conflicts by adjusting the > columns values considering the increments made on subscriber. IIUC, > conflict resolution is not part of built-in logical replication. So we > may not want to go this route. But worth considering. > > Implementation agnostic decoded change > -------------------------------------------------------- > Current method of decoding and replicating the sequences is tied to > the implementation - it replicates the sequence row as is. If the > implementation changes in future, we might need to revise the decoded > presentation of sequence. I think only nextval() matters for sequence. > So as long as we are replicating information enough to calculate the > nextval we should be good. Current implementation does that by > replicating the log_value and is_called. is_called can be consolidated > into log_value itself. The implemented protocol, thus requires two > extra values to be replicated. Those can be ignored right now. But > they might pose a problem in future, if some downstream starts using > them. We will be forced to provide fake but sane values even if a > future upstream implementation does not produce those values. Of > course we can't predict the future implementation enough to decide > what would be an implementation independent format. E.g. if a > pluggable storage were to be used to implement sequences or if we come > around implementing distributed sequences, their shape can't be > predicted right now. So a change in protocol seems to be unavoidable > whatever we do. But starting with bare minimum might save us from > larger troubles. I think, it's better to just replicate the nextval() > and craft the representation on subscriber so that it produces that > nextval(). > > 3. Primary key sequences > ----------------------------------- > I am not experimented with this. But I think we will need to add the > sequences associated with the primary keys to the publications > publishing the owner tables. Otherwise, we will have problems with the > failover. And it needs to be done automatically since a. the names of > these sequences are generated automatically b. publications with FOR > ALL TABLES will add tables automatically and start replicating the > changes. Users may not be able to intercept the replication activity > to add the associated sequences are also addedto the publication. > > -- > Best Wishes, > Ashutosh Bapat -- Best Wishes, Ashutosh Bapat