Fix leak with SMgrRelations in startup process
authorMichael Paquier <michael@paquier.xyz>
Tue, 9 Sep 2025 22:23:24 +0000 (07:23 +0900)
committerMichael Paquier <michael@paquier.xyz>
Tue, 9 Sep 2025 22:23:24 +0000 (07:23 +0900)
commite2dd7b2acf27336d47f78d68f4aac03f7770a6a6
treedad4d51b54fb300c61b819e80e3c365e88e20bb9
parent778f391c26c6c569b3078daff1ac8e218024e46c
Fix leak with SMgrRelations in startup process

The startup process does not process shared invalidation messages, only
sending them, and never calls AtEOXact_SMgr() which clean up any
unpinned SMgrRelations.  Hence, it is never able to free SMgrRelations
on a periodic basis, bloating its hashtable over time.

Like the checkpointer and the bgwriter, this commit takes a conservative
approach by freeing periodically SMgrRelations when replaying a
checkpoint record, either online or shutdown, so as the startup process
has a way to perform a periodic cleanup.

Issue caused by 21d9c3ee4ef7, so backpatch down to v17.

Author: Jingtang Zhang <mrdrivingduck@gmail.com>
Reviewed-by: Yuhang Qiu <iamqyh@gmail.com>
Discussion: https://postgr.es/m/28C687D4-F335-417E-B06C-6612A0BD5A10@gmail.com
Backpatch-through: 17
src/backend/access/transam/xlog.c