mirror of
https://github.com/postgres/postgres.git
synced 2025-11-25 12:03:53 +03:00
Introduce "REFRESH SEQUENCES" for subscriptions.
This patch adds support for a new SQL command: ALTER SUBSCRIPTION ... REFRESH SEQUENCES This command updates the sequence entries present in the pg_subscription_rel catalog table with the INIT state to trigger resynchronization. In addition to the new command, the following subscription commands have been enhanced to automatically refresh sequence mappings: ALTER SUBSCRIPTION ... REFRESH PUBLICATION ALTER SUBSCRIPTION ... ADD PUBLICATION ALTER SUBSCRIPTION ... DROP PUBLICATION ALTER SUBSCRIPTION ... SET PUBLICATION These commands will perform the following actions: Add newly published sequences that are not yet part of the subscription. Remove sequences that are no longer included in the publication. This ensures that sequence replication remains aligned with the current state of the publication on the publisher side. Note that the actual synchronization of sequence data/values will be handled in a subsequent patch that introduces a dedicated sequence sync worker. Author: Vignesh C <vignesh21@gmail.com> Reviewed-by: Amit Kapila <amit.kapila16@gmail.com> Reviewed-by: shveta malik <shveta.malik@gmail.com> Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com> Reviewed-by: Hayato Kuroda <kuroda.hayato@fujitsu.com> Reviewed-by: Dilip Kumar <dilipbalaut@gmail.com> Reviewed-by: Peter Smith <smithpb2250@gmail.com> Reviewed-by: Nisha Moond <nisha.moond412@gmail.com> Reviewed-by: Shlok Kyal <shlok.kyal.oss@gmail.com> Reviewed-by: Chao Li <li.evan.chao@gmail.com> Reviewed-by: Hou Zhijie <houzj.fnst@fujitsu.com> Discussion: https://postgr.es/m/CAA4eK1LC+KJiAkSrpE_NwvNdidw9F2os7GERUeSxSKv71gXysQ@mail.gmail.com
This commit is contained in:
@@ -45,6 +45,7 @@ tests += {
|
||||
't/033_run_as_table_owner.pl',
|
||||
't/034_temporal.pl',
|
||||
't/035_conflicts.pl',
|
||||
't/036_sequences.pl',
|
||||
't/100_bugs.pl',
|
||||
],
|
||||
},
|
||||
|
||||
55
src/test/subscription/t/036_sequences.pl
Normal file
55
src/test/subscription/t/036_sequences.pl
Normal file
@@ -0,0 +1,55 @@
|
||||
|
||||
# Copyright (c) 2025, PostgreSQL Global Development Group
|
||||
|
||||
# This tests that sequences are registered to be synced to the subscriber
|
||||
use strict;
|
||||
use warnings;
|
||||
use PostgreSQL::Test::Cluster;
|
||||
use PostgreSQL::Test::Utils;
|
||||
use Test::More;
|
||||
|
||||
# Initialize publisher node
|
||||
my $node_publisher = PostgreSQL::Test::Cluster->new('publisher');
|
||||
|
||||
# Avoid checkpoint during the test, otherwise, extra values will be fetched for
|
||||
# the sequences which will cause the test to fail randomly.
|
||||
$node_publisher->init(allows_streaming => 'logical');
|
||||
$node_publisher->start;
|
||||
|
||||
# Initialize subscriber node
|
||||
my $node_subscriber = PostgreSQL::Test::Cluster->new('subscriber');
|
||||
$node_subscriber->init;
|
||||
$node_subscriber->start;
|
||||
|
||||
# Setup structure on the publisher
|
||||
my $ddl = qq(
|
||||
CREATE TABLE regress_seq_test (v BIGINT);
|
||||
CREATE SEQUENCE regress_s1;
|
||||
);
|
||||
$node_publisher->safe_psql('postgres', $ddl);
|
||||
|
||||
# Setup the same structure on the subscriber
|
||||
$node_subscriber->safe_psql('postgres', $ddl);
|
||||
|
||||
# Insert initial test data
|
||||
$node_publisher->safe_psql(
|
||||
'postgres', qq(
|
||||
-- generate a number of values using the sequence
|
||||
INSERT INTO regress_seq_test SELECT nextval('regress_s1') FROM generate_series(1,100);
|
||||
));
|
||||
|
||||
# Setup logical replication pub/sub
|
||||
my $publisher_connstr = $node_publisher->connstr . ' dbname=postgres';
|
||||
$node_publisher->safe_psql('postgres',
|
||||
"CREATE PUBLICATION regress_seq_pub FOR ALL SEQUENCES");
|
||||
$node_subscriber->safe_psql('postgres',
|
||||
"CREATE SUBSCRIPTION regress_seq_sub CONNECTION '$publisher_connstr' PUBLICATION regress_seq_pub"
|
||||
);
|
||||
|
||||
# Confirm sequences can be listed in pg_subscription_rel
|
||||
my $result = $node_subscriber->safe_psql('postgres',
|
||||
"SELECT relname, srsubstate FROM pg_class, pg_subscription_rel WHERE oid = srrelid"
|
||||
);
|
||||
is($result, 'regress_s1|i', "Sequence can be in pg_subscription_rel catalog");
|
||||
|
||||
done_testing();
|
||||
Reference in New Issue
Block a user