From f5ce48e45aa79edc4e61fb6c6128dde6cacbd0c6 Mon Sep 17 00:00:00 2001 From: Jerry Jelinek Date: Tue, 26 Jun 2018 11:45:12 +0000 Subject: [PATCH] option to disable WAL recycling --- doc/src/sgml/config.sgml | 22 ++++++++++++++++++++++ src/backend/access/transam/xlog.c | 3 ++- src/backend/utils/misc/guc.c | 10 ++++++++++ src/backend/utils/misc/postgresql.conf.sample | 1 + src/include/access/xlog.h | 1 + 5 files changed, 36 insertions(+), 1 deletion(-) diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml index 7bfbc87..457db77 100644 --- a/doc/src/sgml/config.sgml +++ b/doc/src/sgml/config.sgml @@ -3116,6 +3116,28 @@ include_dir 'conf.d' + + wal_recycle (boolean) + + wal_recycle configuration parameter + + + + + When this parameter is on, past log file segments + in the pg_wal directory are recycled for future + use. + + + + Turning this parameter off causes past log files segments to be deleted + when no longer needed. This can improve performance by eliminating + read-modify-write operations on old files which are no longer in the + filesystem cache. + + + + wal_sender_timeout (integer) diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 1a419aa..74427c5 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -99,6 +99,7 @@ bool wal_log_hints = false; bool wal_compression = false; char *wal_consistency_checking_string = NULL; bool *wal_consistency_checking = NULL; +bool wal_recycle = true; bool log_checkpoints = false; int sync_method = DEFAULT_SYNC_METHOD; int wal_level = WAL_LEVEL_MINIMAL; @@ -4012,7 +4013,7 @@ RemoveXlogFile(const char *segname, XLogRecPtr PriorRedoPtr, XLogRecPtr endptr) * segment. Only recycle normal files, pg_standby for example can create * symbolic links pointing to a separate archive directory. */ - if (endlogSegNo <= recycleSegNo && + if (wal_recycle && endlogSegNo <= recycleSegNo && lstat(path, &statbuf) == 0 && S_ISREG(statbuf.st_mode) && InstallXLogFileSegment(&endlogSegNo, path, true, recycleSegNo, true)) diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index 859ef93..18ede0d 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -1114,6 +1114,16 @@ static struct config_bool ConfigureNamesBool[] = }, { + {"wal_recycle", PGC_SUSET, WAL_SETTINGS, + gettext_noop("WAL recycling enabled."), + NULL + }, + &wal_recycle, + true, + NULL, NULL, NULL + }, + + { {"log_checkpoints", PGC_SIGHUP, LOGGING_WHAT, gettext_noop("Logs each checkpoint."), NULL diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample index 9e39baf..474fd7b 100644 --- a/src/backend/utils/misc/postgresql.conf.sample +++ b/src/backend/utils/misc/postgresql.conf.sample @@ -199,6 +199,7 @@ #wal_compression = off # enable compression of full-page writes #wal_log_hints = off # also do full page writes of non-critical updates # (change requires restart) +#wal_recycle = off # do not recycle WAL files #wal_buffers = -1 # min 32kB, -1 sets based on shared_buffers # (change requires restart) #wal_writer_delay = 200ms # 1-10000 milliseconds diff --git a/src/include/access/xlog.h b/src/include/access/xlog.h index 421ba6d..cf13f12 100644 --- a/src/include/access/xlog.h +++ b/src/include/access/xlog.h @@ -106,6 +106,7 @@ extern bool EnableHotStandby; extern bool fullPageWrites; extern bool wal_log_hints; extern bool wal_compression; +extern bool wal_recycle; extern bool *wal_consistency_checking; extern char *wal_consistency_checking_string; extern bool log_checkpoints; -- 2.2.1