Skip to content

Commit 05d151e

Browse files
committed
Fix handling of temp and unlogged tables in FOR ALL TABLES publications
If a FOR ALL TABLES publication exists, temporary and unlogged tables are ignored for publishing changes. But CheckCmdReplicaIdentity() would still check in that case that such a table has a replica identity set before accepting updates. To fix, have GetRelationPublicationActions() return that such a table publishes no actions. Discussion: https://www.postgresql.org/message-id/f3f151f7-c4dd-1646-b998-f60bd6217dd3@2ndquadrant.com
1 parent fea2cab commit 05d151e

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

src/backend/utils/cache/relcache.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5236,6 +5236,13 @@ GetRelationPublicationActions(Relation relation)
52365236
MemoryContext oldcxt;
52375237
PublicationActions *pubactions = palloc0(sizeof(PublicationActions));
52385238

5239+
/*
5240+
* If not publishable, it publishes no actions. (pgoutput_change() will
5241+
* ignore it.)
5242+
*/
5243+
if (!is_publishable_relation(relation))
5244+
return pubactions;
5245+
52395246
if (relation->rd_pubactions)
52405247
return memcpy(pubactions, relation->rd_pubactions,
52415248
sizeof(PublicationActions));

src/test/subscription/t/100_bugs.pl

Lines changed: 36 additions & 1 deletion
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 => 1;
6+
use Test::More tests => 3;
77

88
sub wait_for_caught_up
99
{
@@ -72,3 +72,38 @@ sub wait_for_caught_up
7272
wait_for_caught_up($node_publisher, 'sub1');
7373

7474
pass('index predicates do not cause crash');
75+
76+
$node_publisher->stop('fast');
77+
$node_subscriber->stop('fast');
78+
79+
80+
# Handling of temporary and unlogged tables with FOR ALL TABLES publications
81+
82+
# If a FOR ALL TABLES publication exists, temporary and unlogged
83+
# tables are ignored for publishing changes. The bug was that we
84+
# would still check in that case that such a table has a replica
85+
# identity set before accepting updates. If it did not it would cause
86+
# an error when an update was attempted.
87+
88+
$node_publisher = get_new_node('publisher2');
89+
$node_publisher->init(allows_streaming => 'logical');
90+
$node_publisher->start;
91+
92+
$node_publisher->safe_psql('postgres',
93+
"CREATE PUBLICATION pub FOR ALL TABLES");
94+
95+
is( $node_publisher->psql(
96+
'postgres',
97+
"CREATE TEMPORARY TABLE tt1 AS SELECT 1 AS a; UPDATE tt1 SET a = 2;"),
98+
0,
99+
'update to temporary table without replica identity with FOR ALL TABLES publication'
100+
);
101+
102+
is( $node_publisher->psql(
103+
'postgres',
104+
"CREATE UNLOGGED TABLE tu1 AS SELECT 1 AS a; UPDATE tu1 SET a = 2;"),
105+
0,
106+
'update to unlogged table without replica identity with FOR ALL TABLES publication'
107+
);
108+
109+
$node_publisher->stop('fast');

0 commit comments

Comments
 (0)