diff --git a/doc/src/sgml/ref/checkpoint.sgml b/doc/src/sgml/ref/checkpoint.sgml index 36a9e323f44..cd981cf2cab 100644 --- a/doc/src/sgml/ref/checkpoint.sgml +++ b/doc/src/sgml/ref/checkpoint.sgml @@ -25,6 +25,7 @@ CHECKPOINT [ ( option [, ...] ) ] where option can be one of: + FLUSH_UNLOGGED [ boolean ] MODE { FAST | SPREAD } @@ -76,6 +77,17 @@ CHECKPOINT [ ( option [, ...] ) ] Parameters + + FLUSH_UNLOGGED + + + Normally, CHECKPOINT does not flush dirty buffers of + unlogged relations. This option, which is disabled by default, enables + flushing unlogged relations to disk. + + + + MODE @@ -93,6 +105,20 @@ CHECKPOINT [ ( option [, ...] ) ] + + + boolean + + + Specifies whether the selected option should be turned on or off. + You can write TRUE, ON, or + 1 to enable the option, and FALSE, + OFF, or 0 to disable it. The + boolean value can also + be omitted, in which case TRUE is assumed. + + + diff --git a/src/backend/postmaster/checkpointer.c b/src/backend/postmaster/checkpointer.c index 9d77269a374..2809e298a44 100644 --- a/src/backend/postmaster/checkpointer.c +++ b/src/backend/postmaster/checkpointer.c @@ -989,6 +989,7 @@ void ExecCheckpoint(ParseState *pstate, CheckPointStmt *stmt) { bool fast = true; + bool unlogged = false; foreach_ptr(DefElem, opt, stmt->options) { @@ -1004,6 +1005,8 @@ ExecCheckpoint(ParseState *pstate, CheckPointStmt *stmt) errmsg("unrecognized MODE option \"%s\"", mode), parser_errposition(pstate, opt->location))); } + else if (strcmp(opt->defname, "flush_unlogged") == 0) + unlogged = defGetBoolean(opt); else ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), @@ -1022,6 +1025,7 @@ ExecCheckpoint(ParseState *pstate, CheckPointStmt *stmt) RequestCheckpoint(CHECKPOINT_WAIT | (fast ? CHECKPOINT_FAST : 0) | + (unlogged ? CHECKPOINT_FLUSH_UNLOGGED : 0) | (RecoveryInProgress() ? 0 : CHECKPOINT_FORCE)); } diff --git a/src/bin/psql/tab-complete.in.c b/src/bin/psql/tab-complete.in.c index a7db04efd93..6872653c6c8 100644 --- a/src/bin/psql/tab-complete.in.c +++ b/src/bin/psql/tab-complete.in.c @@ -3165,7 +3165,7 @@ match_previous_words(int pattern_id, * one word, so the above test is correct. */ if (ends_with(prev_wd, '(') || ends_with(prev_wd, ',')) - COMPLETE_WITH("MODE"); + COMPLETE_WITH("MODE", "FLUSH_UNLOGGED"); else if (TailMatches("MODE")) COMPLETE_WITH("FAST", "SPREAD"); } diff --git a/src/test/regress/expected/stats.out b/src/test/regress/expected/stats.out index b4df9ad5960..605f5070376 100644 --- a/src/test/regress/expected/stats.out +++ b/src/test/regress/expected/stats.out @@ -937,8 +937,8 @@ CHECKPOINT (MODE WRONG); ERROR: unrecognized MODE option "wrong" LINE 1: CHECKPOINT (MODE WRONG); ^ -CHECKPOINT (MODE FAST); -CHECKPOINT; +CHECKPOINT (MODE FAST, FLUSH_UNLOGGED FALSE); +CHECKPOINT (FLUSH_UNLOGGED); SELECT num_requested > :rqst_ckpts_before FROM pg_stat_checkpointer; ?column? ---------- diff --git a/src/test/regress/sql/stats.sql b/src/test/regress/sql/stats.sql index 0868b250a64..54e72866344 100644 --- a/src/test/regress/sql/stats.sql +++ b/src/test/regress/sql/stats.sql @@ -444,8 +444,8 @@ DROP TABLE test_stats_temp; -- because it would prolong the test. CHECKPOINT (WRONG); CHECKPOINT (MODE WRONG); -CHECKPOINT (MODE FAST); -CHECKPOINT; +CHECKPOINT (MODE FAST, FLUSH_UNLOGGED FALSE); +CHECKPOINT (FLUSH_UNLOGGED); SELECT num_requested > :rqst_ckpts_before FROM pg_stat_checkpointer; SELECT wal_bytes > :wal_bytes_before FROM pg_stat_wal;