Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mNK6K-00019N-Pa for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Sep 2021 19:16:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mNK6J-0005Vv-Nw for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Sep 2021 19:16:15 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mNK6I-0005Vn-P8 for pgsql-hackers@lists.postgresql.org; Mon, 06 Sep 2021 19:16:15 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mNK6F-0006GM-8H for pgsql-hackers@postgresql.org; Mon, 06 Sep 2021 19:16:14 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 9EE605C01CE; Mon, 6 Sep 2021 15:16:07 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Mon, 06 Sep 2021 15:16:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=XD5o3UcD2SZDwU5SyhU5ffmcQ5YSwTUXHHNosN/0+L0=; b=nqDkCm7u KSLcpYRjArt1mQp4IPvFqO91kI3mqdGkhqihYtXWeYT1s4BvUDL4jyS7rLnNwpDf VjSaDcWSDUMVvrMG0UPxa390BBdPutqheJ3KfX7ysQx1vUByX1Q1rV6q+rU87lnh d00ae9jmc4kNEezz5T9Nmq5BqoqtqEHCXW53NeVa6ALQmOGeRwMImzwOzYYU4YNF KwJUhGkE3QUWRucjM4xP3AfD2yUC2pMBtPLlF/SPqpYg0luqXrffmBrrotnHOGQk 8t2k9gtB8GsQsO4S9P/ZhmxSkE9MlB1euC+y2NOtvtzFZc38wnVdzBpMaCU9c8fh P6+Kelfbr972pQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrudeffedgudefhecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvuffkgggtugfgjgesthekredttddtjeenucfhrhhomheptehlvhgr rhhoucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgh eqnecuggftrfgrthhtvghrnhepudejveejffejveduudetvdekieeuiedtvdeileefkeev jedufeeguedvjefhueelnecuffhomhgrihhnpegvnhhtvghrphhrihhsvggusgdrtghomh enucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrlhhv hhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhg X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 6 Sep 2021 15:16:06 -0400 (EDT) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 558982A0781; Mon, 6 Sep 2021 16:16:03 -0300 (-03) Date: Mon, 6 Sep 2021 16:16:03 -0300 From: Alvaro Herrera To: Rahila Syed Cc: Amit Kapila , Tomas Vondra , Peter Smith , PostgreSQL-development Subject: Re: Column Filtering in Logical Replication Message-ID: <202109061916.xxrml7wrmuoe@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk The code in get_rel_sync_entry() changes current memory context to CacheMemoryContext, then does a bunch of memory-leaking things. This is not good, because that memory context has to be very carefully managed to avoid permanent memory leaks. I suppose you added that because you need something -- probably entry->att_map -- to survive memory context resets, but if so then you need to change to CacheMemoryContext only when that memory is allocated, not other chunks of memory. I suspect you can fix this by moving the MemoryContextSwitchTo() to just before calling get_table_columnset; then all the leaky thinkgs are done in whatever the original memory context is, which is fine. (However, you also need to make sure that ->att_map is carefully freed at the right time. It looks like this already happens in rel_sync_cache_relation_cb, but is rel_sync_cache_publication_cb correct? And in get_rel_sync_entry() itself, what if the entry already has att_map -- should it be freed prior to allocating another one?) By the way, I notice that your patch doesn't add documentation changes, which are of course necessary. /me is left wondering about PGOutputData->publication_names memory handling ... -- Álvaro Herrera Valdivia, Chile — https://www.EnterpriseDB.com/