Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbc1adc6

Browse files
committed
Fix filtering of unsupported relations in logical replication
In the pgoutput plugin, skip changes for relations that are notpublishable, per is_publishable_class(). This concerns in particularmaterialized views and information_schema tables. While those relationscannot be part of a publication, per existing checks, they will beconsidered by a FOR ALL TABLES publication. A subscription would notactually apply changes for those relations, again per existing checks,but trying to match incoming changes to local tables on the subscriberwould lead to errors if no matching local table exists. Skipping thosechanges on the publisher avoids sending useless changes and eliminatesthe error.Bug: #15044Reported-by: Chad Trabant <chad@iris.washington.edu>Reviewed-by: Petr Jelinek <petr.jelinek@2ndquadrant.com>
1 parenteec1a8c commitbc1adc6

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-0
lines changed

‎src/backend/catalog/pg_publication.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,15 @@ is_publishable_class(Oid relid, Form_pg_class reltuple)
105105
relid >=FirstNormalObjectId;
106106
}
107107

108+
/*
109+
* Another variant of this, taking a Relation.
110+
*/
111+
bool
112+
is_publishable_relation(Relationrel)
113+
{
114+
returnis_publishable_class(RelationGetRelid(rel),rel->rd_rel);
115+
}
116+
108117

109118
/*
110119
* SQL-callable variant of the above

‎src/backend/replication/pgoutput/pgoutput.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,9 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
262262
MemoryContextold;
263263
RelationSyncEntry*relentry;
264264

265+
if (!is_publishable_relation(relation))
266+
return;
267+
265268
relentry=get_rel_sync_entry(data,RelationGetRelid(relation));
266269

267270
/* First check the table filter */

‎src/include/catalog/pg_publication.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ extern List *GetPublicationRelations(Oid pubid);
9393
externList*GetAllTablesPublications(void);
9494
externList*GetAllTablesPublicationRelations(void);
9595

96+
externboolis_publishable_relation(Relationrel);
9697
externObjectAddresspublication_add_relation(Oidpubid,Relationtargetrel,
9798
boolif_not_exists);
9899

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Test materialized views behavior
2+
use strict;
3+
use warnings;
4+
use PostgresNode;
5+
use TestLib;
6+
use Test::Moretests=> 1;
7+
8+
my$node_publisher = get_new_node('publisher');
9+
$node_publisher->init(allows_streaming=>'logical');
10+
$node_publisher->start;
11+
12+
my$node_subscriber = get_new_node('subscriber');
13+
$node_subscriber->init(allows_streaming=>'logical');
14+
$node_subscriber->start;
15+
16+
my$publisher_connstr =$node_publisher->connstr .' dbname=postgres';
17+
my$appname ='replication_test';
18+
19+
$node_publisher->safe_psql('postgres',
20+
"CREATE PUBLICATION mypub FOR ALL TABLES;");
21+
$node_subscriber->safe_psql('postgres',
22+
"CREATE SUBSCRIPTION mysub CONNECTION '$publisher_connstr application_name=$appname' PUBLICATION mypub;"
23+
);
24+
25+
$node_publisher->safe_psql('postgres',q{CREATE TABLE test1 (a int PRIMARY KEY, b text)});
26+
$node_publisher->safe_psql('postgres',q{INSERT INTO test1 (a, b) VALUES (1, 'one'), (2, 'two');});
27+
28+
$node_subscriber->safe_psql('postgres',q{CREATE TABLE test1 (a int PRIMARY KEY, b text);});
29+
30+
$node_publisher->wait_for_catchup($appname);
31+
32+
# Materialized views are not supported by logical replication, but
33+
# logical decoding does produce change information for them, so we
34+
# need to make sure they are properly ignored. (bug #15044)
35+
36+
# create a MV with some data
37+
$node_publisher->safe_psql('postgres',q{CREATE MATERIALIZED VIEW testmv1 AS SELECT * FROM test1;});
38+
$node_publisher->wait_for_catchup($appname);
39+
# There is no equivalent relation on the subscriber, but MV data is
40+
# not replicated, so this does not hang.
41+
42+
pass"materialized view data not replicated";
43+
44+
$node_subscriber->stop;
45+
$node_publisher->stop;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp