Skip to content

Commit bb385c4

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 1cebfde commit bb385c4

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
@@ -5156,6 +5156,13 @@ GetRelationPublicationActions(Relation relation)
51565156
MemoryContext oldcxt;
51575157
PublicationActions *pubactions = palloc0(sizeof(PublicationActions));
51585158

5159+
/*
5160+
* If not publishable, it publishes no actions. (pgoutput_change() will
5161+
* ignore it.)
5162+
*/
5163+
if (!is_publishable_relation(relation))
5164+
return pubactions;
5165+
51595166
if (relation->rd_pubactions)
51605167
return memcpy(pubactions, relation->rd_pubactions,
51615168
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
# Bug #15114
99

@@ -63,3 +63,38 @@
6363
$node_publisher->wait_for_catchup('sub1');
6464

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy