agora inbox for pgsql-hackers@postgresql.orghelp / color / mirror / Atom feed
[PATCH v13 4/6] Move pgsql_tmp file removal to custodian process. 12+ messages / 1 participants [nested] [flat]
* [PATCH v13 4/6] Move pgsql_tmp file removal to custodian process. @ 2021-12-06 05:42 Nathan Bossart <bossartn@amazon.com> 0 siblings, 0 replies; 12+ messages in thread From: Nathan Bossart @ 2021-12-06 05:42 UTC (permalink / raw) With this change, startup (and restart after a crash) simply renames the pgsql_tmp directories, and the custodian process actually removes all the files in the staged directories as well as the staged directories themselves. This should help avoid long startup delays due to many leftover temporary files. --- src/backend/postmaster/custodian.c | 1 + src/backend/postmaster/postmaster.c | 24 +++++++++++++++++++----- src/backend/storage/file/fd.c | 13 +++++++------ src/include/postmaster/custodian.h | 2 +- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/backend/postmaster/custodian.c b/src/backend/postmaster/custodian.c index e90f5d0d1f..fe1f48844e 100644 --- a/src/backend/postmaster/custodian.c +++ b/src/backend/postmaster/custodian.c @@ -70,6 +70,7 @@ struct cust_task_funcs_entry * whether the task is already enqueued. */ static const struct cust_task_funcs_entry cust_task_functions[] = { + {CUSTODIAN_REMOVE_TEMP_FILES, RemovePgTempFiles, NULL}, {INVALID_CUSTODIAN_TASK, NULL, NULL} /* must be last */ }; diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index 3840da94ce..86000935fd 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -109,6 +109,7 @@ #include "postmaster/autovacuum.h" #include "postmaster/auxprocess.h" #include "postmaster/bgworker_internals.h" +#include "postmaster/custodian.h" #include "postmaster/fork_process.h" #include "postmaster/interrupt.h" #include "postmaster/pgarch.h" @@ -1385,9 +1386,12 @@ PostmasterMain(int argc, char *argv[]) /* * Remove old temporary files. At this point there can be no other * Postgres processes running in this directory, so this should be safe. + * + * Note that this just stages the pgsql_tmp directories for deletion. The + * custodian process is responsible for actually removing the files. */ StagePgTempFilesForRemoval(); - RemovePgTempFiles(); + RequestCustodian(CUSTODIAN_REMOVE_TEMP_FILES, false, (Datum) 0); /* * Initialize the autovacuum subsystem (again, no process start yet) @@ -3919,12 +3923,14 @@ PostmasterStateMachine(void) ereport(LOG, (errmsg("all server processes terminated; reinitializing"))); - /* remove leftover temporary files after a crash */ + /* + * Remove leftover temporary files after a crash. + * + * Note that this just stages the pgsql_tmp directories for deletion. + * The custodian process is responsible for actually removing the files. + */ if (remove_temp_files_after_crash) - { StagePgTempFilesForRemoval(); - RemovePgTempFiles(); - } /* allow background workers to immediately restart */ ResetBackgroundWorkerCrashTimes(); @@ -3937,6 +3943,14 @@ PostmasterStateMachine(void) /* re-create shared memory and semaphores */ CreateSharedMemoryAndSemaphores(); + /* + * Now that shared memory is initialized, notify the custodian to clean + * up the staged pgsql_tmp directories. We do this even if + * remove_temp_files_after_crash is false so that any previously staged + * directories are eventually cleaned up. + */ + RequestCustodian(CUSTODIAN_REMOVE_TEMP_FILES, false, (Datum) 0); + StartupPID = StartupDataBase(); Assert(StartupPID != 0); StartupStatus = STARTUP_RUNNING; diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c index 9610850d45..625355c56a 100644 --- a/src/backend/storage/file/fd.c +++ b/src/backend/storage/file/fd.c @@ -96,6 +96,7 @@ #include "miscadmin.h" #include "pgstat.h" #include "portability/mem.h" +#include "postmaster/custodian.h" #include "postmaster/startup.h" #include "storage/fd.h" #include "storage/ipc.h" @@ -1564,9 +1565,9 @@ PathNameOpenFilePerm(const char *fileName, int fileFlags, mode_t fileMode) * * Directories created within the top-level temporary directory should begin * with PG_TEMP_FILE_PREFIX, so that they can be identified as temporary and - * deleted at startup by RemovePgTempFiles(). Further subdirectories below - * that do not need any particular prefix. -*/ + * deleted by RemovePgTempFiles(). Further subdirectories below that do not + * need any particular prefix. + */ void PathNameCreateTemporaryDir(const char *basedir, const char *directory) { @@ -1764,9 +1765,9 @@ OpenTemporaryFileInTablespace(Oid tblspcOid, bool rejectError) * * If the file is inside the top-level temporary directory, its name should * begin with PG_TEMP_FILE_PREFIX so that it can be identified as temporary - * and deleted at startup by RemovePgTempFiles(). Alternatively, it can be - * inside a directory created with PathNameCreateTemporaryDir(), in which case - * the prefix isn't needed. + * and deleted by RemovePgTempFiles(). Alternatively, it can be inside a + * directory created with PathNameCreateTemporaryDir(), in which case the prefix + * isn't needed. */ File PathNameCreateTemporaryFile(const char *path, bool error_on_failure) diff --git a/src/include/postmaster/custodian.h b/src/include/postmaster/custodian.h index 170ca61a21..80890ceadd 100644 --- a/src/include/postmaster/custodian.h +++ b/src/include/postmaster/custodian.h @@ -18,7 +18,7 @@ */ typedef enum CustodianTask { - FAKE_TASK, /* placeholder until we have a real task */ + CUSTODIAN_REMOVE_TEMP_FILES, NUM_CUSTODIAN_TASKS, /* new tasks go above */ INVALID_CUSTODIAN_TASK -- 2.25.1 --CE+1k2dSO48ffgeK Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v13-0005-Move-removal-of-old-serialized-snapshots-to-cust.patch" ^ permalink raw reply [nested|flat] 12+ messages in thread
* [PATCH v12 4/6] Move pgsql_tmp file removal to custodian process. @ 2021-12-06 05:42 Nathan Bossart <bossartn@amazon.com> 0 siblings, 0 replies; 12+ messages in thread From: Nathan Bossart @ 2021-12-06 05:42 UTC (permalink / raw) With this change, startup (and restart after a crash) simply renames the pgsql_tmp directories, and the custodian process actually removes all the files in the staged directories as well as the staged directories themselves. This should help avoid long startup delays due to many leftover temporary files. --- src/backend/postmaster/custodian.c | 1 + src/backend/postmaster/postmaster.c | 24 +++++++++++++++++++----- src/backend/storage/file/fd.c | 13 +++++++------ src/include/postmaster/custodian.h | 2 +- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/backend/postmaster/custodian.c b/src/backend/postmaster/custodian.c index e90f5d0d1f..fe1f48844e 100644 --- a/src/backend/postmaster/custodian.c +++ b/src/backend/postmaster/custodian.c @@ -70,6 +70,7 @@ struct cust_task_funcs_entry * whether the task is already enqueued. */ static const struct cust_task_funcs_entry cust_task_functions[] = { + {CUSTODIAN_REMOVE_TEMP_FILES, RemovePgTempFiles, NULL}, {INVALID_CUSTODIAN_TASK, NULL, NULL} /* must be last */ }; diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index 54548e28e9..6dc33724f4 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -109,6 +109,7 @@ #include "postmaster/autovacuum.h" #include "postmaster/auxprocess.h" #include "postmaster/bgworker_internals.h" +#include "postmaster/custodian.h" #include "postmaster/fork_process.h" #include "postmaster/interrupt.h" #include "postmaster/pgarch.h" @@ -1398,9 +1399,12 @@ PostmasterMain(int argc, char *argv[]) /* * Remove old temporary files. At this point there can be no other * Postgres processes running in this directory, so this should be safe. + * + * Note that this just stages the pgsql_tmp directories for deletion. The + * custodian process is responsible for actually removing the files. */ StagePgTempFilesForRemoval(); - RemovePgTempFiles(); + RequestCustodian(CUSTODIAN_REMOVE_TEMP_FILES, false, (Datum) 0); /* * Initialize the autovacuum subsystem (again, no process start yet) @@ -4029,12 +4033,14 @@ PostmasterStateMachine(void) ereport(LOG, (errmsg("all server processes terminated; reinitializing"))); - /* remove leftover temporary files after a crash */ + /* + * Remove leftover temporary files after a crash. + * + * Note that this just stages the pgsql_tmp directories for deletion. + * The custodian process is responsible for actually removing the files. + */ if (remove_temp_files_after_crash) - { StagePgTempFilesForRemoval(); - RemovePgTempFiles(); - } /* allow background workers to immediately restart */ ResetBackgroundWorkerCrashTimes(); @@ -4047,6 +4053,14 @@ PostmasterStateMachine(void) /* re-create shared memory and semaphores */ CreateSharedMemoryAndSemaphores(); + /* + * Now that shared memory is initialized, notify the custodian to clean + * up the staged pgsql_tmp directories. We do this even if + * remove_temp_files_after_crash is false so that any previously staged + * directories are eventually cleaned up. + */ + RequestCustodian(CUSTODIAN_REMOVE_TEMP_FILES, false, (Datum) 0); + StartupPID = StartupDataBase(); Assert(StartupPID != 0); StartupStatus = STARTUP_RUNNING; diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c index 9610850d45..625355c56a 100644 --- a/src/backend/storage/file/fd.c +++ b/src/backend/storage/file/fd.c @@ -96,6 +96,7 @@ #include "miscadmin.h" #include "pgstat.h" #include "portability/mem.h" +#include "postmaster/custodian.h" #include "postmaster/startup.h" #include "storage/fd.h" #include "storage/ipc.h" @@ -1564,9 +1565,9 @@ PathNameOpenFilePerm(const char *fileName, int fileFlags, mode_t fileMode) * * Directories created within the top-level temporary directory should begin * with PG_TEMP_FILE_PREFIX, so that they can be identified as temporary and - * deleted at startup by RemovePgTempFiles(). Further subdirectories below - * that do not need any particular prefix. -*/ + * deleted by RemovePgTempFiles(). Further subdirectories below that do not + * need any particular prefix. + */ void PathNameCreateTemporaryDir(const char *basedir, const char *directory) { @@ -1764,9 +1765,9 @@ OpenTemporaryFileInTablespace(Oid tblspcOid, bool rejectError) * * If the file is inside the top-level temporary directory, its name should * begin with PG_TEMP_FILE_PREFIX so that it can be identified as temporary - * and deleted at startup by RemovePgTempFiles(). Alternatively, it can be - * inside a directory created with PathNameCreateTemporaryDir(), in which case - * the prefix isn't needed. + * and deleted by RemovePgTempFiles(). Alternatively, it can be inside a + * directory created with PathNameCreateTemporaryDir(), in which case the prefix + * isn't needed. */ File PathNameCreateTemporaryFile(const char *path, bool error_on_failure) diff --git a/src/include/postmaster/custodian.h b/src/include/postmaster/custodian.h index 170ca61a21..80890ceadd 100644 --- a/src/include/postmaster/custodian.h +++ b/src/include/postmaster/custodian.h @@ -18,7 +18,7 @@ */ typedef enum CustodianTask { - FAKE_TASK, /* placeholder until we have a real task */ + CUSTODIAN_REMOVE_TEMP_FILES, NUM_CUSTODIAN_TASKS, /* new tasks go above */ INVALID_CUSTODIAN_TASK -- 2.25.1 --UlVJffcvxoiEqYs2 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v12-0005-Move-removal-of-old-serialized-snapshots-to-cust.patch" ^ permalink raw reply [nested|flat] 12+ messages in thread
* [PATCH v13 4/6] Move pgsql_tmp file removal to custodian process. @ 2021-12-06 05:42 Nathan Bossart <bossartn@amazon.com> 0 siblings, 0 replies; 12+ messages in thread From: Nathan Bossart @ 2021-12-06 05:42 UTC (permalink / raw) With this change, startup (and restart after a crash) simply renames the pgsql_tmp directories, and the custodian process actually removes all the files in the staged directories as well as the staged directories themselves. This should help avoid long startup delays due to many leftover temporary files. --- src/backend/postmaster/custodian.c | 1 + src/backend/postmaster/postmaster.c | 24 +++++++++++++++++++----- src/backend/storage/file/fd.c | 13 +++++++------ src/include/postmaster/custodian.h | 2 +- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/backend/postmaster/custodian.c b/src/backend/postmaster/custodian.c index e90f5d0d1f..fe1f48844e 100644 --- a/src/backend/postmaster/custodian.c +++ b/src/backend/postmaster/custodian.c @@ -70,6 +70,7 @@ struct cust_task_funcs_entry * whether the task is already enqueued. */ static const struct cust_task_funcs_entry cust_task_functions[] = { + {CUSTODIAN_REMOVE_TEMP_FILES, RemovePgTempFiles, NULL}, {INVALID_CUSTODIAN_TASK, NULL, NULL} /* must be last */ }; diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index 3840da94ce..86000935fd 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -109,6 +109,7 @@ #include "postmaster/autovacuum.h" #include "postmaster/auxprocess.h" #include "postmaster/bgworker_internals.h" +#include "postmaster/custodian.h" #include "postmaster/fork_process.h" #include "postmaster/interrupt.h" #include "postmaster/pgarch.h" @@ -1385,9 +1386,12 @@ PostmasterMain(int argc, char *argv[]) /* * Remove old temporary files. At this point there can be no other * Postgres processes running in this directory, so this should be safe. + * + * Note that this just stages the pgsql_tmp directories for deletion. The + * custodian process is responsible for actually removing the files. */ StagePgTempFilesForRemoval(); - RemovePgTempFiles(); + RequestCustodian(CUSTODIAN_REMOVE_TEMP_FILES, false, (Datum) 0); /* * Initialize the autovacuum subsystem (again, no process start yet) @@ -3919,12 +3923,14 @@ PostmasterStateMachine(void) ereport(LOG, (errmsg("all server processes terminated; reinitializing"))); - /* remove leftover temporary files after a crash */ + /* + * Remove leftover temporary files after a crash. + * + * Note that this just stages the pgsql_tmp directories for deletion. + * The custodian process is responsible for actually removing the files. + */ if (remove_temp_files_after_crash) - { StagePgTempFilesForRemoval(); - RemovePgTempFiles(); - } /* allow background workers to immediately restart */ ResetBackgroundWorkerCrashTimes(); @@ -3937,6 +3943,14 @@ PostmasterStateMachine(void) /* re-create shared memory and semaphores */ CreateSharedMemoryAndSemaphores(); + /* + * Now that shared memory is initialized, notify the custodian to clean + * up the staged pgsql_tmp directories. We do this even if + * remove_temp_files_after_crash is false so that any previously staged + * directories are eventually cleaned up. + */ + RequestCustodian(CUSTODIAN_REMOVE_TEMP_FILES, false, (Datum) 0); + StartupPID = StartupDataBase(); Assert(StartupPID != 0); StartupStatus = STARTUP_RUNNING; diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c index 9610850d45..625355c56a 100644 --- a/src/backend/storage/file/fd.c +++ b/src/backend/storage/file/fd.c @@ -96,6 +96,7 @@ #include "miscadmin.h" #include "pgstat.h" #include "portability/mem.h" +#include "postmaster/custodian.h" #include "postmaster/startup.h" #include "storage/fd.h" #include "storage/ipc.h" @@ -1564,9 +1565,9 @@ PathNameOpenFilePerm(const char *fileName, int fileFlags, mode_t fileMode) * * Directories created within the top-level temporary directory should begin * with PG_TEMP_FILE_PREFIX, so that they can be identified as temporary and - * deleted at startup by RemovePgTempFiles(). Further subdirectories below - * that do not need any particular prefix. -*/ + * deleted by RemovePgTempFiles(). Further subdirectories below that do not + * need any particular prefix. + */ void PathNameCreateTemporaryDir(const char *basedir, const char *directory) { @@ -1764,9 +1765,9 @@ OpenTemporaryFileInTablespace(Oid tblspcOid, bool rejectError) * * If the file is inside the top-level temporary directory, its name should * begin with PG_TEMP_FILE_PREFIX so that it can be identified as temporary - * and deleted at startup by RemovePgTempFiles(). Alternatively, it can be - * inside a directory created with PathNameCreateTemporaryDir(), in which case - * the prefix isn't needed. + * and deleted by RemovePgTempFiles(). Alternatively, it can be inside a + * directory created with PathNameCreateTemporaryDir(), in which case the prefix + * isn't needed. */ File PathNameCreateTemporaryFile(const char *path, bool error_on_failure) diff --git a/src/include/postmaster/custodian.h b/src/include/postmaster/custodian.h index 170ca61a21..80890ceadd 100644 --- a/src/include/postmaster/custodian.h +++ b/src/include/postmaster/custodian.h @@ -18,7 +18,7 @@ */ typedef enum CustodianTask { - FAKE_TASK, /* placeholder until we have a real task */ + CUSTODIAN_REMOVE_TEMP_FILES, NUM_CUSTODIAN_TASKS, /* new tasks go above */ INVALID_CUSTODIAN_TASK -- 2.25.1 --CE+1k2dSO48ffgeK Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v13-0005-Move-removal-of-old-serialized-snapshots-to-cust.patch" ^ permalink raw reply [nested|flat] 12+ messages in thread
* [PATCH v12 4/6] Move pgsql_tmp file removal to custodian process. @ 2021-12-06 05:42 Nathan Bossart <bossartn@amazon.com> 0 siblings, 0 replies; 12+ messages in thread From: Nathan Bossart @ 2021-12-06 05:42 UTC (permalink / raw) With this change, startup (and restart after a crash) simply renames the pgsql_tmp directories, and the custodian process actually removes all the files in the staged directories as well as the staged directories themselves. This should help avoid long startup delays due to many leftover temporary files. --- src/backend/postmaster/custodian.c | 1 + src/backend/postmaster/postmaster.c | 24 +++++++++++++++++++----- src/backend/storage/file/fd.c | 13 +++++++------ src/include/postmaster/custodian.h | 2 +- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/backend/postmaster/custodian.c b/src/backend/postmaster/custodian.c index e90f5d0d1f..fe1f48844e 100644 --- a/src/backend/postmaster/custodian.c +++ b/src/backend/postmaster/custodian.c @@ -70,6 +70,7 @@ struct cust_task_funcs_entry * whether the task is already enqueued. */ static const struct cust_task_funcs_entry cust_task_functions[] = { + {CUSTODIAN_REMOVE_TEMP_FILES, RemovePgTempFiles, NULL}, {INVALID_CUSTODIAN_TASK, NULL, NULL} /* must be last */ }; diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index 54548e28e9..6dc33724f4 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -109,6 +109,7 @@ #include "postmaster/autovacuum.h" #include "postmaster/auxprocess.h" #include "postmaster/bgworker_internals.h" +#include "postmaster/custodian.h" #include "postmaster/fork_process.h" #include "postmaster/interrupt.h" #include "postmaster/pgarch.h" @@ -1398,9 +1399,12 @@ PostmasterMain(int argc, char *argv[]) /* * Remove old temporary files. At this point there can be no other * Postgres processes running in this directory, so this should be safe. + * + * Note that this just stages the pgsql_tmp directories for deletion. The + * custodian process is responsible for actually removing the files. */ StagePgTempFilesForRemoval(); - RemovePgTempFiles(); + RequestCustodian(CUSTODIAN_REMOVE_TEMP_FILES, false, (Datum) 0); /* * Initialize the autovacuum subsystem (again, no process start yet) @@ -4029,12 +4033,14 @@ PostmasterStateMachine(void) ereport(LOG, (errmsg("all server processes terminated; reinitializing"))); - /* remove leftover temporary files after a crash */ + /* + * Remove leftover temporary files after a crash. + * + * Note that this just stages the pgsql_tmp directories for deletion. + * The custodian process is responsible for actually removing the files. + */ if (remove_temp_files_after_crash) - { StagePgTempFilesForRemoval(); - RemovePgTempFiles(); - } /* allow background workers to immediately restart */ ResetBackgroundWorkerCrashTimes(); @@ -4047,6 +4053,14 @@ PostmasterStateMachine(void) /* re-create shared memory and semaphores */ CreateSharedMemoryAndSemaphores(); + /* + * Now that shared memory is initialized, notify the custodian to clean + * up the staged pgsql_tmp directories. We do this even if + * remove_temp_files_after_crash is false so that any previously staged + * directories are eventually cleaned up. + */ + RequestCustodian(CUSTODIAN_REMOVE_TEMP_FILES, false, (Datum) 0); + StartupPID = StartupDataBase(); Assert(StartupPID != 0); StartupStatus = STARTUP_RUNNING; diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c index 9610850d45..625355c56a 100644 --- a/src/backend/storage/file/fd.c +++ b/src/backend/storage/file/fd.c @@ -96,6 +96,7 @@ #include "miscadmin.h" #include "pgstat.h" #include "portability/mem.h" +#include "postmaster/custodian.h" #include "postmaster/startup.h" #include "storage/fd.h" #include "storage/ipc.h" @@ -1564,9 +1565,9 @@ PathNameOpenFilePerm(const char *fileName, int fileFlags, mode_t fileMode) * * Directories created within the top-level temporary directory should begin * with PG_TEMP_FILE_PREFIX, so that they can be identified as temporary and - * deleted at startup by RemovePgTempFiles(). Further subdirectories below - * that do not need any particular prefix. -*/ + * deleted by RemovePgTempFiles(). Further subdirectories below that do not + * need any particular prefix. + */ void PathNameCreateTemporaryDir(const char *basedir, const char *directory) { @@ -1764,9 +1765,9 @@ OpenTemporaryFileInTablespace(Oid tblspcOid, bool rejectError) * * If the file is inside the top-level temporary directory, its name should * begin with PG_TEMP_FILE_PREFIX so that it can be identified as temporary - * and deleted at startup by RemovePgTempFiles(). Alternatively, it can be - * inside a directory created with PathNameCreateTemporaryDir(), in which case - * the prefix isn't needed. + * and deleted by RemovePgTempFiles(). Alternatively, it can be inside a + * directory created with PathNameCreateTemporaryDir(), in which case the prefix + * isn't needed. */ File PathNameCreateTemporaryFile(const char *path, bool error_on_failure) diff --git a/src/include/postmaster/custodian.h b/src/include/postmaster/custodian.h index 170ca61a21..80890ceadd 100644 --- a/src/include/postmaster/custodian.h +++ b/src/include/postmaster/custodian.h @@ -18,7 +18,7 @@ */ typedef enum CustodianTask { - FAKE_TASK, /* placeholder until we have a real task */ + CUSTODIAN_REMOVE_TEMP_FILES, NUM_CUSTODIAN_TASKS, /* new tasks go above */ INVALID_CUSTODIAN_TASK -- 2.25.1 --UlVJffcvxoiEqYs2 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v12-0005-Move-removal-of-old-serialized-snapshots-to-cust.patch" ^ permalink raw reply [nested|flat] 12+ messages in thread
* [PATCH v10 4/6] Move pgsql_tmp file removal to custodian process. @ 2021-12-06 05:42 Nathan Bossart <bossartn@amazon.com> 0 siblings, 0 replies; 12+ messages in thread From: Nathan Bossart @ 2021-12-06 05:42 UTC (permalink / raw) With this change, startup (and restart after a crash) simply renames the pgsql_tmp directories, and the custodian process actually removes all the files in the staged directories as well as the staged directories themselves. This should help avoid long startup delays due to many leftover temporary files. --- src/backend/postmaster/custodian.c | 1 + src/backend/postmaster/postmaster.c | 24 +++++++++++++++++++----- src/backend/storage/file/fd.c | 13 +++++++------ src/include/postmaster/custodian.h | 2 +- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/backend/postmaster/custodian.c b/src/backend/postmaster/custodian.c index e90f5d0d1f..fe1f48844e 100644 --- a/src/backend/postmaster/custodian.c +++ b/src/backend/postmaster/custodian.c @@ -70,6 +70,7 @@ struct cust_task_funcs_entry * whether the task is already enqueued. */ static const struct cust_task_funcs_entry cust_task_functions[] = { + {CUSTODIAN_REMOVE_TEMP_FILES, RemovePgTempFiles, NULL}, {INVALID_CUSTODIAN_TASK, NULL, NULL} /* must be last */ }; diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index 6edae456f1..c0500fe4df 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -109,6 +109,7 @@ #include "postmaster/autovacuum.h" #include "postmaster/auxprocess.h" #include "postmaster/bgworker_internals.h" +#include "postmaster/custodian.h" #include "postmaster/fork_process.h" #include "postmaster/interrupt.h" #include "postmaster/pgarch.h" @@ -1398,9 +1399,12 @@ PostmasterMain(int argc, char *argv[]) /* * Remove old temporary files. At this point there can be no other * Postgres processes running in this directory, so this should be safe. + * + * Note that this just stages the pgsql_tmp directories for deletion. The + * custodian process is responsible for actually removing the files. */ StagePgTempFilesForRemoval(); - RemovePgTempFiles(); + RequestCustodian(CUSTODIAN_REMOVE_TEMP_FILES, false, (Datum) 0); /* * Initialize the autovacuum subsystem (again, no process start yet) @@ -4033,12 +4037,14 @@ PostmasterStateMachine(void) ereport(LOG, (errmsg("all server processes terminated; reinitializing"))); - /* remove leftover temporary files after a crash */ + /* + * Remove leftover temporary files after a crash. + * + * Note that this just stages the pgsql_tmp directories for deletion. + * The custodian process is responsible for actually removing the files. + */ if (remove_temp_files_after_crash) - { StagePgTempFilesForRemoval(); - RemovePgTempFiles(); - } /* allow background workers to immediately restart */ ResetBackgroundWorkerCrashTimes(); @@ -4051,6 +4057,14 @@ PostmasterStateMachine(void) /* re-create shared memory and semaphores */ CreateSharedMemoryAndSemaphores(); + /* + * Now that shared memory is initialized, notify the custodian to clean + * up the staged pgsql_tmp directories. We do this even if + * remove_temp_files_after_crash is false so that any previously staged + * directories are eventually cleaned up. + */ + RequestCustodian(CUSTODIAN_REMOVE_TEMP_FILES, false, (Datum) 0); + StartupPID = StartupDataBase(); Assert(StartupPID != 0); StartupStatus = STARTUP_RUNNING; diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c index 64c844ab87..2475b35c1e 100644 --- a/src/backend/storage/file/fd.c +++ b/src/backend/storage/file/fd.c @@ -97,6 +97,7 @@ #include "pgstat.h" #include "port/pg_iovec.h" #include "portability/mem.h" +#include "postmaster/custodian.h" #include "postmaster/startup.h" #include "storage/fd.h" #include "storage/ipc.h" @@ -1565,9 +1566,9 @@ PathNameOpenFilePerm(const char *fileName, int fileFlags, mode_t fileMode) * * Directories created within the top-level temporary directory should begin * with PG_TEMP_FILE_PREFIX, so that they can be identified as temporary and - * deleted at startup by RemovePgTempFiles(). Further subdirectories below - * that do not need any particular prefix. -*/ + * deleted by RemovePgTempFiles(). Further subdirectories below that do not + * need any particular prefix. + */ void PathNameCreateTemporaryDir(const char *basedir, const char *directory) { @@ -1765,9 +1766,9 @@ OpenTemporaryFileInTablespace(Oid tblspcOid, bool rejectError) * * If the file is inside the top-level temporary directory, its name should * begin with PG_TEMP_FILE_PREFIX so that it can be identified as temporary - * and deleted at startup by RemovePgTempFiles(). Alternatively, it can be - * inside a directory created with PathNameCreateTemporaryDir(), in which case - * the prefix isn't needed. + * and deleted by RemovePgTempFiles(). Alternatively, it can be inside a + * directory created with PathNameCreateTemporaryDir(), in which case the prefix + * isn't needed. */ File PathNameCreateTemporaryFile(const char *path, bool error_on_failure) diff --git a/src/include/postmaster/custodian.h b/src/include/postmaster/custodian.h index 170ca61a21..80890ceadd 100644 --- a/src/include/postmaster/custodian.h +++ b/src/include/postmaster/custodian.h @@ -18,7 +18,7 @@ */ typedef enum CustodianTask { - FAKE_TASK, /* placeholder until we have a real task */ + CUSTODIAN_REMOVE_TEMP_FILES, NUM_CUSTODIAN_TASKS, /* new tasks go above */ INVALID_CUSTODIAN_TASK -- 2.25.1 --+QahgC5+KEYLbs62 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v10-0005-Move-removal-of-old-serialized-snapshots-to-cust.patch" ^ permalink raw reply [nested|flat] 12+ messages in thread
* [PATCH v11 4/6] Move pgsql_tmp file removal to custodian process. @ 2021-12-06 05:42 Nathan Bossart <bossartn@amazon.com> 0 siblings, 0 replies; 12+ messages in thread From: Nathan Bossart @ 2021-12-06 05:42 UTC (permalink / raw) With this change, startup (and restart after a crash) simply renames the pgsql_tmp directories, and the custodian process actually removes all the files in the staged directories as well as the staged directories themselves. This should help avoid long startup delays due to many leftover temporary files. --- src/backend/postmaster/custodian.c | 1 + src/backend/postmaster/postmaster.c | 24 +++++++++++++++++++----- src/backend/storage/file/fd.c | 13 +++++++------ src/include/postmaster/custodian.h | 2 +- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/backend/postmaster/custodian.c b/src/backend/postmaster/custodian.c index e90f5d0d1f..fe1f48844e 100644 --- a/src/backend/postmaster/custodian.c +++ b/src/backend/postmaster/custodian.c @@ -70,6 +70,7 @@ struct cust_task_funcs_entry * whether the task is already enqueued. */ static const struct cust_task_funcs_entry cust_task_functions[] = { + {CUSTODIAN_REMOVE_TEMP_FILES, RemovePgTempFiles, NULL}, {INVALID_CUSTODIAN_TASK, NULL, NULL} /* must be last */ }; diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index e13bc11daf..44479eec60 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -109,6 +109,7 @@ #include "postmaster/autovacuum.h" #include "postmaster/auxprocess.h" #include "postmaster/bgworker_internals.h" +#include "postmaster/custodian.h" #include "postmaster/fork_process.h" #include "postmaster/interrupt.h" #include "postmaster/pgarch.h" @@ -1398,9 +1399,12 @@ PostmasterMain(int argc, char *argv[]) /* * Remove old temporary files. At this point there can be no other * Postgres processes running in this directory, so this should be safe. + * + * Note that this just stages the pgsql_tmp directories for deletion. The + * custodian process is responsible for actually removing the files. */ StagePgTempFilesForRemoval(); - RemovePgTempFiles(); + RequestCustodian(CUSTODIAN_REMOVE_TEMP_FILES, false, (Datum) 0); /* * Initialize the autovacuum subsystem (again, no process start yet) @@ -4029,12 +4033,14 @@ PostmasterStateMachine(void) ereport(LOG, (errmsg("all server processes terminated; reinitializing"))); - /* remove leftover temporary files after a crash */ + /* + * Remove leftover temporary files after a crash. + * + * Note that this just stages the pgsql_tmp directories for deletion. + * The custodian process is responsible for actually removing the files. + */ if (remove_temp_files_after_crash) - { StagePgTempFilesForRemoval(); - RemovePgTempFiles(); - } /* allow background workers to immediately restart */ ResetBackgroundWorkerCrashTimes(); @@ -4047,6 +4053,14 @@ PostmasterStateMachine(void) /* re-create shared memory and semaphores */ CreateSharedMemoryAndSemaphores(); + /* + * Now that shared memory is initialized, notify the custodian to clean + * up the staged pgsql_tmp directories. We do this even if + * remove_temp_files_after_crash is false so that any previously staged + * directories are eventually cleaned up. + */ + RequestCustodian(CUSTODIAN_REMOVE_TEMP_FILES, false, (Datum) 0); + StartupPID = StartupDataBase(); Assert(StartupPID != 0); StartupStatus = STARTUP_RUNNING; diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c index c8ffb53b2c..64546ca738 100644 --- a/src/backend/storage/file/fd.c +++ b/src/backend/storage/file/fd.c @@ -97,6 +97,7 @@ #include "pgstat.h" #include "port/pg_iovec.h" #include "portability/mem.h" +#include "postmaster/custodian.h" #include "postmaster/startup.h" #include "storage/fd.h" #include "storage/ipc.h" @@ -1565,9 +1566,9 @@ PathNameOpenFilePerm(const char *fileName, int fileFlags, mode_t fileMode) * * Directories created within the top-level temporary directory should begin * with PG_TEMP_FILE_PREFIX, so that they can be identified as temporary and - * deleted at startup by RemovePgTempFiles(). Further subdirectories below - * that do not need any particular prefix. -*/ + * deleted by RemovePgTempFiles(). Further subdirectories below that do not + * need any particular prefix. + */ void PathNameCreateTemporaryDir(const char *basedir, const char *directory) { @@ -1765,9 +1766,9 @@ OpenTemporaryFileInTablespace(Oid tblspcOid, bool rejectError) * * If the file is inside the top-level temporary directory, its name should * begin with PG_TEMP_FILE_PREFIX so that it can be identified as temporary - * and deleted at startup by RemovePgTempFiles(). Alternatively, it can be - * inside a directory created with PathNameCreateTemporaryDir(), in which case - * the prefix isn't needed. + * and deleted by RemovePgTempFiles(). Alternatively, it can be inside a + * directory created with PathNameCreateTemporaryDir(), in which case the prefix + * isn't needed. */ File PathNameCreateTemporaryFile(const char *path, bool error_on_failure) diff --git a/src/include/postmaster/custodian.h b/src/include/postmaster/custodian.h index 170ca61a21..80890ceadd 100644 --- a/src/include/postmaster/custodian.h +++ b/src/include/postmaster/custodian.h @@ -18,7 +18,7 @@ */ typedef enum CustodianTask { - FAKE_TASK, /* placeholder until we have a real task */ + CUSTODIAN_REMOVE_TEMP_FILES, NUM_CUSTODIAN_TASKS, /* new tasks go above */ INVALID_CUSTODIAN_TASK -- 2.25.1 --envbJBWh7q8WU6mo Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v11-0005-Move-removal-of-old-serialized-snapshots-to-cust.patch" ^ permalink raw reply [nested|flat] 12+ messages in thread
* [PATCH v6 4/6] Move pgsql_tmp file removal to custodian process. @ 2021-12-06 05:42 Nathan Bossart <bossartn@amazon.com> 0 siblings, 0 replies; 12+ messages in thread From: Nathan Bossart @ 2021-12-06 05:42 UTC (permalink / raw) With this change, startup (and restart after a crash) simply renames the pgsql_tmp directories, and the custodian process actually removes all the files in the staged directories as well as the staged directories themselves. This should help avoid long startup delays due to many leftover temporary files. --- src/backend/postmaster/custodian.c | 14 +++++++++++++- src/backend/postmaster/postmaster.c | 14 +++++++++----- src/backend/storage/file/fd.c | 21 +++++++++++++++------ src/include/postmaster/custodian.h | 3 +++ 4 files changed, 40 insertions(+), 12 deletions(-) diff --git a/src/backend/postmaster/custodian.c b/src/backend/postmaster/custodian.c index db00282658..a0ec94ea5c 100644 --- a/src/backend/postmaster/custodian.c +++ b/src/backend/postmaster/custodian.c @@ -196,7 +196,19 @@ CustodianMain(void) CustodianShmem->cust_flags = 0; SpinLockRelease(&CustodianShmem->cust_lck); - /* TODO: offloaded tasks go here */ + /* + * Remove any pgsql_tmp directories that have been staged for deletion. + * Since pgsql_tmp directories can accumulate many files, removing all + * of the files during startup (which we used to do) can take a very + * long time. To avoid delaying startup, we simply have startup rename + * the temporary directories, and we clean them up here. + * + * pgsql_tmp directories are not staged or cleaned in single-user mode, + * so we don't need any extra handling outside of the custodian process + * for this. + */ + if (flags & CUSTODIAN_REMOVE_TEMP_FILES) + RemovePgTempFiles(false, false); /* Calculate how long to sleep */ end_time = (pg_time_t) time(NULL); diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index 82aa0c6307..b67f8828df 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -1401,9 +1401,11 @@ PostmasterMain(int argc, char *argv[]) /* * Remove old temporary files. At this point there can be no other * Postgres processes running in this directory, so this should be safe. + * + * Note that this just stages the pgsql_tmp directories for deletion. The + * custodian process is responsible for actually removing the files. */ RemovePgTempFiles(true, true); - RemovePgTempFiles(false, false); /* * Initialize the autovacuum subsystem (again, no process start yet) @@ -4052,12 +4054,14 @@ PostmasterStateMachine(void) ereport(LOG, (errmsg("all server processes terminated; reinitializing"))); - /* remove leftover temporary files after a crash */ + /* + * Remove leftover temporary files after a crash. + * + * Note that this just stages the pgsql_tmp directories for deletion. + * The custodian process is responsible for actually removing the files. + */ if (remove_temp_files_after_crash) - { RemovePgTempFiles(true, true); - RemovePgTempFiles(false, false); - } /* allow background workers to immediately restart */ ResetBackgroundWorkerCrashTimes(); diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c index 79ca3a5be9..46dc1925a2 100644 --- a/src/backend/storage/file/fd.c +++ b/src/backend/storage/file/fd.c @@ -97,6 +97,7 @@ #include "pgstat.h" #include "port/pg_iovec.h" #include "portability/mem.h" +#include "postmaster/custodian.h" #include "postmaster/startup.h" #include "storage/fd.h" #include "storage/ipc.h" @@ -1640,9 +1641,9 @@ PathNameOpenFilePerm(const char *fileName, int fileFlags, mode_t fileMode) * * Directories created within the top-level temporary directory should begin * with PG_TEMP_FILE_PREFIX, so that they can be identified as temporary and - * deleted at startup by RemovePgTempFiles(). Further subdirectories below - * that do not need any particular prefix. -*/ + * deleted by RemovePgTempFiles(). Further subdirectories below that do not + * need any particular prefix. + */ void PathNameCreateTemporaryDir(const char *basedir, const char *directory) { @@ -1840,9 +1841,9 @@ OpenTemporaryFileInTablespace(Oid tblspcOid, bool rejectError) * * If the file is inside the top-level temporary directory, its name should * begin with PG_TEMP_FILE_PREFIX so that it can be identified as temporary - * and deleted at startup by RemovePgTempFiles(). Alternatively, it can be - * inside a directory created with PathNameCreateTemporaryDir(), in which case - * the prefix isn't needed. + * and deleted by RemovePgTempFiles(). Alternatively, it can be inside a + * directory created with PathNameCreateTemporaryDir(), in which case the prefix + * isn't needed. */ File PathNameCreateTemporaryFile(const char *path, bool error_on_failure) @@ -3211,6 +3212,14 @@ RemovePgTempFiles(bool stage, bool remove_relation_files) * would create a race condition. It's done separately, earlier in * postmaster startup. */ + + /* + * If we just staged some pgsql_tmp directories for removal, wake up the + * custodian process so that it deletes all the files in the staged + * directories as well as the directories themselves. + */ + if (stage) + RequestCustodian(CUSTODIAN_REMOVE_TEMP_FILES); } /* diff --git a/src/include/postmaster/custodian.h b/src/include/postmaster/custodian.h index c95a7c7de6..f6dcd9ddef 100644 --- a/src/include/postmaster/custodian.h +++ b/src/include/postmaster/custodian.h @@ -17,4 +17,7 @@ extern Size CustodianShmemSize(void); extern void CustodianShmemInit(void); extern void RequestCustodian(int flags); +/* flags for RequestCustodian() */ +#define CUSTODIAN_REMOVE_TEMP_FILES 0x0001 + #endif /* _CUSTODIAN_H */ -- 2.25.1 --liOOAslEiF7prFVr Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v6-0005-Move-removal-of-old-serialized-snapshots-to-custo.patch" ^ permalink raw reply [nested|flat] 12+ messages in thread
* [PATCH v4 4/8] Move pgsql_tmp file removal to custodian process. @ 2021-12-06 05:42 Nathan Bossart <bossartn@amazon.com> 0 siblings, 0 replies; 12+ messages in thread From: Nathan Bossart @ 2021-12-06 05:42 UTC (permalink / raw) With this change, startup (and restart after a crash) simply renames the pgsql_tmp directories, and the custodian process actually removes all the files in the staged directories as well as the staged directories themselves. This should help avoid long startup delays due to many leftover temporary files. --- src/backend/postmaster/custodian.c | 13 +++++++++++- src/backend/postmaster/postmaster.c | 14 ++++++++----- src/backend/storage/file/fd.c | 32 +++++++++++++++++++++-------- 3 files changed, 44 insertions(+), 15 deletions(-) diff --git a/src/backend/postmaster/custodian.c b/src/backend/postmaster/custodian.c index dd86f0f5ce..79bc4a7065 100644 --- a/src/backend/postmaster/custodian.c +++ b/src/backend/postmaster/custodian.c @@ -194,7 +194,18 @@ CustodianMain(void) start_time = (pg_time_t) time(NULL); - /* TODO: offloaded tasks go here */ + /* + * Remove any pgsql_tmp directories that have been staged for deletion. + * Since pgsql_tmp directories can accumulate many files, removing all + * of the files during startup (which we used to do) can take a very + * long time. To avoid delaying startup, we simply have startup rename + * the temporary directories, and we clean them up here. + * + * pgsql_tmp directories are not staged or cleaned in single-user mode, + * so we don't need any extra handling outside of the custodian process + * for this. + */ + RemovePgTempFiles(false, false); /* Calculate how long to sleep */ end_time = (pg_time_t) time(NULL); diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index a6bc9feabd..a8303a6482 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -1389,9 +1389,11 @@ PostmasterMain(int argc, char *argv[]) /* * Remove old temporary files. At this point there can be no other * Postgres processes running in this directory, so this should be safe. + * + * Note that this just stages the pgsql_tmp directories for deletion. The + * custodian process is responsible for actually removing the files. */ RemovePgTempFiles(true, true); - RemovePgTempFiles(false, false); /* * Initialize stats collection subsystem (this does NOT start the @@ -4137,12 +4139,14 @@ PostmasterStateMachine(void) ereport(LOG, (errmsg("all server processes terminated; reinitializing"))); - /* remove leftover temporary files after a crash */ + /* + * Remove leftover temporary files after a crash. + * + * Note that this just stages the pgsql_tmp directories for deletion. + * The custodian process is responsible for actually removing the files. + */ if (remove_temp_files_after_crash) - { RemovePgTempFiles(true, true); - RemovePgTempFiles(false, false); - } /* allow background workers to immediately restart */ ResetBackgroundWorkerCrashTimes(); diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c index d3019a4b67..5d39a31d14 100644 --- a/src/backend/storage/file/fd.c +++ b/src/backend/storage/file/fd.c @@ -97,9 +97,12 @@ #include "pgstat.h" #include "port/pg_iovec.h" #include "portability/mem.h" +#include "postmaster/interrupt.h" #include "postmaster/startup.h" #include "storage/fd.h" #include "storage/ipc.h" +#include "storage/latch.h" +#include "storage/proc.h" #include "utils/guc.h" #include "utils/resowner_private.h" @@ -1640,9 +1643,9 @@ PathNameOpenFilePerm(const char *fileName, int fileFlags, mode_t fileMode) * * Directories created within the top-level temporary directory should begin * with PG_TEMP_FILE_PREFIX, so that they can be identified as temporary and - * deleted at startup by RemovePgTempFiles(). Further subdirectories below - * that do not need any particular prefix. -*/ + * deleted by RemovePgTempFiles(). Further subdirectories below that do not + * need any particular prefix. + */ void PathNameCreateTemporaryDir(const char *basedir, const char *directory) { @@ -1840,9 +1843,9 @@ OpenTemporaryFileInTablespace(Oid tblspcOid, bool rejectError) * * If the file is inside the top-level temporary directory, its name should * begin with PG_TEMP_FILE_PREFIX so that it can be identified as temporary - * and deleted at startup by RemovePgTempFiles(). Alternatively, it can be - * inside a directory created with PathNameCreateTemporaryDir(), in which case - * the prefix isn't needed. + * and deleted by RemovePgTempFiles(). Alternatively, it can be inside a + * directory created with PathNameCreateTemporaryDir(), in which case the prefix + * isn't needed. */ File PathNameCreateTemporaryFile(const char *path, bool error_on_failure) @@ -3175,7 +3178,8 @@ RemovePgTempFiles(bool stage, bool remove_relation_files) */ spc_dir = AllocateDir("pg_tblspc"); - while ((spc_de = ReadDirExtended(spc_dir, "pg_tblspc", LOG)) != NULL) + while (!ShutdownRequestPending && + (spc_de = ReadDirExtended(spc_dir, "pg_tblspc", LOG)) != NULL) { if (strcmp(spc_de->d_name, ".") == 0 || strcmp(spc_de->d_name, "..") == 0) @@ -3211,6 +3215,14 @@ RemovePgTempFiles(bool stage, bool remove_relation_files) * would create a race condition. It's done separately, earlier in * postmaster startup. */ + + /* + * If we just staged some pgsql_tmp directories for removal, wake up the + * custodian process so that it deletes all the files in the staged + * directories as well as the directories themselves. + */ + if (stage && ProcGlobal->custodianLatch) + SetLatch(ProcGlobal->custodianLatch); } /* @@ -3315,7 +3327,8 @@ RemoveStagedPgTempDirs(const char *spc_dir) struct dirent *de; dir = AllocateDir(spc_dir); - while ((de = ReadDirExtended(dir, spc_dir, LOG)) != NULL) + while (!ShutdownRequestPending && + (de = ReadDirExtended(dir, spc_dir, LOG)) != NULL) { if (strncmp(de->d_name, PG_TEMP_DIR_TO_REMOVE_PREFIX, strlen(PG_TEMP_DIR_TO_REMOVE_PREFIX)) != 0) @@ -3354,7 +3367,8 @@ RemovePgTempDir(const char *tmpdirname, bool missing_ok, bool unlink_all) if (temp_dir == NULL && errno == ENOENT && missing_ok) return; - while ((temp_de = ReadDirExtended(temp_dir, tmpdirname, LOG)) != NULL) + while (!ShutdownRequestPending && + (temp_de = ReadDirExtended(temp_dir, tmpdirname, LOG)) != NULL) { if (strcmp(temp_de->d_name, ".") == 0 || strcmp(temp_de->d_name, "..") == 0) -- 2.25.1 --BXVAT5kNtrzKuDFl Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v4-0005-Move-removal-of-old-serialized-snapshots-to-custo.patch" ^ permalink raw reply [nested|flat] 12+ messages in thread
* [PATCH v8 4/6] Move pgsql_tmp file removal to custodian process. @ 2021-12-06 05:42 Nathan Bossart <bossartn@amazon.com> 0 siblings, 0 replies; 12+ messages in thread From: Nathan Bossart @ 2021-12-06 05:42 UTC (permalink / raw) With this change, startup (and restart after a crash) simply renames the pgsql_tmp directories, and the custodian process actually removes all the files in the staged directories as well as the staged directories themselves. This should help avoid long startup delays due to many leftover temporary files. --- src/backend/postmaster/custodian.c | 1 + src/backend/postmaster/postmaster.c | 24 +++++++++++++++++++----- src/backend/storage/file/fd.c | 13 +++++++------ src/include/postmaster/custodian.h | 2 +- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/backend/postmaster/custodian.c b/src/backend/postmaster/custodian.c index e90f5d0d1f..fe1f48844e 100644 --- a/src/backend/postmaster/custodian.c +++ b/src/backend/postmaster/custodian.c @@ -70,6 +70,7 @@ struct cust_task_funcs_entry * whether the task is already enqueued. */ static const struct cust_task_funcs_entry cust_task_functions[] = { + {CUSTODIAN_REMOVE_TEMP_FILES, RemovePgTempFiles, NULL}, {INVALID_CUSTODIAN_TASK, NULL, NULL} /* must be last */ }; diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index c3a466552e..151375be03 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -112,6 +112,7 @@ #include "postmaster/autovacuum.h" #include "postmaster/auxprocess.h" #include "postmaster/bgworker_internals.h" +#include "postmaster/custodian.h" #include "postmaster/fork_process.h" #include "postmaster/interrupt.h" #include "postmaster/pgarch.h" @@ -1403,9 +1404,12 @@ PostmasterMain(int argc, char *argv[]) /* * Remove old temporary files. At this point there can be no other * Postgres processes running in this directory, so this should be safe. + * + * Note that this just stages the pgsql_tmp directories for deletion. The + * custodian process is responsible for actually removing the files. */ StagePgTempFilesForRemoval(); - RemovePgTempFiles(); + RequestCustodian(CUSTODIAN_REMOVE_TEMP_FILES, false, (Datum) 0); /* * Initialize the autovacuum subsystem (again, no process start yet) @@ -4038,12 +4042,14 @@ PostmasterStateMachine(void) ereport(LOG, (errmsg("all server processes terminated; reinitializing"))); - /* remove leftover temporary files after a crash */ + /* + * Remove leftover temporary files after a crash. + * + * Note that this just stages the pgsql_tmp directories for deletion. + * The custodian process is responsible for actually removing the files. + */ if (remove_temp_files_after_crash) - { StagePgTempFilesForRemoval(); - RemovePgTempFiles(); - } /* allow background workers to immediately restart */ ResetBackgroundWorkerCrashTimes(); @@ -4056,6 +4062,14 @@ PostmasterStateMachine(void) /* re-create shared memory and semaphores */ CreateSharedMemoryAndSemaphores(); + /* + * Now that shared memory is initialized, notify the custodian to clean + * up the staged pgsql_tmp directories. We do this even if + * remove_temp_files_after_crash is false so that any previously staged + * directories are eventually cleaned up. + */ + RequestCustodian(CUSTODIAN_REMOVE_TEMP_FILES, false, (Datum) 0); + StartupPID = StartupDataBase(); Assert(StartupPID != 0); StartupStatus = STARTUP_RUNNING; diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c index a9312b83aa..c705a77e46 100644 --- a/src/backend/storage/file/fd.c +++ b/src/backend/storage/file/fd.c @@ -99,6 +99,7 @@ #include "pgstat.h" #include "port/pg_iovec.h" #include "portability/mem.h" +#include "postmaster/custodian.h" #include "postmaster/startup.h" #include "storage/fd.h" #include "storage/ipc.h" @@ -1567,9 +1568,9 @@ PathNameOpenFilePerm(const char *fileName, int fileFlags, mode_t fileMode) * * Directories created within the top-level temporary directory should begin * with PG_TEMP_FILE_PREFIX, so that they can be identified as temporary and - * deleted at startup by RemovePgTempFiles(). Further subdirectories below - * that do not need any particular prefix. -*/ + * deleted by RemovePgTempFiles(). Further subdirectories below that do not + * need any particular prefix. + */ void PathNameCreateTemporaryDir(const char *basedir, const char *directory) { @@ -1767,9 +1768,9 @@ OpenTemporaryFileInTablespace(Oid tblspcOid, bool rejectError) * * If the file is inside the top-level temporary directory, its name should * begin with PG_TEMP_FILE_PREFIX so that it can be identified as temporary - * and deleted at startup by RemovePgTempFiles(). Alternatively, it can be - * inside a directory created with PathNameCreateTemporaryDir(), in which case - * the prefix isn't needed. + * and deleted by RemovePgTempFiles(). Alternatively, it can be inside a + * directory created with PathNameCreateTemporaryDir(), in which case the prefix + * isn't needed. */ File PathNameCreateTemporaryFile(const char *path, bool error_on_failure) diff --git a/src/include/postmaster/custodian.h b/src/include/postmaster/custodian.h index 170ca61a21..80890ceadd 100644 --- a/src/include/postmaster/custodian.h +++ b/src/include/postmaster/custodian.h @@ -18,7 +18,7 @@ */ typedef enum CustodianTask { - FAKE_TASK, /* placeholder until we have a real task */ + CUSTODIAN_REMOVE_TEMP_FILES, NUM_CUSTODIAN_TASKS, /* new tasks go above */ INVALID_CUSTODIAN_TASK -- 2.25.1 --X1bOJ3K7DJ5YkBrT Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v8-0005-Move-removal-of-old-serialized-snapshots-to-custo.patch" ^ permalink raw reply [nested|flat] 12+ messages in thread
* [PATCH v9 4/6] Move pgsql_tmp file removal to custodian process. @ 2021-12-06 05:42 Nathan Bossart <bossartn@amazon.com> 0 siblings, 0 replies; 12+ messages in thread From: Nathan Bossart @ 2021-12-06 05:42 UTC (permalink / raw) With this change, startup (and restart after a crash) simply renames the pgsql_tmp directories, and the custodian process actually removes all the files in the staged directories as well as the staged directories themselves. This should help avoid long startup delays due to many leftover temporary files. --- src/backend/postmaster/custodian.c | 1 + src/backend/postmaster/postmaster.c | 24 +++++++++++++++++++----- src/backend/storage/file/fd.c | 13 +++++++------ src/include/postmaster/custodian.h | 2 +- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/backend/postmaster/custodian.c b/src/backend/postmaster/custodian.c index e90f5d0d1f..fe1f48844e 100644 --- a/src/backend/postmaster/custodian.c +++ b/src/backend/postmaster/custodian.c @@ -70,6 +70,7 @@ struct cust_task_funcs_entry * whether the task is already enqueued. */ static const struct cust_task_funcs_entry cust_task_functions[] = { + {CUSTODIAN_REMOVE_TEMP_FILES, RemovePgTempFiles, NULL}, {INVALID_CUSTODIAN_TASK, NULL, NULL} /* must be last */ }; diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index 6edae456f1..c0500fe4df 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -109,6 +109,7 @@ #include "postmaster/autovacuum.h" #include "postmaster/auxprocess.h" #include "postmaster/bgworker_internals.h" +#include "postmaster/custodian.h" #include "postmaster/fork_process.h" #include "postmaster/interrupt.h" #include "postmaster/pgarch.h" @@ -1398,9 +1399,12 @@ PostmasterMain(int argc, char *argv[]) /* * Remove old temporary files. At this point there can be no other * Postgres processes running in this directory, so this should be safe. + * + * Note that this just stages the pgsql_tmp directories for deletion. The + * custodian process is responsible for actually removing the files. */ StagePgTempFilesForRemoval(); - RemovePgTempFiles(); + RequestCustodian(CUSTODIAN_REMOVE_TEMP_FILES, false, (Datum) 0); /* * Initialize the autovacuum subsystem (again, no process start yet) @@ -4033,12 +4037,14 @@ PostmasterStateMachine(void) ereport(LOG, (errmsg("all server processes terminated; reinitializing"))); - /* remove leftover temporary files after a crash */ + /* + * Remove leftover temporary files after a crash. + * + * Note that this just stages the pgsql_tmp directories for deletion. + * The custodian process is responsible for actually removing the files. + */ if (remove_temp_files_after_crash) - { StagePgTempFilesForRemoval(); - RemovePgTempFiles(); - } /* allow background workers to immediately restart */ ResetBackgroundWorkerCrashTimes(); @@ -4051,6 +4057,14 @@ PostmasterStateMachine(void) /* re-create shared memory and semaphores */ CreateSharedMemoryAndSemaphores(); + /* + * Now that shared memory is initialized, notify the custodian to clean + * up the staged pgsql_tmp directories. We do this even if + * remove_temp_files_after_crash is false so that any previously staged + * directories are eventually cleaned up. + */ + RequestCustodian(CUSTODIAN_REMOVE_TEMP_FILES, false, (Datum) 0); + StartupPID = StartupDataBase(); Assert(StartupPID != 0); StartupStatus = STARTUP_RUNNING; diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c index a687bd05d7..067e5920d6 100644 --- a/src/backend/storage/file/fd.c +++ b/src/backend/storage/file/fd.c @@ -97,6 +97,7 @@ #include "pgstat.h" #include "port/pg_iovec.h" #include "portability/mem.h" +#include "postmaster/custodian.h" #include "postmaster/startup.h" #include "storage/fd.h" #include "storage/ipc.h" @@ -1565,9 +1566,9 @@ PathNameOpenFilePerm(const char *fileName, int fileFlags, mode_t fileMode) * * Directories created within the top-level temporary directory should begin * with PG_TEMP_FILE_PREFIX, so that they can be identified as temporary and - * deleted at startup by RemovePgTempFiles(). Further subdirectories below - * that do not need any particular prefix. -*/ + * deleted by RemovePgTempFiles(). Further subdirectories below that do not + * need any particular prefix. + */ void PathNameCreateTemporaryDir(const char *basedir, const char *directory) { @@ -1765,9 +1766,9 @@ OpenTemporaryFileInTablespace(Oid tblspcOid, bool rejectError) * * If the file is inside the top-level temporary directory, its name should * begin with PG_TEMP_FILE_PREFIX so that it can be identified as temporary - * and deleted at startup by RemovePgTempFiles(). Alternatively, it can be - * inside a directory created with PathNameCreateTemporaryDir(), in which case - * the prefix isn't needed. + * and deleted by RemovePgTempFiles(). Alternatively, it can be inside a + * directory created with PathNameCreateTemporaryDir(), in which case the prefix + * isn't needed. */ File PathNameCreateTemporaryFile(const char *path, bool error_on_failure) diff --git a/src/include/postmaster/custodian.h b/src/include/postmaster/custodian.h index 170ca61a21..80890ceadd 100644 --- a/src/include/postmaster/custodian.h +++ b/src/include/postmaster/custodian.h @@ -18,7 +18,7 @@ */ typedef enum CustodianTask { - FAKE_TASK, /* placeholder until we have a real task */ + CUSTODIAN_REMOVE_TEMP_FILES, NUM_CUSTODIAN_TASKS, /* new tasks go above */ INVALID_CUSTODIAN_TASK -- 2.25.1 --y0ulUmNC+osPPQO6 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v9-0005-Move-removal-of-old-serialized-snapshots-to-custo.patch" ^ permalink raw reply [nested|flat] 12+ messages in thread
* [PATCH v7 4/6] Move pgsql_tmp file removal to custodian process. @ 2021-12-06 05:42 Nathan Bossart <bossartn@amazon.com> 0 siblings, 0 replies; 12+ messages in thread From: Nathan Bossart @ 2021-12-06 05:42 UTC (permalink / raw) With this change, startup (and restart after a crash) simply renames the pgsql_tmp directories, and the custodian process actually removes all the files in the staged directories as well as the staged directories themselves. This should help avoid long startup delays due to many leftover temporary files. --- src/backend/postmaster/custodian.c | 1 + src/backend/postmaster/postmaster.c | 24 +++++++++++++++++++----- src/backend/storage/file/fd.c | 13 +++++++------ src/include/postmaster/custodian.h | 2 +- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/backend/postmaster/custodian.c b/src/backend/postmaster/custodian.c index e90f5d0d1f..fe1f48844e 100644 --- a/src/backend/postmaster/custodian.c +++ b/src/backend/postmaster/custodian.c @@ -70,6 +70,7 @@ struct cust_task_funcs_entry * whether the task is already enqueued. */ static const struct cust_task_funcs_entry cust_task_functions[] = { + {CUSTODIAN_REMOVE_TEMP_FILES, RemovePgTempFiles, NULL}, {INVALID_CUSTODIAN_TASK, NULL, NULL} /* must be last */ }; diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index 50f348c42c..ed120eb836 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -112,6 +112,7 @@ #include "postmaster/autovacuum.h" #include "postmaster/auxprocess.h" #include "postmaster/bgworker_internals.h" +#include "postmaster/custodian.h" #include "postmaster/fork_process.h" #include "postmaster/interrupt.h" #include "postmaster/pgarch.h" @@ -1400,9 +1401,12 @@ PostmasterMain(int argc, char *argv[]) /* * Remove old temporary files. At this point there can be no other * Postgres processes running in this directory, so this should be safe. + * + * Note that this just stages the pgsql_tmp directories for deletion. The + * custodian process is responsible for actually removing the files. */ StagePgTempFilesForRemoval(); - RemovePgTempFiles(); + RequestCustodian(CUSTODIAN_REMOVE_TEMP_FILES, false, (Datum) 0); /* * Initialize the autovacuum subsystem (again, no process start yet) @@ -4051,12 +4055,14 @@ PostmasterStateMachine(void) ereport(LOG, (errmsg("all server processes terminated; reinitializing"))); - /* remove leftover temporary files after a crash */ + /* + * Remove leftover temporary files after a crash. + * + * Note that this just stages the pgsql_tmp directories for deletion. + * The custodian process is responsible for actually removing the files. + */ if (remove_temp_files_after_crash) - { StagePgTempFilesForRemoval(); - RemovePgTempFiles(); - } /* allow background workers to immediately restart */ ResetBackgroundWorkerCrashTimes(); @@ -4068,6 +4074,14 @@ PostmasterStateMachine(void) reset_shared(); + /* + * Now that shared memory is initialized, notify the custodian to clean + * up the staged pgsql_tmp directories. We do this even if + * remove_temp_files_after_crash is false so that any previously staged + * directories are eventually cleaned up. + */ + RequestCustodian(CUSTODIAN_REMOVE_TEMP_FILES, false, (Datum) 0); + StartupPID = StartupDataBase(); Assert(StartupPID != 0); StartupStatus = STARTUP_RUNNING; diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c index 02c48a668b..2f93f71d44 100644 --- a/src/backend/storage/file/fd.c +++ b/src/backend/storage/file/fd.c @@ -99,6 +99,7 @@ #include "pgstat.h" #include "port/pg_iovec.h" #include "portability/mem.h" +#include "postmaster/custodian.h" #include "postmaster/startup.h" #include "storage/fd.h" #include "storage/ipc.h" @@ -1579,9 +1580,9 @@ PathNameOpenFilePerm(const char *fileName, int fileFlags, mode_t fileMode) * * Directories created within the top-level temporary directory should begin * with PG_TEMP_FILE_PREFIX, so that they can be identified as temporary and - * deleted at startup by RemovePgTempFiles(). Further subdirectories below - * that do not need any particular prefix. -*/ + * deleted by RemovePgTempFiles(). Further subdirectories below that do not + * need any particular prefix. + */ void PathNameCreateTemporaryDir(const char *basedir, const char *directory) { @@ -1779,9 +1780,9 @@ OpenTemporaryFileInTablespace(Oid tblspcOid, bool rejectError) * * If the file is inside the top-level temporary directory, its name should * begin with PG_TEMP_FILE_PREFIX so that it can be identified as temporary - * and deleted at startup by RemovePgTempFiles(). Alternatively, it can be - * inside a directory created with PathNameCreateTemporaryDir(), in which case - * the prefix isn't needed. + * and deleted by RemovePgTempFiles(). Alternatively, it can be inside a + * directory created with PathNameCreateTemporaryDir(), in which case the prefix + * isn't needed. */ File PathNameCreateTemporaryFile(const char *path, bool error_on_failure) diff --git a/src/include/postmaster/custodian.h b/src/include/postmaster/custodian.h index 170ca61a21..80890ceadd 100644 --- a/src/include/postmaster/custodian.h +++ b/src/include/postmaster/custodian.h @@ -18,7 +18,7 @@ */ typedef enum CustodianTask { - FAKE_TASK, /* placeholder until we have a real task */ + CUSTODIAN_REMOVE_TEMP_FILES, NUM_CUSTODIAN_TASKS, /* new tasks go above */ INVALID_CUSTODIAN_TASK -- 2.25.1 --/04w6evG8XlLl3ft Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v7-0005-Move-removal-of-old-serialized-snapshots-to-custo.patch" ^ permalink raw reply [nested|flat] 12+ messages in thread
* [PATCH v5 4/8] Move pgsql_tmp file removal to custodian process. @ 2021-12-06 05:42 Nathan Bossart <bossartn@amazon.com> 0 siblings, 0 replies; 12+ messages in thread From: Nathan Bossart @ 2021-12-06 05:42 UTC (permalink / raw) With this change, startup (and restart after a crash) simply renames the pgsql_tmp directories, and the custodian process actually removes all the files in the staged directories as well as the staged directories themselves. This should help avoid long startup delays due to many leftover temporary files. --- src/backend/postmaster/custodian.c | 13 +++++++++++- src/backend/postmaster/postmaster.c | 14 ++++++++----- src/backend/storage/file/fd.c | 32 +++++++++++++++++++++-------- 3 files changed, 44 insertions(+), 15 deletions(-) diff --git a/src/backend/postmaster/custodian.c b/src/backend/postmaster/custodian.c index 5f2b647544..5bad0af474 100644 --- a/src/backend/postmaster/custodian.c +++ b/src/backend/postmaster/custodian.c @@ -195,7 +195,18 @@ CustodianMain(void) start_time = (pg_time_t) time(NULL); - /* TODO: offloaded tasks go here */ + /* + * Remove any pgsql_tmp directories that have been staged for deletion. + * Since pgsql_tmp directories can accumulate many files, removing all + * of the files during startup (which we used to do) can take a very + * long time. To avoid delaying startup, we simply have startup rename + * the temporary directories, and we clean them up here. + * + * pgsql_tmp directories are not staged or cleaned in single-user mode, + * so we don't need any extra handling outside of the custodian process + * for this. + */ + RemovePgTempFiles(false, false); /* Calculate how long to sleep */ end_time = (pg_time_t) time(NULL); diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index 8248d55e23..56b87d79a3 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -1390,9 +1390,11 @@ PostmasterMain(int argc, char *argv[]) /* * Remove old temporary files. At this point there can be no other * Postgres processes running in this directory, so this should be safe. + * + * Note that this just stages the pgsql_tmp directories for deletion. The + * custodian process is responsible for actually removing the files. */ RemovePgTempFiles(true, true); - RemovePgTempFiles(false, false); /* * Initialize stats collection subsystem (this does NOT start the @@ -4138,12 +4140,14 @@ PostmasterStateMachine(void) ereport(LOG, (errmsg("all server processes terminated; reinitializing"))); - /* remove leftover temporary files after a crash */ + /* + * Remove leftover temporary files after a crash. + * + * Note that this just stages the pgsql_tmp directories for deletion. + * The custodian process is responsible for actually removing the files. + */ if (remove_temp_files_after_crash) - { RemovePgTempFiles(true, true); - RemovePgTempFiles(false, false); - } /* allow background workers to immediately restart */ ResetBackgroundWorkerCrashTimes(); diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c index d3019a4b67..5d39a31d14 100644 --- a/src/backend/storage/file/fd.c +++ b/src/backend/storage/file/fd.c @@ -97,9 +97,12 @@ #include "pgstat.h" #include "port/pg_iovec.h" #include "portability/mem.h" +#include "postmaster/interrupt.h" #include "postmaster/startup.h" #include "storage/fd.h" #include "storage/ipc.h" +#include "storage/latch.h" +#include "storage/proc.h" #include "utils/guc.h" #include "utils/resowner_private.h" @@ -1640,9 +1643,9 @@ PathNameOpenFilePerm(const char *fileName, int fileFlags, mode_t fileMode) * * Directories created within the top-level temporary directory should begin * with PG_TEMP_FILE_PREFIX, so that they can be identified as temporary and - * deleted at startup by RemovePgTempFiles(). Further subdirectories below - * that do not need any particular prefix. -*/ + * deleted by RemovePgTempFiles(). Further subdirectories below that do not + * need any particular prefix. + */ void PathNameCreateTemporaryDir(const char *basedir, const char *directory) { @@ -1840,9 +1843,9 @@ OpenTemporaryFileInTablespace(Oid tblspcOid, bool rejectError) * * If the file is inside the top-level temporary directory, its name should * begin with PG_TEMP_FILE_PREFIX so that it can be identified as temporary - * and deleted at startup by RemovePgTempFiles(). Alternatively, it can be - * inside a directory created with PathNameCreateTemporaryDir(), in which case - * the prefix isn't needed. + * and deleted by RemovePgTempFiles(). Alternatively, it can be inside a + * directory created with PathNameCreateTemporaryDir(), in which case the prefix + * isn't needed. */ File PathNameCreateTemporaryFile(const char *path, bool error_on_failure) @@ -3175,7 +3178,8 @@ RemovePgTempFiles(bool stage, bool remove_relation_files) */ spc_dir = AllocateDir("pg_tblspc"); - while ((spc_de = ReadDirExtended(spc_dir, "pg_tblspc", LOG)) != NULL) + while (!ShutdownRequestPending && + (spc_de = ReadDirExtended(spc_dir, "pg_tblspc", LOG)) != NULL) { if (strcmp(spc_de->d_name, ".") == 0 || strcmp(spc_de->d_name, "..") == 0) @@ -3211,6 +3215,14 @@ RemovePgTempFiles(bool stage, bool remove_relation_files) * would create a race condition. It's done separately, earlier in * postmaster startup. */ + + /* + * If we just staged some pgsql_tmp directories for removal, wake up the + * custodian process so that it deletes all the files in the staged + * directories as well as the directories themselves. + */ + if (stage && ProcGlobal->custodianLatch) + SetLatch(ProcGlobal->custodianLatch); } /* @@ -3315,7 +3327,8 @@ RemoveStagedPgTempDirs(const char *spc_dir) struct dirent *de; dir = AllocateDir(spc_dir); - while ((de = ReadDirExtended(dir, spc_dir, LOG)) != NULL) + while (!ShutdownRequestPending && + (de = ReadDirExtended(dir, spc_dir, LOG)) != NULL) { if (strncmp(de->d_name, PG_TEMP_DIR_TO_REMOVE_PREFIX, strlen(PG_TEMP_DIR_TO_REMOVE_PREFIX)) != 0) @@ -3354,7 +3367,8 @@ RemovePgTempDir(const char *tmpdirname, bool missing_ok, bool unlink_all) if (temp_dir == NULL && errno == ENOENT && missing_ok) return; - while ((temp_de = ReadDirExtended(temp_dir, tmpdirname, LOG)) != NULL) + while (!ShutdownRequestPending && + (temp_de = ReadDirExtended(temp_dir, tmpdirname, LOG)) != NULL) { if (strcmp(temp_de->d_name, ".") == 0 || strcmp(temp_de->d_name, "..") == 0) -- 2.25.1 --2oS5YaxWCcQjTEyO Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v5-0005-Move-removal-of-old-serialized-snapshots-to-custo.patch" ^ permalink raw reply [nested|flat] 12+ messages in thread
end of thread, other threads:[~2021-12-06 05:42 UTC | newest] Thread overview: 12+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2021-12-06 05:42 [PATCH v13 4/6] Move pgsql_tmp file removal to custodian process. Nathan Bossart <bossartn@amazon.com> 2021-12-06 05:42 [PATCH v12 4/6] Move pgsql_tmp file removal to custodian process. Nathan Bossart <bossartn@amazon.com> 2021-12-06 05:42 [PATCH v13 4/6] Move pgsql_tmp file removal to custodian process. Nathan Bossart <bossartn@amazon.com> 2021-12-06 05:42 [PATCH v12 4/6] Move pgsql_tmp file removal to custodian process. Nathan Bossart <bossartn@amazon.com> 2021-12-06 05:42 [PATCH v10 4/6] Move pgsql_tmp file removal to custodian process. Nathan Bossart <bossartn@amazon.com> 2021-12-06 05:42 [PATCH v11 4/6] Move pgsql_tmp file removal to custodian process. Nathan Bossart <bossartn@amazon.com> 2021-12-06 05:42 [PATCH v6 4/6] Move pgsql_tmp file removal to custodian process. Nathan Bossart <bossartn@amazon.com> 2021-12-06 05:42 [PATCH v4 4/8] Move pgsql_tmp file removal to custodian process. Nathan Bossart <bossartn@amazon.com> 2021-12-06 05:42 [PATCH v8 4/6] Move pgsql_tmp file removal to custodian process. Nathan Bossart <bossartn@amazon.com> 2021-12-06 05:42 [PATCH v9 4/6] Move pgsql_tmp file removal to custodian process. Nathan Bossart <bossartn@amazon.com> 2021-12-06 05:42 [PATCH v7 4/6] Move pgsql_tmp file removal to custodian process. Nathan Bossart <bossartn@amazon.com> 2021-12-06 05:42 [PATCH v5 4/8] Move pgsql_tmp file removal to custodian process. Nathan Bossart <bossartn@amazon.com>
This inbox is served by agora; see mirroring instructions for how to clone and mirror all data and code used for this inbox