From f993344ccc0f37363de1d4cb4050a3ee481d9e55 Mon Sep 17 00:00:00 2001 From: Shlok Kyal Date: Thu, 20 Jun 2024 17:42:45 +0530 Subject: [PATCH v9 3/3] Fix tablesync behaviour for Virtual Generated columns Currently during tablesync Virtual generated columns are also replicated. We are not supporting replication of virtual generated columns for now. This patch fix the behaviour of tablesync. --- doc/src/sgml/ref/create_subscription.sgml | 3 ++- src/backend/replication/logical/tablesync.c | 14 +++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/doc/src/sgml/ref/create_subscription.sgml b/doc/src/sgml/ref/create_subscription.sgml index b62c0ca931..5666931355 100644 --- a/doc/src/sgml/ref/create_subscription.sgml +++ b/doc/src/sgml/ref/create_subscription.sgml @@ -441,7 +441,8 @@ CREATE SUBSCRIPTION subscription_name If the subscriber-side column is also a generated column then this option has no effect; the subscriber column will be filled as normal with the - subscriber-side computed or default data. + subscriber-side computed or default data. This option allows replication + of only STORED GENERATED COLUMNS. diff --git a/src/backend/replication/logical/tablesync.c b/src/backend/replication/logical/tablesync.c index 0fbf661ab0..f6644c5199 100644 --- a/src/backend/replication/logical/tablesync.c +++ b/src/backend/replication/logical/tablesync.c @@ -997,10 +997,18 @@ fetch_remote_table_info(char *nspname, char *relname, bool **attgenlist, " WHERE a.attnum > 0::pg_catalog.int2" " AND NOT a.attisdropped", lrel->remoteid); - if ((walrcv_server_version(LogRepWorkerWalRcvConn) >= 120000 && - walrcv_server_version(LogRepWorkerWalRcvConn) <= 160000) || - !MySubscription->includegencols) + if (walrcv_server_version(LogRepWorkerWalRcvConn) < 170000) + { + if (walrcv_server_version(LogRepWorkerWalRcvConn) >= 120000) appendStringInfo(&cmd, " AND a.attgenerated = ''"); + } + else if (walrcv_server_version(LogRepWorkerWalRcvConn) >= 170000) + { + if(MySubscription->includegencols) + appendStringInfo(&cmd, " AND a.attgenerated != 'v'"); + else + appendStringInfo(&cmd, " AND a.attgenerated = ''"); + } appendStringInfo(&cmd, " AND a.attrelid = %u" -- 2.34.1