Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tHEdM-004yEk-8P for pgsql-hackers@arkaria.postgresql.org; Sat, 30 Nov 2024 03:59:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tHEdJ-00D4wF-MW for pgsql-hackers@arkaria.postgresql.org; Sat, 30 Nov 2024 03:59:02 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tHEdJ-00D4w7-C9 for pgsql-hackers@lists.postgresql.org; Sat, 30 Nov 2024 03:59:02 +0000 Received: from fout-b1-smtp.messagingengine.com ([202.12.124.144]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tHEdG-000FsY-NV for pgsql-hackers@lists.postgresql.org; Sat, 30 Nov 2024 03:59:01 +0000 Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfout.stl.internal (Postfix) with ESMTP id 28C6C114016E; Fri, 29 Nov 2024 22:58:57 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-11.internal (MEProxy); Fri, 29 Nov 2024 22:58:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1732939137; x=1733025537; bh=qYKSHTgOJv SpQu+t6V/nDW+SFxxgbKorvPBI1xNtVqU=; b=WQQs87pIvf/MLe6sNj7v2wauyj rGwe6m09ORvV4cyp9LTmiJUAts61C3ok/Ad54KPS2C1YtS+gRMWsa5C+Cu74o0db 8k79QsgcvLrkZ3KNsLMv2FoBnkhBOXI4PKcfl5LAxPFFZ5caj5GNJszIC4h4HbxA 1pU2UlHX51FMyzEkywOt9meun0VM1YUvYUIiFHjbrrQTcY0hPzVoLyNFklsSo3g1 iw3aDXMMetoliphJqpTE+tQiFGNKV+aNqM05mIJwx8YZJyj4RrHyleVYmm6lErHD jshGKG713HIX0BJcqJXCqzOKk2fcr6dW4E/9rBp9HLdv8lfg73Trp/ZZekew== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1732939137; x=1733025537; bh=qYKSHTgOJvSpQu+t6V/nDW+SFxxgbKorvPB I1xNtVqU=; b=55PeJd5yCRE2g1q1FCHeLTbTHWrRmuBxWdbqLpFeSd9fa/TwMj8 4IbY199wq3uNPPJKxn5/BDYwyRH9E9eQch3jwXWf3gTp0Y5UNFM+x8MKzwSvJaPS +Cdx+Z1z491scppxWZojmue5SgWgWgSqZ0XaytJnPxSzilpfztinlUqhHeum+8rn pWdOduBPub+i9p6t2FyeqZDJFEdGlwUnVFGyFQNXtVn9oDfNu70W8hiLL6JVJyux eYGMGjsrQjtk0YTXgHWUnu27Hv3Qbu5PAUvogqiu2ugSlVTqibuIra4oliNU18FB UB80ocMAAb0I8GW8i3OSdiCxhO//bqiu7jQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrheeggdeigecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenfghrlhcuvffnffculdefhedmnecujfgurhepfffhvfevuffkfhgg tggujgesghdtreertddtvdenucfhrhhomhepofhitghhrggvlhcurfgrqhhuihgvrhcuoe hmihgthhgrvghlsehprghquhhivghrrdighiiiqeenucggtffrrghtthgvrhhnpeegffej vefgveduvdejtddvtdeijeehudeuledvudeftdfgfeejvdekveekiedvvdenucffohhmrg hinhepphhoshhtghhrvghsqhhlrdhorhhgnecuvehluhhsthgvrhfuihiivgeptdenucfr rghrrghmpehmrghilhhfrhhomhepmhhitghhrggvlhesphgrqhhuihgvrhdrgiihiidpnh gspghrtghpthhtohepvddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepphhgshhq lhdqhhgrtghkvghrsheslhhishhtshdrphhoshhtghhrvghsqhhlrdhorhhgpdhrtghpth htoheprghmihhtrdhkrghpihhlrgduieesghhmrghilhdrtghomh X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 29 Nov 2024 22:58:55 -0500 (EST) Date: Sat, 30 Nov 2024 12:58:44 +0900 From: Michael Paquier To: Postgres hackers Cc: Amit Kapila Subject: Re: Memory leak in WAL sender with pgoutput (v10~) Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="EgbDO9k3s+84+MwI" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --EgbDO9k3s+84+MwI Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Nov 29, 2024 at 11:05:51AM +0900, Michael Paquier wrote: > This is a follow-up of ea792bfd93ab and this thread where I've noticed > that some memory was still leaking when running sysbench with a > logical replication setup: > https://www.postgresql.org/message-id/Zz7SRcBXxhOYngOr@paquier.xyz Adding Amit in CC in case, as we've talked about this topic offlist. > This problem exists since the introduction of logical replication, > down to v10. It would be sad to have an extra loop on publications to > free explicitely the publication names, and the issue would still be > hidden to the existing callers of GetPublication(), so I'd suggest to > change the Publication structure to use a NAMEDATALEN string to force > the free to happen, as in the attached. >=20 > That means an ABI break. I've looked around and did not notice any > out-of-core code relying on sizeof(Publication). That does not mean > that nothing would break, of course, but the odds should be pretty > good as this is a rather internal structure. One way would be to just > fix that on HEAD and call it a day, but I'm aware of heavy logirep > users whose workloads would be able to see memory bloating because > they maintain WAL senders around. After sleeping on that, and because the leak is minimal, I'm thinking about just applying the fix only on HEAD and call it a day. This changes the structure of Publication so as we use a char[NAMEDATALEN] rather than a char*, avoiding the pstrdup(), for the publication name and free it in the list_free_deep() when reloading the list of publications. If there are any objections or comments, feel free. I'll revisit that again around the middle of next week. -- Michael --EgbDO9k3s+84+MwI Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmdKjXQACgkQnvQgOdby QH3F2g/9GRwnC99g54WUFSb8lL2VgazWzd2Hebt6JvJwmNLu1F6aKBW8M0F2IAFt eYcYIQ5Os4AqjJCpRvfdhx5Cn1uucHosgraVWVjSkeAZyXDeaRRHG1l+W7QYlaXQ U6XT/ih8mt4Wn9f9A3hdEGssSo7UYsUqUvZ4nB6lY2MoyMVCNCOicjSjZ4R0P+Wz 2ZP5Hns5FdhQLO55oIxS/yMgYtebEd7VfOmnRRjFwp8lMjL6WeOjvjVj1VlV5eX0 kif2g69ecz6K/yE3PVK/byX5q8GoMEJp4vkVORDBHdCHwBgYfL8577Y15tdjeQpe iY8y7c4qQpRSqSMXbvuM50aD9nOXH+cOaZcRYaG4nP0/1cm2qkyDOdw1zCiWuUIn q07l5kwFWzIQRRBg3JPnSoM6m2dyaTM96p0UPkTIwVfZGEH8UdVmN8wJZXdQpZ9h 6AdfEZKYJgiVWXU0Ad2+AkxQkZppqDL7Jne91a/mCSYrv2n9lOQAbvf3smj1nkS2 xG0PMr4PaeVZJHMpFXDyX3oVi+JoVFSeu4enOw9YCxNGeN6sstIt8IKBns/KO63E wPE6KelGLAD9UtrdifIi0nqAQakAMjDZDOo06XQzU8jBLFx9Rgl3GETnTWCUW2Bc ZEFhmMMUJECUsrtY1g+pUDMJb4A1HhwyNxm/bo+GfYmNzdjG1bY= =os// -----END PGP SIGNATURE----- --EgbDO9k3s+84+MwI--