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 1vsOSP-003USs-2d for pgsql-bugs@arkaria.postgresql.org; Tue, 17 Feb 2026 17:01:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vsOSO-00Aqso-1i for pgsql-bugs@arkaria.postgresql.org; Tue, 17 Feb 2026 17:01:52 +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 1vsOSO-00Aqsg-0z for pgsql-bugs@lists.postgresql.org; Tue, 17 Feb 2026 17:01:52 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vsOSL-000000015Nq-3ba7 for pgsql-bugs@lists.postgresql.org; Tue, 17 Feb 2026 17:01:51 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 61HH1nub1702506; Tue, 17 Feb 2026 12:01:49 -0500 From: Tom Lane To: mcarter@twosigma.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #19411: libpq 16.x exhibits a memory leak when connections are repeatedly created and destroyed In-reply-to: <19411-0440c8897a04b638@postgresql.org> References: <19411-0440c8897a04b638@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Mon, 16 Feb 2026 20:44:35 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1702504.1771347709.1@sss.pgh.pa.us> Date: Tue, 17 Feb 2026 12:01:49 -0500 Message-ID: <1702505.1771347709@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk PG Bug reporting form writes: > This report is for the libpq client library for PostgreSQL. > I noticed the issue because my Apache Airflow task supervisor processes were > experiencing memory growth of ~600 KB/min. When running hundreds of tasks, > my 32 GB machine OOM-crashed every few hours. I traced the problem to when > I upgraded libpq from version 13 to 16. Varying Python version, and > PostgreSQL DB version didn't make a difference. When I updated to psycopg3, > the leak rate dropped dramatically. I think there are way too many moving parts here, and too few configuration details, to allow assigning blame confidently. I tried making a simple C test program that just connected, issued BEGIN/UPDATE/COMMIT, and disconnected in a tight loop. I see zero leakage with that. So either the leak isn't actually in libpq, or there's some critical environmental factor you didn't mention. Plausible such factors include connection type and authentication method. (For example, years ago libpq did leak memory while using GSSAPI encryption.) I tried both regular and SSL connections but didn't really push hard on that, since I'd just be guessing blindly about what your setup is. regards, tom lane