Skip to content

Commit 8c8f7b1

Browse files
committed
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 21d9c3e, 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
1 parent d96c854 commit 8c8f7b1

File tree

1 file changed

+16
-0
lines changed
  • src/backend/access/transam

1 file changed

+16
-0
lines changed

src/backend/access/transam/xlog.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8385,6 +8385,14 @@ xlog_redo(XLogReaderState *record)
83858385
checkPoint.ThisTimeLineID, replayTLI)));
83868386

83878387
RecoveryRestartPoint(&checkPoint, record);
8388+
8389+
/*
8390+
* After replaying a checkpoint record, free all smgr objects.
8391+
* Otherwise we would never do so for dropped relations, as the
8392+
* startup does not process shared invalidation messages or call
8393+
* AtEOXact_SMgr().
8394+
*/
8395+
smgrdestroyall();
83888396
}
83898397
else if (info == XLOG_CHECKPOINT_ONLINE)
83908398
{
@@ -8438,6 +8446,14 @@ xlog_redo(XLogReaderState *record)
84388446
checkPoint.ThisTimeLineID, replayTLI)));
84398447

84408448
RecoveryRestartPoint(&checkPoint, record);
8449+
8450+
/*
8451+
* After replaying a checkpoint record, free all smgr objects.
8452+
* Otherwise we would never do so for dropped relations, as the
8453+
* startup does not process shared invalidation messages or call
8454+
* AtEOXact_SMgr().
8455+
*/
8456+
smgrdestroyall();
84418457
}
84428458
else if (info == XLOG_OVERWRITE_CONTRECORD)
84438459
{

0 commit comments

Comments
 (0)