Re: [Logical Replication] TRAP: FailedAssertion("rel->rd_rel->relreplident == REPLICA_IDENTITY_DEFAULT || rel->rd_rel->relreplident == REPLICA_IDENTITY_FULL || rel->rd_rel->relreplident == REPLICA_IDENTITY_INDEX"

Michael Paquier <[email protected]> Fri, 10 Jan 2020 14:01:20 +0900
Newsgroups gmane.comp.db.postgresql.devel.general
Message-ID <[email protected]>
On Fri, Jan 10, 2020 at 07:30:34AM +0530, Dilip Kumar wrote:
> On Thu, 9 Jan 2020 at 10:43 PM, Andres Freund <[email protected]> wrote:
>> There's not much point in having this assert, right? Given that it
>> covers all choices? Seems better to just drop it.
>
> Yeah right!

Refreshing my mind on that...  The two remaining assertions still make
sense for update and delete changes per the restrictions in place in
CheckCmdReplicaIdentity(), and there is a gap with the regression
tests.  So combining all that I get the attached patch (origin point
is 665d1fa).  Thoughts? 
--
Michael
logirep-identity.patch (text/x-diff, 3.5 KB)
diff --git a/src/backend/replication/logical/proto.c b/src/backend/replication/logical/proto.c
index dcf7c08c18..3c6d0cd171 100644
--- a/src/backend/replication/logical/proto.c
+++ b/src/backend/replication/logical/proto.c
@@ -143,10 +143,6 @@ logicalrep_write_insert(StringInfo out, Relation rel, HeapTuple newtuple)
 {
 	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 */
 	pq_sendint32(out, RelationGetRelid(rel));
 
diff --git a/src/test/subscription/t/001_rep_changes.pl b/src/test/subscription/t/001_rep_changes.pl
index 77a1560b23..b9608d21f2 100644
--- a/src/test/subscription/t/001_rep_changes.pl
+++ b/src/test/subscription/t/001_rep_changes.pl
@@ -3,7 +3,7 @@ use strict;
 use warnings;
 use PostgresNode;
 use TestLib;
-use Test::More tests => 22;
+use Test::More tests => 23;
 
 # Initialize publisher node
 my $node_publisher = get_new_node('publisher');
@@ -34,6 +34,10 @@ $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))"
 );
+# 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
 $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_rep (a int primary key)");
+$node_subscriber->safe_psql('postgres', "CREATE TABLE tab_nothing (a int)");
 
 # different column count and order than on publisher
 $node_subscriber->safe_psql('postgres',
@@ -59,7 +64,7 @@ $node_publisher->safe_psql('postgres', "CREATE PUBLICATION tap_pub");
 $node_publisher->safe_psql('postgres',
 	"CREATE PUBLICATION tap_pub_ins_only WITH (publish = insert)");
 $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',
 	"ALTER PUBLICATION tap_pub_ins_only ADD TABLE tab_ins");
@@ -97,6 +102,9 @@ $node_publisher->safe_psql('postgres', "UPDATE tab_rep SET a = -a");
 $node_publisher->safe_psql('postgres',
 	"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',
 	"INSERT INTO tab_include SELECT generate_series(1,50)");
 $node_publisher->safe_psql('postgres',
@@ -117,6 +125,10 @@ $result = $node_subscriber->safe_psql('postgres', "SELECT * FROM tab_mixed");
 is( $result, qq(local|1.1|foo|1
 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',
 	"SELECT count(*), min(a), max(a) FROM tab_include");
 is($result, qq(20|-20|-1),
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAl4YBSAACgkQnvQgOdby
QH1BnQ//WUmViXRfOstfDNfOPoQtXIH033f5s8GTy3PGR0CxSbqzUUPG4XQU/7Yk
z952m9LBFcvoMlvqLgvrtzeZjb/7eVXnahuPShuEjmxwIrnPFikhvVbkS62XsQc1
34bDSRn1vreUzdE3dxGGpiBgNh3UlRM4ef466KYZJY4s446HMt6hME0ZNoIRuUwW
wDpA4PPQ4sx8n2X6kYofRquIYJx1nZBwfKRGfe9UhR6s3jH8mJlAriwvJT19cbGq
Cr0HONDP8yRQVb11AiHOaJ+mxivsI//QAjVFLiAhofSj2nXCrrk1bs2kXHX2OBXM
rhZF4G/jSoeU7D/Io3DkE68qgEAQ456K3/fSFaSL/+YtOqJRRPDKhzUN8vqvge2d
lx+PeuEKQVKzPM89JVR69UMarbcAY0TxQBlWJ4zVtt2dV3+y9YFw2b+UGXACtZfT
gugYmqYVg5hRD+Gmba9KllIK+VuC4tcDduK9WJ3xN0xjtPBcW/dV+Hli5G5Ig+Mm
mH8L0WE9pqhvK9I3kz07/mixVccMXtU6fZ6EVtcRRX0xYzey3ibcy6bUMQ+ADleP
zlIyzhive2ycEvytoSq3FBaT4GYa4Xgr0tmXrlqrAdsORNfHYz9m+5uQlHJCeqNO
2EDkq/a43ZJGB3ZRGfJBrxAKCH8TRc/WV8ONjRujZA5GRx4XAHQ=
=Qvd4
-----END PGP SIGNATURE-----