Skip to content

Commit 055c352

Browse files
After any checkpoint, close all smgr files handles in bgwriter
1 parent a297d64 commit 055c352

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

src/backend/postmaster/bgwriter.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff 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
*

src/backend/postmaster/checkpointer.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
}

src/include/postmaster/bgwriter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,6 @@ extern void AbsorbFsyncRequests(void);
3838
extern Size CheckpointerShmemSize(void);
3939
extern void CheckpointerShmemInit(void);
4040

41+
extern bool FirstCallSinceLastCheckpoint(void);
42+
4143
#endif /* _BGWRITER_H */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy