Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e82d71c

Browse files
df7cbCommitfest Bot
authored and
Commitfest Bot
committed
Add immediate and flush_all options to checkpoint
Field reports indicate that some users are running CHECKPOINT just before shutting down to reduce the amount of data that the shutdown checkpoint has to write out, making restarts faster. That works well unless big unlogged tables are in play; a regular CHECKPOINT does not flush these. Hence, add a CHECKPOINT option to force flushing of all relations. Since it's easy enough, also add an IMMEDIATE option to allow avoiding triggering a fast checkpoint.
1 parent 961553d commit e82d71c

File tree

7 files changed

+95
-12
lines changed

7 files changed

+95
-12
lines changed

doc/src/sgml/ref/checkpoint.sgml

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ PostgreSQL documentation
2121

2222
<refsynopsisdiv>
2323
<synopsis>
24-
CHECKPOINT
24+
CHECKPOINT [ ( option [, ...] ) ]
25+
26+
<phrase>where <replaceable class="parameter">option</replaceable> can be one of:</phrase>
27+
28+
IMMEDIATE [ <replaceable class="parameter">boolean</replaceable> ]
29+
FLUSH_ALL [ <replaceable class="parameter">boolean</replaceable> ]
2530
</synopsis>
2631
</refsynopsisdiv>
2732

@@ -31,18 +36,18 @@ CHECKPOINT
3136
<para>
3237
A checkpoint is a point in the write-ahead log sequence at which
3338
all data files have been updated to reflect the information in the
34-
log. All data files will be flushed to disk. Refer to
39+
log. All data files will be flushed to disk, except for relations marked <literal>UNLOGGED</literal>. Refer to
3540
<xref linkend="wal-configuration"/> for more details about what happens
3641
during a checkpoint.
3742
</para>
3843

3944
<para>
45+
Running <command>CHECKPOINT</command> is not required during normal
46+
operation; the system schedules checkpoints automatically (controlled by
47+
the settings in <xref linkend="runtime-config-wal-checkpoints"/>).
4048
The <command>CHECKPOINT</command> command forces an immediate
41-
checkpoint when the command is issued, without waiting for a
42-
regular checkpoint scheduled by the system (controlled by the settings in
43-
<xref linkend="runtime-config-wal-checkpoints"/>).
44-
<command>CHECKPOINT</command> is not intended for use during normal
45-
operation.
49+
checkpoint by default when the command is issued, without waiting for a
50+
regular checkpoint scheduled by the system.
4651
</para>
4752

4853
<para>
@@ -58,6 +63,46 @@ CHECKPOINT
5863
</para>
5964
</refsect1>
6065

66+
<refsect1>
67+
<title>Parameters</title>
68+
69+
<variablelist>
70+
<varlistentry>
71+
<term><literal>IMMEDIATE</literal></term>
72+
<listitem>
73+
<para>
74+
Requests the checkpoint to start immediately and run at full speed
75+
without spreading the I/O load out. Defaults to on.
76+
</para>
77+
</listitem>
78+
</varlistentry>
79+
80+
<varlistentry>
81+
<term><literal>FLUSH_ALL</literal></term>
82+
<listitem>
83+
<para>
84+
Requests the checkpoint to also flush data of <literal>UNLOGGED</literal>
85+
relations. Defaults to off.
86+
</para>
87+
</listitem>
88+
</varlistentry>
89+
90+
<varlistentry>
91+
<term><replaceable class="parameter">boolean</replaceable></term>
92+
<listitem>
93+
<para>
94+
Specifies whether the selected option should be turned on or off.
95+
You can write <literal>TRUE</literal>, <literal>ON</literal>, or
96+
<literal>1</literal> to enable the option, and <literal>FALSE</literal>,
97+
<literal>OFF</literal>, or <literal>0</literal> to disable it. The
98+
<replaceable class="parameter">boolean</replaceable> value can also
99+
be omitted, in which case <literal>TRUE</literal> is assumed.
100+
</para>
101+
</listitem>
102+
</varlistentry>
103+
</variablelist>
104+
</refsect1>
105+
61106
<refsect1>
62107
<title>Compatibility</title>
63108

src/backend/parser/gram.y

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2034,6 +2034,14 @@ CheckPointStmt:
20342034
CheckPointStmt *n = makeNode(CheckPointStmt);
20352035

20362036
$$ = (Node *) n;
2037+
n->options = NULL;
2038+
}
2039+
| CHECKPOINT '(' utility_option_list ')'
2040+
{
2041+
CheckPointStmt *n = makeNode(CheckPointStmt);
2042+
2043+
$$ = (Node *) n;
2044+
n->options = $3;
20372045
}
20382046
;
20392047

