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.96) (envelope-from ) id 1wVc6y-00253j-2x for pgsql-hackers@arkaria.postgresql.org; Fri, 05 Jun 2026 21:29:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wVc6x-00Eot2-1R for pgsql-hackers@arkaria.postgresql.org; Fri, 05 Jun 2026 21:29:51 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wVc6w-00Eost-2r for pgsql-hackers@lists.postgresql.org; Fri, 05 Jun 2026 21:29:51 +0000 Received: from fhigh-b6-smtp.messagingengine.com ([202.12.124.157]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wVc6v-00000001IhR-0V0N for pgsql-hackers@lists.postgresql.org; Fri, 05 Jun 2026 21:29:50 +0000 Received: from phl-compute-05.internal (phl-compute-05.internal [10.202.2.45]) by mailfhigh.stl.internal (Postfix) with ESMTP id AE9B97A00DC; Fri, 5 Jun 2026 17:29:47 -0400 (EDT) Received: from phl-imap-15 ([10.202.2.104]) by phl-compute-05.internal (MEProxy); Fri, 05 Jun 2026 17:29:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=partin.io; h=cc :cc:content-transfer-encoding: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=1780694987; x=1780781387; bh=/sxk3zBGx/++dKsg8um9BZUuoTu/dYowL2Vfrq8Fnik=; b= o7gFG92HD90PjpQXqaux0r3D3ZnIPaMA64XJ03v8q6shnlBEHsy9aQFmIGotH12K PmrOVMO5oOQQSWzOjgUJ6/U5psxQAgBobw/9sdhS8Neemvnsbarl2qQRGLhPq0GU TGL5I3DQRsXy+8kJsWj4WuqjuT1yK2FvQxSgW0nXvnM1yEDG3NoNj4ESWC9LVBkY 6Ph2EHio0iT1G7UE7zgOXqvt7ub47It3ymJydBe5rQUzgiW+d8T07U3FgXloRN93 9ipW/e+xXwfgZPrhM+lSzeZs7070/HH23f6WLxlba5rVXF4rvKOKvZ5rQMKdM2NW dRfm7rpemfKh7/p9L/GbGg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :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=1780694987; x= 1780781387; bh=/sxk3zBGx/++dKsg8um9BZUuoTu/dYowL2Vfrq8Fnik=; b=D oLc6MxUViMrltwO84Sbq6DQLgMj55TgkyJxvj/fQBi2xR3V293KqPtaX8OgBIaaO 81rN99/PVHuG47GYkeOvD0ktIF4poJeq02/xgxW2N1Aqs+3HxAgGmQRgwQdikxsu wcmIHN4kdvUTRNSlLXeQz8EvMOl/uyZ58Zqwr2ByKt7YFqvl+lw4z4L8KrVIbtrN FfeWOmlF2QMCM4OIoaTyY6CxXFPIunzbUC9frTEZo1LrE5ZXZ4H75jbOSC2QJwYI 1ICEJoiVQTUWBFbNKEYXUgYk6uNSKqbQFe/vZFTz6TPMB3rvL7gwK0HspEVMY9v4 ikWjk3pFrKANq383PyN4w== X-ME-Sender: X-ME-Proxy-Cause: dmFkZTG040A9mxPmuoDESWdn15wEF3E579LmZ7NIsEeNUpk3b0aY3mb7Z0pI243Fb4eRwU LOYwEgjOJSPpDOWj7Bni/Dkhl9Xq0BqoqXXMF7WVnGDdGw30keZwlJEphbxXl6Ho3r1Rfd SdEysNUGzYeFXZoMP86m7BQV9tTClEBfKBdGkhDFQNfHzYVF3D78g5P1e09DuuLa1Vg0lu N8jrXduZez/afY2D1GiZMjHhti/ppt/pma4DMmlooLmThVK5vxGlIzzETIdUrrU1NaSZvG QSeSSb8J8htTNLnw7rHtN1EqewzffFIkDpom+Dcq7Hzg15NgpCmAfz+JeBxvuS1s5dIPni C3LtUxNxu4K8HQSdVsUdLIzTRrb52VBMFDFujDjW5U4gyhEDdNcfu01KKZHhE0sgZ/jXhU HCu7KOMUIsJgTJ/gW0NqGJevNGxa4M+oh6Ho6xTtlNmmq5x6Z0g2+/KZMKkb+Qzkhv6eJN jeZ/nHs7mp8wDypvbMV/4DzQTHnmb8Ou+eRRe8TQGdwnNurTP3WsV00VQH5c3f5myYrfe6 DHhRp4z8hZDReuzHVJlm2EnNAKQJ5ZwsakoDErCWQla6HWnob4t83eqtg27zHe2HpEhv8Z XC8L2QA9rUx5Aeq1OLf/mfj/VFSuLNOY4xOOGIqSKJp8GJquhQkjVzk5vO4w X-ME-Proxy: Feedback-ID: idd01497b:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id BE31C780070; Fri, 5 Jun 2026 17:29:46 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Fri, 05 Jun 2026 21:29:46 +0000 Message-Id: Cc: , Subject: Re: [PATCH] Fix memory leak in pgstat_progress_parallel_incr_param() To: "Baji Shaik" From: "Tristan Partin" X-Mailer: aerc 0.21.0 References: In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri Jun 5, 2026 at 5:44 PM UTC, Baji Shaik wrote: > Hi, > > While running parallel vacuum with track_cost_delay_timing=3Don, I > noticed memory in the parallel worker process keeps growing > proportionally to vacuum runtime, and is never reclaimed until the > worker exits. > > I think pgstat_progress_parallel_incr_param() (backend_progress.c) > leaks memory on every call from a parallel worker. > > The suspected block: > > static StringInfoData progress_message; > initStringInfo(&progress_message); /* palloc -> A */ > pq_beginmessage(&progress_message, PqMsg_Progress); > /* pq_beginmessage internally calls initStringInfo again -> > palloc -> B, A is orphaned *= / > pq_sendint32(&progress_message, index); > pq_sendint64(&progress_message, incr); > pq_endmessage(&progress_message); /* pfree(B), A leak= ed > */ > > So one palloc(~1 kB) leaks per call, into the per-worker context. > > This is an oversight of f1889729dd3 ("Add new parallel message type > to progress reporting"); track_cost_delay_timing just makes it more > visible. With that GUC enabled, a long-running parallel vacuum leaks > megabytes per worker (~232 MB observed in a 43-min vacuum at default > settings on a 15M-row, 30-index workload). > > The proposed fix is in the attached patch which does a one-time init of t= he > static > buffer, then pq_beginmessage_reuse() / pq_endmessage_reuse() so the > buffer is allocated once and reused. Hey Baji, This looks pretty reasonable to me. Nice find. Did you think about=20 keeping the code path as is and just removing the first initStringInfo()=20 call? Removing the allocation per progress message seems like a good=20 idea to me. Maybe you could separate this change into two patches. One=20 to fix the memory leak and another to remove the allocation per message.=20 A committer could then decide for themselves if the second patch is=20 worth committing. --=20 Tristan Partin PostgreSQL Contributors Team AWS (https://aws.amazon.com)