Hello! I've found a simple problem in one of subscription tests (`src/test/subscription/t/009_matviews.pl`). When running this test, it completes successfully (All tests successful. Result: PASS) but there is an error in subscriber's logs: ``` logical replication apply worker[1865731] ERROR: logical replication target relation "public.test1" does not exist ```
How do I run the test: ``` # configure ./configure --enable-debug --enable-cassert --enable-tap-tests --with-icu --prefix=$PG_PREFIX # make ... cd src/test/subscription make installcheck PG_TEST_INITDB_EXTRA_OPTS="--locale=C" PROVE_TESTS="t/ 009_matviews.pl" ``` The main purpose of this test is to check materialized views behavior, which are not supported by logical replication, but logical decoding does produce change information for them, so we need to make sure they are properly ignored. The problem I found is about incorrect setup for logical replication: publisher performs INSERT to a table that has not yet been created on subscriber, and this causes an error `target relation does not exist`. According to docs: https://www.postgresql.org/docs/17/logical-replication-subscription.html : > The schema definitions are not replicated, and the published tables must exist on the subscriber. Only regular tables may be the target of replication. For example, you can't replicate to a view. Also, the sequence of actions in subscription test does not match the correct example in documentation ( https://www.postgresql.org/docs/17/logical-replication-subscription.html#LOGICAL-REPLICATION-SUBSCRIPTION-EXAMPLES ). Therefore, I would like to propose a patch with trivial fix for logical replication in subscription test `t/009_matviews.pl`. The patch is in attachments to this letter. The patch was created via: `git format-patch master --base master`.
From 9424ff98cece61fcacd47bc9b9cb0dccd523e518 Mon Sep 17 00:00:00 2001 From: GremSnoort <[email protected]> Date: Thu, 9 Oct 2025 15:28:20 +0300 Subject: [PATCH] Fix logical replication setup in subscription test t/009_matviews.pl --- src/test/subscription/t/009_matviews.pl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/test/subscription/t/009_matviews.pl b/src/test/subscription/t/009_matviews.pl index 9316fd1bb6d..2389680af13 100644 --- a/src/test/subscription/t/009_matviews.pl +++ b/src/test/subscription/t/009_matviews.pl @@ -18,20 +18,20 @@ $node_subscriber->start; my $publisher_connstr = $node_publisher->connstr . ' dbname=postgres'; +$node_publisher->safe_psql('postgres', + q{CREATE TABLE test1 (a int PRIMARY KEY, b text)}); +$node_subscriber->safe_psql('postgres', + q{CREATE TABLE test1 (a int PRIMARY KEY, b text);}); + $node_publisher->safe_psql('postgres', "CREATE PUBLICATION mypub FOR ALL TABLES;"); $node_subscriber->safe_psql('postgres', "CREATE SUBSCRIPTION mysub CONNECTION '$publisher_connstr' PUBLICATION mypub;" ); -$node_publisher->safe_psql('postgres', - q{CREATE TABLE test1 (a int PRIMARY KEY, b text)}); $node_publisher->safe_psql('postgres', q{INSERT INTO test1 (a, b) VALUES (1, 'one'), (2, 'two');}); -$node_subscriber->safe_psql('postgres', - q{CREATE TABLE test1 (a int PRIMARY KEY, b text);}); - $node_publisher->wait_for_catchup('mysub'); # Materialized views are not supported by logical replication, but base-commit: 36fd8bde1b77191eaf7d3499052c0636b6b93a87 -- 2.43.0
