BUG #19021: Memory leak of SMgrRelation object during standby redo

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: mrdrivingduck(at)gmail(dot)com
Subject: BUG #19021: Memory leak of SMgrRelation object during standby redo
Date: 2025-08-17 16:41:23
Message-ID: 19021-8748e174cf6859bc@postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 19021
Logged by: Jingtang Zhang
Email address: mrdrivingduck(at)gmail(dot)com
PostgreSQL version: 17.6
Operating system: Linux
Description:

Hi~ hackers

Back to v17, commit 21d9c3ee gave SMgrRelation a well-defined lifetime, and
smgrclose nolonger removes SMgrRelation object from the hashtable, leaving
the work to smgrdestroyall. But I find a place that relies on the removing
behavior previously, but is still calling smgrclose.

Startup process of standby will redo table dropping with DropRelationFiles,
using smgrdounlinkall to drop buffers and unlink physical files, and then
uses smgrclose to destroy the SMgrRelation object. I think it should use
smgrdestroy here, or the object memory will be leaked.

With concurrent clients, the following pgbench script will produce the
memory leak of a standby startup process easily. Entries will be entered
into the hashtable but never removed.

pgbench -f bench.sql -n -c 32 -j 32 -T 600

```sql
DROP TABLE IF EXISTS tbl:client_id;
CREATE TABLE tbl:client_id (id int);
```

The attached patch export smgrdestroy as a public function, and use it in
DropRelationFiles:

(Sorry I have sent an e-mail to pgsql-development, with a patch)
https://www.postgresql.org/message-id/flat/28C687D4-F335-417E-B06C-6612A0BD5A10%40gmail.com

I think it affects v17, v18 and master.

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2025-08-17 18:04:22 BUG #19022: Trying to set up pem server not accepting any passwords
Previous Message vignesh C 2025-08-17 13:53:18 Re: BUG #18988: DROP SUBSCRIPTION locks not-yet-accessed database