mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-08-23 20:57:32 +02:00
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
This commit is contained in:
parent
2e86e154da
commit
7eb6217db9
@ -143,10 +143,6 @@ logicalrep_write_insert(StringInfo out, Relation rel, HeapTuple newtuple)
|
|||||||
{
|
{
|
||||||
pq_sendbyte(out, 'I'); /* action INSERT */
|
pq_sendbyte(out, 'I'); /* action INSERT */
|
||||||
|
|
||||||
Assert(rel->rd_rel->relreplident == REPLICA_IDENTITY_DEFAULT ||
|
|
||||||
rel->rd_rel->relreplident == REPLICA_IDENTITY_FULL ||
|
|
||||||
rel->rd_rel->relreplident == REPLICA_IDENTITY_INDEX);
|
|
||||||
|
|
||||||
/* use Oid as relation identifier */
|
/* use Oid as relation identifier */
|
||||||
pq_sendint32(out, RelationGetRelid(rel));
|
pq_sendint32(out, RelationGetRelid(rel));
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ use strict;
|
|||||||
use warnings;
|
use warnings;
|
||||||
use PostgresNode;
|
use PostgresNode;
|
||||||
use TestLib;
|
use TestLib;
|
||||||
use Test::More tests => 22;
|
use Test::More tests => 23;
|
||||||
|
|
||||||
# Initialize publisher node
|
# Initialize publisher node
|
||||||
my $node_publisher = get_new_node('publisher');
|
my $node_publisher = get_new_node('publisher');
|
||||||
@ -34,6 +34,10 @@ $node_publisher->safe_psql('postgres',
|
|||||||
$node_publisher->safe_psql('postgres',
|
$node_publisher->safe_psql('postgres',
|
||||||
"CREATE TABLE tab_include (a int, b text, CONSTRAINT covering PRIMARY KEY(a) INCLUDE(b))"
|
"CREATE TABLE tab_include (a int, b text, CONSTRAINT covering PRIMARY KEY(a) INCLUDE(b))"
|
||||||
);
|
);
|
||||||
|
# Let this table with REPLICA IDENTITY NOTHING, allowing only INSERT changes.
|
||||||
|
$node_publisher->safe_psql('postgres', "CREATE TABLE tab_nothing (a int)");
|
||||||
|
$node_publisher->safe_psql('postgres',
|
||||||
|
"ALTER TABLE tab_nothing REPLICA IDENTITY NOTHING");
|
||||||
|
|
||||||
# Setup structure on subscriber
|
# Setup structure on subscriber
|
||||||
$node_subscriber->safe_psql('postgres', "CREATE TABLE tab_notrep (a int)");
|
$node_subscriber->safe_psql('postgres', "CREATE TABLE tab_notrep (a int)");
|
||||||
@ -42,6 +46,7 @@ $node_subscriber->safe_psql('postgres', "CREATE TABLE tab_full (a int)");
|
|||||||
$node_subscriber->safe_psql('postgres', "CREATE TABLE tab_full2 (x text)");
|
$node_subscriber->safe_psql('postgres', "CREATE TABLE tab_full2 (x text)");
|
||||||
$node_subscriber->safe_psql('postgres',
|
$node_subscriber->safe_psql('postgres',
|
||||||
"CREATE TABLE tab_rep (a int primary key)");
|
"CREATE TABLE tab_rep (a int primary key)");
|
||||||
|
$node_subscriber->safe_psql('postgres', "CREATE TABLE tab_nothing (a int)");
|
||||||
|
|
||||||
# different column count and order than on publisher
|
# different column count and order than on publisher
|
||||||
$node_subscriber->safe_psql('postgres',
|
$node_subscriber->safe_psql('postgres',
|
||||||
@ -59,7 +64,7 @@ $node_publisher->safe_psql('postgres', "CREATE PUBLICATION tap_pub");
|
|||||||
$node_publisher->safe_psql('postgres',
|
$node_publisher->safe_psql('postgres',
|
||||||
"CREATE PUBLICATION tap_pub_ins_only WITH (publish = insert)");
|
"CREATE PUBLICATION tap_pub_ins_only WITH (publish = insert)");
|
||||||
$node_publisher->safe_psql('postgres',
|
$node_publisher->safe_psql('postgres',
|
||||||
"ALTER PUBLICATION tap_pub ADD TABLE tab_rep, tab_full, tab_full2, tab_mixed, tab_include"
|
"ALTER PUBLICATION tap_pub ADD TABLE tab_rep, tab_full, tab_full2, tab_mixed, tab_include, tab_nothing"
|
||||||
);
|
);
|
||||||
$node_publisher->safe_psql('postgres',
|
$node_publisher->safe_psql('postgres',
|
||||||
"ALTER PUBLICATION tap_pub_ins_only ADD TABLE tab_ins");
|
"ALTER PUBLICATION tap_pub_ins_only ADD TABLE tab_ins");
|
||||||
@ -98,6 +103,9 @@ $node_publisher->safe_psql('postgres', "UPDATE tab_rep SET a = -a");
|
|||||||
$node_publisher->safe_psql('postgres',
|
$node_publisher->safe_psql('postgres',
|
||||||
"INSERT INTO tab_mixed VALUES (2, 'bar', 2.2)");
|
"INSERT INTO tab_mixed VALUES (2, 'bar', 2.2)");
|
||||||
|
|
||||||
|
$node_publisher->safe_psql('postgres',
|
||||||
|
"INSERT INTO tab_nothing VALUES (generate_series(1,20))");
|
||||||
|
|
||||||
$node_publisher->safe_psql('postgres',
|
$node_publisher->safe_psql('postgres',
|
||||||
"INSERT INTO tab_include SELECT generate_series(1,50)");
|
"INSERT INTO tab_include SELECT generate_series(1,50)");
|
||||||
$node_publisher->safe_psql('postgres',
|
$node_publisher->safe_psql('postgres',
|
||||||
@ -118,6 +126,10 @@ $result = $node_subscriber->safe_psql('postgres', "SELECT * FROM tab_mixed");
|
|||||||
is( $result, qq(local|1.1|foo|1
|
is( $result, qq(local|1.1|foo|1
|
||||||
local|2.2|bar|2), 'check replicated changes with different column order');
|
local|2.2|bar|2), 'check replicated changes with different column order');
|
||||||
|
|
||||||
|
$result =
|
||||||
|
$node_subscriber->safe_psql('postgres', "SELECT count(*) FROM tab_nothing");
|
||||||
|
is($result, qq(20), 'check replicated changes with REPLICA IDENTITY NOTHING');
|
||||||
|
|
||||||
$result = $node_subscriber->safe_psql('postgres',
|
$result = $node_subscriber->safe_psql('postgres',
|
||||||
"SELECT count(*), min(a), max(a) FROM tab_include");
|
"SELECT count(*), min(a), max(a) FROM tab_include");
|
||||||
is($result, qq(20|-20|-1),
|
is($result, qq(20|-20|-1),
|
||||||
|
Loading…
Reference in New Issue
Block a user