Skip to content

Commit 30104ec

Browse files
committed
Remove incorrect assertion for INSERT in logical replication's publisher
On the publisher, it was assumed that an INSERT change cannot happen for a relation with no replica identity. However this is true only for a change that needs references to old rows, aka UPDATE or DELETE, so trying to use logical replication with a relation that has no replica identity led to an assertion failure in the publisher when issuing an INSERT. This commit removes the incorrect assertion, and adds more regression tests to provide coverage for relations without replica identity. Reported-by: Neha Sharma Author: Dilip Kumar, Michael Paquier Reviewed-by: Andres Freund Discussion: https://postgr.es/m/CANiYTQsL1Hb8_Km08qd32svrqNumXLJeoGo014O7VZymgOhZEA@mail.gmail.com Backpatch-through: 10
1 parent cb97742 commit 30104ec

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/backend/replication/logical/proto.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,6 @@ logicalrep_write_insert(StringInfo out, Relation rel, HeapTuple newtuple)
140140
{
141141
pq_sendbyte(out, 'I'); /* action INSERT */
142142

143-
Assert(rel->rd_rel->relreplident == REPLICA_IDENTITY_DEFAULT ||
144-
rel->rd_rel->relreplident == REPLICA_IDENTITY_FULL ||
145-
rel->rd_rel->relreplident == REPLICA_IDENTITY_INDEX);
146-
147143
/* use Oid as relation identifier */
148144
pq_sendint(out, RelationGetRelid(rel), 4);
149145

src/test/subscription/t/001_rep_changes.pl

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use warnings;
44
use PostgresNode;
55
use TestLib;
6-
use Test::More tests => 21;
6+
use Test::More tests => 22;
77

88
# Initialize publisher node
99
my $node_publisher = get_new_node('publisher');
@@ -31,6 +31,10 @@
3131
"CREATE TABLE tab_mixed (a int primary key, b text, c numeric)");
3232
$node_publisher->safe_psql('postgres',
3333
"INSERT INTO tab_mixed (a, b, c) VALUES (1, 'foo', 1.1)");
34+
# Let this table with REPLICA IDENTITY NOTHING, allowing only INSERT changes.
35+
$node_publisher->safe_psql('postgres', "CREATE TABLE tab_nothing (a int)");
36+
$node_publisher->safe_psql('postgres',
37+
"ALTER TABLE tab_nothing REPLICA IDENTITY NOTHING");
3438

3539
# Setup structure on subscriber
3640
$node_subscriber->safe_psql('postgres', "CREATE TABLE tab_notrep (a int)");
@@ -39,6 +43,7 @@
3943
$node_subscriber->safe_psql('postgres', "CREATE TABLE tab_full2 (x text)");
4044
$node_subscriber->safe_psql('postgres',
4145
"CREATE TABLE tab_rep (a int primary key)");
46+
$node_subscriber->safe_psql('postgres', "CREATE TABLE tab_nothing (a int)");
4247

4348
# different column count and order than on publisher
4449
$node_subscriber->safe_psql('postgres',
@@ -51,7 +56,7 @@
5156
$node_publisher->safe_psql('postgres',
5257
"CREATE PUBLICATION tap_pub_ins_only WITH (publish = insert)");
5358
$node_publisher->safe_psql('postgres',
54-
"ALTER PUBLICATION tap_pub ADD TABLE tab_rep, tab_full, tab_full2, tab_mixed"
59+
"ALTER PUBLICATION tap_pub ADD TABLE tab_rep, tab_full, tab_full2, tab_mixed, tab_nothing"
5560
);
5661
$node_publisher->safe_psql('postgres',
5762
"ALTER PUBLICATION tap_pub_ins_only ADD TABLE tab_ins");
@@ -94,6 +99,9 @@
9499
$node_publisher->safe_psql('postgres',
95100
"INSERT INTO tab_mixed VALUES (2, 'bar', 2.2)");
96101

102+
$node_publisher->safe_psql('postgres',
103+
"INSERT INTO tab_nothing VALUES (generate_series(1,20))");
104+
97105
$node_publisher->poll_query_until('postgres', $caughtup_query)
98106
or die "Timed out while waiting for subscriber to catch up";
99107

@@ -109,6 +117,10 @@
109117
is( $result, qq(local|1.1|foo|1
110118
local|2.2|bar|2), 'check replicated changes with different column order');
111119

120+
$result =
121+
$node_subscriber->safe_psql('postgres', "SELECT count(*) FROM tab_nothing");
122+
is($result, qq(20), 'check replicated changes with REPLICA IDENTITY NOTHING');
123+
112124
# insert some duplicate rows
113125
$node_publisher->safe_psql('postgres',
114126
"INSERT INTO tab_full SELECT generate_series(1,10)");

0 commit comments

Comments
 (0)