public inbox for [email protected]  
help / color / mirror / Atom feed
From: Matt Carter <[email protected]>
To: Tom Lane <[email protected]>
Cc: [email protected] <[email protected]>
Subject: RE: BUG #19411: libpq 16.x exhibits a memory leak when connections are repeatedly created and destroyed
Date: Tue, 17 Feb 2026 20:54:35 +0000
Message-ID: <BL3PR08MB72838C12A57F4D9668D27AF0996DA@BL3PR08MB7283.namprd08.prod.outlook.com> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
	<[email protected]>
	<BL3PR08MB728301C87997AF17C743633A996DA@BL3PR08MB7283.namprd08.prod.outlook.com>
	<[email protected]>

Tom Lane <[email protected]>  wrote:
> Please try varying the connection type and encryption.

Good idea.  Here's what I found:

Test 1:
  Configuration: Original (SQLAlchemy + NullPool)
  libpq: 16.0.7
  SQLAlchemy: Yes
  Leak Rate: 803 KB/min

Test 2:
  Configuration: Pure psycopg2 (default)
  libpq: 16.0.7
  SQLAlchemy: NO
  Leak Rate: 801 KB/min

Test 3:
  Configuration: Pure psycopg2 + gssencmode=disable
  libpq: 16.0.7
  SQLAlchemy: NO
  Leak Rate: 858 KB/min

Test 4:
  Configuration: Pure psycopg2 + SSL only
  libpq: 16.0.7
  SQLAlchemy: NO
  Leak Rate: 861 KB/min

Test 5:
  Configuration: Pure psycopg2
  libpq: 13.0.11
  SQLAlchemy: NO
  Leak Rate: 17 KB/min

So, it seems none of these changes avoids the leak:
- Removing SQLAlchemy
- Disabling GSSAPI encryption
- Using SSL-only
- Changing PostgreSQL DB Server version from 16 to 13

The only changes that I found that avoid the leak are:
- Changing libpq version from 16 to 13, or
- Changing psycopg version from 2 to 3.

Tom, since your C test showed no leak, the issue is likely in how psycopg2 calls libpq, not pure libpq itself.

I guess I should report this to the psycopg2 project.


reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: RE: BUG #19411: libpq 16.x exhibits a memory leak when connections are repeatedly created and destroyed
  In-Reply-To: <BL3PR08MB72838C12A57F4D9668D27AF0996DA@BL3PR08MB7283.namprd08.prod.outlook.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox