Re: BUG #19411: libpq 16.x exhibits a memory leak when connections are repeatedly created and destroyed

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: mcarter(at)twosigma(dot)com
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #19411: libpq 16.x exhibits a memory leak when connections are repeatedly created and destroyed
Date: 2026-02-17 17:01:49
Message-ID: 1702505.1771347709@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

PG Bug reporting form <noreply(at)postgresql(dot)org> 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

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Matt Carter 2026-02-17 17:54:17 RE: BUG #19411: libpq 16.x exhibits a memory leak when connections are repeatedly created and destroyed
Previous Message Artem Fadeev 2026-02-17 12:14:40 Re: BUG #19412: Wrong query result with not null constraint