mirror of
https://github.com/postgres/postgres.git
synced 2025-05-01 01:04:50 +03:00
After any checkpoint, close all smgr files handles in bgwriter
This commit is contained in:
parent
a297d64d92
commit
055c352abb
@ -276,6 +276,15 @@ BackgroundWriterMain(void)
|
||||
*/
|
||||
pgstat_send_bgwriter();
|
||||
|
||||
if (FirstCallSinceLastCheckpoint())
|
||||
{
|
||||
/*
|
||||
* After any checkpoint, close all smgr files. This is so we
|
||||
* won't hang onto smgr references to deleted files indefinitely.
|
||||
*/
|
||||
smgrcloseall();
|
||||
}
|
||||
|
||||
/*
|
||||
* Sleep until we are signaled or BgWriterDelay has elapsed.
|
||||
*
|
||||
|
@ -1346,3 +1346,28 @@ UpdateSharedMemoryConfig(void)
|
||||
|
||||
elog(DEBUG2, "checkpointer updated shared memory configuration values");
|
||||
}
|
||||
|
||||
/*
|
||||
* FirstCallSinceLastCheckpoint allows a process to take an action once
|
||||
* per checkpoint cycle by asynchronously checking for checkpoint completion.
|
||||
*/
|
||||
bool
|
||||
FirstCallSinceLastCheckpoint(void)
|
||||
{
|
||||
/* use volatile pointer to prevent code rearrangement */
|
||||
volatile CheckpointerShmemStruct *cps = CheckpointerShmem;
|
||||
static int ckpt_done = 0;
|
||||
int new_done;
|
||||
bool FirstCall = false;
|
||||
|
||||
SpinLockAcquire(&cps->ckpt_lck);
|
||||
new_done = cps->ckpt_done;
|
||||
SpinLockRelease(&cps->ckpt_lck);
|
||||
|
||||
if (new_done != ckpt_done)
|
||||
FirstCall = true;
|
||||
|
||||
ckpt_done = new_done;
|
||||
|
||||
return FirstCall;
|
||||
}
|
||||
|
@ -38,4 +38,6 @@ extern void AbsorbFsyncRequests(void);
|
||||
extern Size CheckpointerShmemSize(void);
|
||||
extern void CheckpointerShmemInit(void);
|
||||
|
||||
extern bool FirstCallSinceLastCheckpoint(void);
|
||||
|
||||
#endif /* _BGWRITER_H */
|
||||
|
Loading…
x
Reference in New Issue
Block a user