File tree Expand file tree Collapse file tree 3 files changed +36
-0
lines changed Expand file tree Collapse file tree 3 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -276,6 +276,15 @@ BackgroundWriterMain(void)
276276 */
277277 pgstat_send_bgwriter ();
278278
279+ if (FirstCallSinceLastCheckpoint ())
280+ {
281+ /*
282+ * After any checkpoint, close all smgr files. This is so we
283+ * won't hang onto smgr references to deleted files indefinitely.
284+ */
285+ smgrcloseall ();
286+ }
287+
279288 /*
280289 * Sleep until we are signaled or BgWriterDelay has elapsed.
281290 *
Original file line number Diff line number Diff line change @@ -1346,3 +1346,28 @@ UpdateSharedMemoryConfig(void)
13461346
13471347 elog (DEBUG2 , "checkpointer updated shared memory configuration values" );
13481348}
1349+
1350+ /*
1351+ * FirstCallSinceLastCheckpoint allows a process to take an action once
1352+ * per checkpoint cycle by asynchronously checking for checkpoint completion.
1353+ */
1354+ bool
1355+ FirstCallSinceLastCheckpoint (void )
1356+ {
1357+ /* use volatile pointer to prevent code rearrangement */
1358+ volatile CheckpointerShmemStruct * cps = CheckpointerShmem ;
1359+ static int ckpt_done = 0 ;
1360+ int new_done ;
1361+ bool FirstCall = false;
1362+
1363+ SpinLockAcquire (& cps -> ckpt_lck );
1364+ new_done = cps -> ckpt_done ;
1365+ SpinLockRelease (& cps -> ckpt_lck );
1366+
1367+ if (new_done != ckpt_done )
1368+ FirstCall = true;
1369+
1370+ ckpt_done = new_done ;
1371+
1372+ return FirstCall ;
1373+ }
Original file line number Diff line number Diff line change @@ -38,4 +38,6 @@ extern void AbsorbFsyncRequests(void);
3838extern Size CheckpointerShmemSize (void );
3939extern void CheckpointerShmemInit (void );
4040
41+ extern bool FirstCallSinceLastCheckpoint (void );
42+
4143#endif /* _BGWRITER_H */
You can’t perform that action at this time.
0 commit comments