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 1vsR0d-00119s-11 for pgsql-bugs@arkaria.postgresql.org; Tue, 17 Feb 2026 19:45:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vsR0c-00BnFT-1W for pgsql-bugs@arkaria.postgresql.org; Tue, 17 Feb 2026 19:45:22 +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 1vsR0b-00BnF4-1s for pgsql-bugs@lists.postgresql.org; Tue, 17 Feb 2026 19:45:22 +0000 Received: from fhigh-a2-smtp.messagingengine.com ([103.168.172.153]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vsR0Y-000000016cu-2fZB for pgsql-bugs@lists.postgresql.org; Tue, 17 Feb 2026 19:45:20 +0000 Received: from phl-compute-12.internal (phl-compute-12.internal [10.202.2.52]) by mailfhigh.phl.internal (Postfix) with ESMTP id A1B311400109; Tue, 17 Feb 2026 14:45:18 -0500 (EST) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-12.internal (MEProxy); Tue, 17 Feb 2026 14:45:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; 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=fm3; t=1771357518; x=1771443918; bh=Zfsc7GTEjy IfibEokm3bcCUsSDTcDs7avqRKWeVOGL4=; b=eun3N6GsPieg12JwQTKaqKiWtA V7IaxGocFTVdsHAbyGIJ+Inr/RK/LYGX5C6R3FfNz9W73HJ4t3XOL6eGGTJgt+uX qJMtg+cDD0vrCVFdMXrO21gtRD6gaE85TXo050E9YzNBP6J7JOdgXKVWHqEX56+l TmiSb1a1q+Gj1h+j8MJ/nohluUV8Lh2986F1JaERmvfCMJjxXJwNpfl5GiCN5yay W5M6wJpux+v/GcxdGV0GjDURXz/xZjRkRNdp1+1z+esjaeWooU5BLtwlgmbG3hK8 sI0p1byMDNFk9LOsmjvSCnnd5KAOoa1EDRTPkSY75PZ9Dssc+K9DPGzhL1pw== 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=fm3; t= 1771357518; x=1771443918; bh=Zfsc7GTEjyIfibEokm3bcCUsSDTcDs7avqR KWeVOGL4=; b=YRI2M/0zaUP3rxm3T+4mqQ3lMURxndwGHBXn93OC5NzCCIM56mn 9knw6g3XpNU3BT32Yns/v0LnuwmHmgMgmP8vdUH+GixuQ/2ujuvLkuaO2bHAXyG7 jI+naoaioFjCYtwfD77XN0KAIkh0AQzRsSOkqBpk/NrW9OcSLb4pRp3cphMWEt7F EUghyo+N1NladteVY9fuDxTBrgAVYHP6Jg60VzfUOj9+I4B2FdJekI8uuCTWGDgP 5u9WamVM9Gh+JezkedHdYH3+DekJqKfDdFPaUVP0P+EzDxAYx03sfcQPaObFyqZl fTijZ5ZMITV0t5DrP3gFea/PMPFg/lLryuA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgddvvddtieefucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepfffhvfevuffkfhggtggujgesthdtsfdttddtvdenucfhrhhomheptehnughrvghs ucfhrhgvuhhnugcuoegrnhgurhgvshesrghnrghrrgiivghlrdguvgeqnecuggftrfgrth htvghrnhepfeffgfelvdffgedtveelgfdtgefghfdvkefggeetieevjeekteduleevjefh ueegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprg hnughrvghssegrnhgrrhgriigvlhdruggvpdhnsggprhgtphhtthhopeefpdhmohguvgep shhmthhpohhuthdprhgtphhtthhopehpghhsqhhlqdgsuhhgsheslhhishhtshdrphhosh htghhrvghsqhhlrdhorhhgpdhrtghpthhtohepthhglhesshhsshdrphhghhdrphgrrdhu shdprhgtphhtthhopehmrghtthdrtggrrhhtvghrsehtfihoshhighhmrgdrtghomh X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 17 Feb 2026 14:45:18 -0500 (EST) Date: Tue, 17 Feb 2026 14:45:17 -0500 From: Andres Freund To: Tom Lane Cc: Matt Carter , "pgsql-bugs@lists.postgresql.org" Subject: Re: BUG #19411: libpq 16.x exhibits a memory leak when connections are repeatedly created and destroyed Message-ID: <6xylkfh6idnx7ujhfhyoxku3v67ygoeve4yt7z2ytc65vzwvcv@z2sj5jnamhbe> References: <19411-0440c8897a04b638@postgresql.org> <1702505.1771347709@sss.pgh.pa.us> <1881734.1771354069@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1881734.1771354069@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 2026-02-17 13:47:49 -0500, Tom Lane wrote: > Matt Carter writes: > > Thank you for taking the time to test this and for the feedback. Your C test showing no leak suggests the issue is specific to how psycopg2 uses libpq, not libpq itself. I apologize for not including enough environmental details. I used Kerberos/GSSAPI with SSL (TLS 1.2 connections). My connection string was: "postgresql://hostname/database" (no password, Kerberos auth). > > Your mention of "years ago libpq did leak memory while using GSSAPI encryption" is interesting because we ARE using GSSAPI/Kerberos authentication. > > Interesting. I wondered about GSSAPI, but spinning up such an > environment is more work than I wanted to do on speculation. Heh, understandable... > > I can test with non-GSSAPI authentication to try to isolate that variable. I can also create a pure psycopg2 reproducer (without SQLAlchemy). I can also test whether disabling GSSAPI encryption (but keeping GSSAPI auth) changes the behavior. Would testing with GSSAPI authentication help narrow this down? I can also report this to the psycopg2 project if you think it's their issue. > > Please try varying the connection type and encryption. I do suspect > this may be psycopg2's fault, but we lack enough data to pin blame > as yet. Matt, you could try analyzing the memory usage with heaptrack, it tends to be pretty good at finding them even in uninstrumented builds, as long as enough debug symbols for a backtrace are available. Often enough it'll pinpoint where the leak is coming from quite easily (but note that it will report some constant-sized leaks that are "intentional"). Greetings, Andres