File tree 3 files changed +36
-0
lines changed
3 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -276,6 +276,15 @@ BackgroundWriterMain(void)
276
276
*/
277
277
pgstat_send_bgwriter ();
278
278
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
+
279
288
/*
280
289
* Sleep until we are signaled or BgWriterDelay has elapsed.
281
290
*
Original file line number Diff line number Diff line change @@ -1346,3 +1346,28 @@ UpdateSharedMemoryConfig(void)
1346
1346
1347
1347
elog (DEBUG2 , "checkpointer updated shared memory configuration values" );
1348
1348
}
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);
38
38
extern Size CheckpointerShmemSize (void );
39
39
extern void CheckpointerShmemInit (void );
40
40
41
+ extern bool FirstCallSinceLastCheckpoint (void );
42
+
41
43
#endif /* _BGWRITER_H */
You can’t perform that action at this time.
0 commit comments