src/backend/tcop/utility.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,11 @@ standard_ProcessUtility(PlannedStmt *pstmt,
943943
break;
944944

945945
case T_CheckPointStmt:
946+
CheckPointStmt *stmt = (CheckPointStmt *) parsetree;
947+
ListCell *lc;
948+
bool immediate = true;
949+
bool flush_all = false;
950+
946951
if (!has_privs_of_role(GetUserId(), ROLE_PG_CHECKPOINT))
947952
ereport(ERROR,
948953
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
@@ -952,7 +957,26 @@ standard_ProcessUtility(PlannedStmt *pstmt,
952957
errdetail("Only roles with privileges of the \"%s\" role may execute this command.",
953958
"pg_checkpoint")));
954959

955-
RequestCheckpoint(CHECKPOINT_IMMEDIATE | CHECKPOINT_WAIT |
960+
/* Parse options list */
961+
foreach(lc, stmt->options)
962+
{
963+
DefElem *opt = (DefElem *) lfirst(lc);
964+
965+
if (strcmp(opt->defname, "immediate") == 0)
966+
immediate = defGetBoolean(opt);
967+
else if (strcmp(opt->defname, "flush_all") == 0)
968+
flush_all = defGetBoolean(opt);
969+
else
970+
ereport(ERROR,
971+
(errcode(ERRCODE_SYNTAX_ERROR),
972+
errmsg("unrecognized CHECKPOINT option \"%s\"", opt->defname),
973+
errhint("valid options are \"IMMEDIATE\" and \"FLUSH_ALL\""),
974+
parser_errposition(pstate, opt->location)));
975+
}
976+
977+
RequestCheckpoint(CHECKPOINT_WAIT |
978+
(immediate ? CHECKPOINT_IMMEDIATE : 0) |
979+
(flush_all ? CHECKPOINT_FLUSH_ALL : 0) |
956980
(RecoveryInProgress() ? 0 : CHECKPOINT_FORCE));
957981
break;
958982

src/bin/psql/tab-complete.in.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3125,6 +3125,11 @@ match_previous_words(int pattern_id,
31253125
COMPLETE_WITH_VERSIONED_SCHEMA_QUERY(Query_for_list_of_procedures);
31263126
else if (Matches("CALL", MatchAny))
31273127
COMPLETE_WITH("(");
3128+
/* CHECKPOINT */
3129+
else if (Matches("CHECKPOINT"))
3130+
COMPLETE_WITH("(");
3131+
else if (Matches("CHECKPOINT", "("))
3132+
COMPLETE_WITH("IMMEDIATE", "FLUSH_ALL");
31283133
/* CLOSE */
31293134
else if (Matches("CLOSE"))
31303135
COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_cursors,

src/include/nodes/parsenodes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4015,6 +4015,7 @@ typedef struct RefreshMatViewStmt
40154015
typedef struct CheckPointStmt
40164016
{
40174017
NodeTag type;
4018+
List *options;
40184019
} CheckPointStmt;
40194020

40204021
/* ----------------------

src/test/regress/expected/stats.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -925,9 +925,9 @@ CREATE TEMP TABLE test_stats_temp AS SELECT 17;
925925
DROP TABLE test_stats_temp;
926926
-- Checkpoint twice: The checkpointer reports stats after reporting completion
927927
-- of the checkpoint. But after a second checkpoint we'll see at least the
928-
-- results of the first.
929-
CHECKPOINT;
928+
-- results of the first. And while at it, test checkpoint options.
930929
CHECKPOINT;
930+
CHECKPOINT (immediate, flush_all);
931931
SELECT num_requested > :rqst_ckpts_before FROM pg_stat_checkpointer;
932932
?column?
933933
----------

src/test/regress/sql/stats.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,9 +438,9 @@ DROP TABLE test_stats_temp;
438438

439439
-- Checkpoint twice: The checkpointer reports stats after reporting completion
440440
-- of the checkpoint. But after a second checkpoint we'll see at least the
441-
-- results of the first.
442-
CHECKPOINT;
441+
-- results of the first. And while at it, test checkpoint options.
443442
CHECKPOINT;
443+
CHECKPOINT (immediate, flush_all);
444444

445445
SELECT num_requested > :rqst_ckpts_before FROM pg_stat_checkpointer;
446446
SELECT wal_bytes > :wal_bytes_before FROM pg_stat_wal;

0 commit comments

Comments
 (0)