Skip to content

Commit da67ae6

Browse files
author
Commitfest Bot
committed
[CF 5786] v9 - CHECKPOINT unlogged data
This branch was automatically generated by a robot using patches from an email thread registered at: https://commitfest.postgresql.org/patch/5786 The branch will be overwritten each time a new patch version is posted to the thread, and also periodically to check for bitrot caused by changes on the master branch. Patch(es): https://www.postgresql.org/message-id/aG_kOm3bkKVKjmhI@nathan Author(s): Christoph Berg
2 parents b41c430 + 7c157ac commit da67ae6

File tree

18 files changed

+213
-65
lines changed

18 files changed

+213
-65
lines changed

doc/src/sgml/backup.sgml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,7 @@ SELECT pg_backup_start(label => 'label', fast => false);
991991
usually preferable as it minimizes the impact on the running system. If you
992992
want to start the backup as soon as possible, pass <literal>true</literal> as
993993
the second parameter to <function>pg_backup_start</function> and it will
994-
request an immediate checkpoint, which will finish as fast as possible using
994+
request a fast checkpoint, which will finish as fast as possible using
995995
as much I/O as possible.
996996
</para>
997997

doc/src/sgml/func.sgml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28973,7 +28973,7 @@ LOG: Grand total: 1651920 bytes in 201 blocks; 622360 free (88 chunks); 1029560
2897328973
will be stored.)
2897428974
If the optional second parameter is given as <literal>true</literal>,
2897528975
it specifies executing <function>pg_backup_start</function> as quickly
28976-
as possible. This forces an immediate checkpoint which will cause a
28976+
as possible. This forces a fast checkpoint which will cause a
2897728977
spike in I/O operations, slowing any concurrently executing queries.
2897828978
</para>
2897928979
<para>

doc/src/sgml/ref/checkpoint.sgml

Lines changed: 66 additions & 2 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+
FLUSH_UNLOGGED [ <replaceable class="parameter">boolean</replaceable> ]
29+
MODE { FAST | SPREAD }
2530
</synopsis>
2631
</refsynopsisdiv>
2732

@@ -37,14 +42,24 @@ CHECKPOINT
3742
</para>
3843

3944
<para>
40-
The <command>CHECKPOINT</command> command forces an immediate
45+
By default, the <command>CHECKPOINT</command> command forces a fast
4146
checkpoint when the command is issued, without waiting for a
4247
regular checkpoint scheduled by the system (controlled by the settings in
4348
<xref linkend="runtime-config-wal-checkpoints"/>).
49+
To request the checkpoint be spread over a longer interval, set the
50+
<literal>MODE</literal> option to <literal>SPREAD</literal>.
4451
<command>CHECKPOINT</command> is not intended for use during normal
4552
operation.
4653
</para>
4754

55+
<para>
56+
The server may consolidate concurrently requested checkpoints. Such
57+
consolidated requests will contain a combined set of options. For example,
58+
if one session requests a fast checkpoint and another requests a spread
59+
checkpoint, the server may combine those requests and perform one fast
60+
checkpoint.
61+
</para>
62+
4863
<para>
4964
If executed during recovery, the <command>CHECKPOINT</command> command
5065
will force a restartpoint (see <xref linkend="wal-configuration"/>)
@@ -58,6 +73,55 @@ CHECKPOINT
5873
</para>
5974
</refsect1>
6075

76+
<refsect1>
77+
<title>Parameters</title>
78+
79+
<variablelist>
80+
<varlistentry>
81+
<term><literal>FLUSH_UNLOGGED</literal></term>
82+
<listitem>
83+
<para>
84+
Normally, <command>CHECKPOINT</command> does not flush dirty buffers of
85+
unlogged relations. This option, which is disabled by default, enables
86+
flushing unlogged relations to disk.
87+
</para>
88+
</listitem>
89+
</varlistentry>
90+
91+
<varlistentry>
92+
<term><literal>MODE</literal></term>
93+
<listitem>
94+
<para>
95+
When set to <literal>FAST</literal>, which is the default, the requested
96+
checkpoint will be completed as fast as possible, which may result in a
97+
significantly higher rate of I/O during the checkpoint.
98+
</para>
99+
<para>
100+
<literal>MODE</literal> can also be set to <literal>SPREAD</literal> to
101+
request the checkpoint be spread over a longer interval (controlled via
102+
the settings in <xref linkend="runtime-config-wal-checkpoints"/>), like a
103+
regular checkpoint scheduled by the system. This can reduce the rate of
104+
I/O during the checkpoint.
105+
</para>
106+
</listitem>
107+
</varlistentry>
108+
109+
<varlistentry>
110+
<term><replaceable class="parameter">boolean</replaceable></term>
111+
<listitem>
112+
<para>
113+
Specifies whether the selected option should be turned on or off.
114+
You can write <literal>TRUE</literal>, <literal>ON</literal>, or
115+
<literal>1</literal> to enable the option, and <literal>FALSE</literal>,
116+
<literal>OFF</literal>, or <literal>0</literal> to disable it. The
117+
<replaceable class="parameter">boolean</replaceable> value can also
118+
be omitted, in which case <literal>TRUE</literal> is assumed.
119+
</para>
120+
</listitem>
121+
</varlistentry>
122+
</variablelist>
123+
</refsect1>
124+
61125
<refsect1>
62126
<title>Compatibility</title>
63127

doc/src/sgml/ref/pg_basebackup.sgml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,8 +500,9 @@ PostgreSQL documentation
500500
<term><option>--checkpoint={fast|spread}</option></term>
501501
<listitem>
502502
<para>
503-
Sets checkpoint mode to fast (immediate) or spread (the default)
503+
Sets checkpoint mode to fast or spread
504504
(see <xref linkend="backup-lowlevel-base-backup"/>).
505+
The default is spread.
505506
</para>
506507
</listitem>
507508
</varlistentry>

src/backend/access/transam/xlog.c

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6505,7 +6505,7 @@ PerformRecoveryXLogAction(void)
65056505
else
65066506
{
65076507
RequestCheckpoint(CHECKPOINT_END_OF_RECOVERY |
6508-
CHECKPOINT_IMMEDIATE |
6508+
CHECKPOINT_FAST |
65096509
CHECKPOINT_WAIT);
65106510
}
65116511

@@ -6814,7 +6814,7 @@ ShutdownXLOG(int code, Datum arg)
68146814
WalSndWaitStopping();
68156815

68166816
if (RecoveryInProgress())
6817-
CreateRestartPoint(CHECKPOINT_IS_SHUTDOWN | CHECKPOINT_IMMEDIATE);
6817+
CreateRestartPoint(CHECKPOINT_IS_SHUTDOWN | CHECKPOINT_FAST);
68186818
else
68196819
{
68206820
/*
@@ -6826,7 +6826,7 @@ ShutdownXLOG(int code, Datum arg)
68266826
if (XLogArchivingActive())
68276827
RequestXLogSwitch(false);
68286828

6829-
CreateCheckPoint(CHECKPOINT_IS_SHUTDOWN | CHECKPOINT_IMMEDIATE);
6829+
CreateCheckPoint(CHECKPOINT_IS_SHUTDOWN | CHECKPOINT_FAST);
68306830
}
68316831
}
68326832

@@ -6842,24 +6842,24 @@ LogCheckpointStart(int flags, bool restartpoint)
68426842
(errmsg("restartpoint starting:%s%s%s%s%s%s%s%s",
68436843
(flags & CHECKPOINT_IS_SHUTDOWN) ? " shutdown" : "",
68446844
(flags & CHECKPOINT_END_OF_RECOVERY) ? " end-of-recovery" : "",
6845-
(flags & CHECKPOINT_IMMEDIATE) ? " immediate" : "",
6845+
(flags & CHECKPOINT_FAST) ? " fast" : "",
68466846
(flags & CHECKPOINT_FORCE) ? " force" : "",
68476847
(flags & CHECKPOINT_WAIT) ? " wait" : "",
68486848
(flags & CHECKPOINT_CAUSE_XLOG) ? " wal" : "",
68496849
(flags & CHECKPOINT_CAUSE_TIME) ? " time" : "",
6850-
(flags & CHECKPOINT_FLUSH_ALL) ? " flush-all" : "")));
6850+
(flags & CHECKPOINT_FLUSH_UNLOGGED) ? " flush-unlogged" : "")));
68516851
else
68526852
ereport(LOG,
68536853
/* translator: the placeholders show checkpoint options */
68546854
(errmsg("checkpoint starting:%s%s%s%s%s%s%s%s",
68556855
(flags & CHECKPOINT_IS_SHUTDOWN) ? " shutdown" : "",
68566856
(flags & CHECKPOINT_END_OF_RECOVERY) ? " end-of-recovery" : "",
6857-
(flags & CHECKPOINT_IMMEDIATE) ? " immediate" : "",
6857+
(flags & CHECKPOINT_FAST) ? " fast" : "",
68586858
(flags & CHECKPOINT_FORCE) ? " force" : "",
68596859
(flags & CHECKPOINT_WAIT) ? " wait" : "",
68606860
(flags & CHECKPOINT_CAUSE_XLOG) ? " wal" : "",
68616861
(flags & CHECKPOINT_CAUSE_TIME) ? " time" : "",
6862-
(flags & CHECKPOINT_FLUSH_ALL) ? " flush-all" : "")));
6862+
(flags & CHECKPOINT_FLUSH_UNLOGGED) ? " flush-unlogged" : "")));
68636863
}
68646864

68656865
/*
@@ -7042,12 +7042,12 @@ update_checkpoint_display(int flags, bool restartpoint, bool reset)
70427042
* flags is a bitwise OR of the following:
70437043
* CHECKPOINT_IS_SHUTDOWN: checkpoint is for database shutdown.
70447044
* CHECKPOINT_END_OF_RECOVERY: checkpoint is for end of WAL recovery.
7045-
* CHECKPOINT_IMMEDIATE: finish the checkpoint ASAP,
7046-
* ignoring checkpoint_completion_target parameter.
7045+
* CHECKPOINT_FAST: finish the checkpoint ASAP, ignoring
7046+
* checkpoint_completion_target parameter.
70477047
* CHECKPOINT_FORCE: force a checkpoint even if no XLOG activity has occurred
70487048
* since the last one (implied by CHECKPOINT_IS_SHUTDOWN or
70497049
* CHECKPOINT_END_OF_RECOVERY).
7050-
* CHECKPOINT_FLUSH_ALL: also flush buffers of unlogged tables.
7050+
* CHECKPOINT_FLUSH_UNLOGGED: also flush buffers of unlogged tables.
70517051
*
70527052
* Note: flags contains other bits, of interest here only for logging purposes.
70537053
* In particular note that this routine is synchronous and does not pay
@@ -8946,9 +8946,8 @@ issue_xlog_fsync(int fd, XLogSegNo segno, TimeLineID tli)
89468946
* backup state and tablespace map.
89478947
*
89488948
* Input parameters are "state" (the backup state), "fast" (if true, we do
8949-
* the checkpoint in immediate mode to make it faster), and "tablespaces"
8950-
* (if non-NULL, indicates a list of tablespaceinfo structs describing the
8951-
* cluster's tablespaces.).
8949+
* the checkpoint in fast mode), and "tablespaces" (if non-NULL, indicates a
8950+
* list of tablespaceinfo structs describing the cluster's tablespaces.).
89528951
*
89538952
* The tablespace map contents are appended to passed-in parameter
89548953
* tablespace_map and the caller is responsible for including it in the backup
@@ -9076,11 +9075,11 @@ do_pg_backup_start(const char *backupidstr, bool fast, List **tablespaces,
90769075
* during recovery means that checkpointer is running, we can use
90779076
* RequestCheckpoint() to establish a restartpoint.
90789077
*
9079-
* We use CHECKPOINT_IMMEDIATE only if requested by user (via
9080-
* passing fast = true). Otherwise this can take awhile.
9078+
* We use CHECKPOINT_FAST only if requested by user (via passing
9079+
* fast = true). Otherwise this can take awhile.
90819080
*/
90829081
RequestCheckpoint(CHECKPOINT_FORCE | CHECKPOINT_WAIT |
9083-
(fast ? CHECKPOINT_IMMEDIATE : 0));
9082+
(fast ? CHECKPOINT_FAST : 0));
90849083

90859084
/*
90869085
* Now we need to fetch the checkpoint record location, and also

src/backend/commands/dbcommands.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -570,8 +570,8 @@ CreateDatabaseUsingFileCopy(Oid src_dboid, Oid dst_dboid, Oid src_tsid,
570570
* any CREATE DATABASE commands.
571571
*/
572572
if (!IsBinaryUpgrade)
573-
RequestCheckpoint(CHECKPOINT_IMMEDIATE | CHECKPOINT_FORCE |
574-
CHECKPOINT_WAIT | CHECKPOINT_FLUSH_ALL);
573+
RequestCheckpoint(CHECKPOINT_FAST | CHECKPOINT_FORCE |
574+
CHECKPOINT_WAIT | CHECKPOINT_FLUSH_UNLOGGED);
575575

576576
/*
577577
* Iterate through all tablespaces of the template database, and copy each
@@ -673,7 +673,7 @@ CreateDatabaseUsingFileCopy(Oid src_dboid, Oid dst_dboid, Oid src_tsid,
673673
* strategy that avoids these problems.
674674
*/
675675
if (!IsBinaryUpgrade)
676-
RequestCheckpoint(CHECKPOINT_IMMEDIATE | CHECKPOINT_FORCE |
676+
RequestCheckpoint(CHECKPOINT_FAST | CHECKPOINT_FORCE |
677677
CHECKPOINT_WAIT);
678678
}
679679

@@ -1870,7 +1870,7 @@ dropdb(const char *dbname, bool missing_ok, bool force)
18701870
* Force a checkpoint to make sure the checkpointer has received the
18711871
* message sent by ForgetDatabaseSyncRequests.
18721872
*/
1873-
RequestCheckpoint(CHECKPOINT_IMMEDIATE | CHECKPOINT_FORCE | CHECKPOINT_WAIT);
1873+
RequestCheckpoint(CHECKPOINT_FAST | CHECKPOINT_FORCE | CHECKPOINT_WAIT);
18741874

18751875
/* Close all smgr fds in all backends. */
18761876
WaitForProcSignalBarrier(EmitProcSignalBarrier(PROCSIGNAL_BARRIER_SMGRRELEASE));
@@ -2120,8 +2120,8 @@ movedb(const char *dbname, const char *tblspcname)
21202120
* On Windows, this also ensures that background procs don't hold any open
21212121
* files, which would cause rmdir() to fail.
21222122
*/
2123-
RequestCheckpoint(CHECKPOINT_IMMEDIATE | CHECKPOINT_FORCE | CHECKPOINT_WAIT
2124-
| CHECKPOINT_FLUSH_ALL);
2123+
RequestCheckpoint(CHECKPOINT_FAST | CHECKPOINT_FORCE | CHECKPOINT_WAIT
2124+
| CHECKPOINT_FLUSH_UNLOGGED);
21252125

21262126
/* Close all smgr fds in all backends. */
21272127
WaitForProcSignalBarrier(EmitProcSignalBarrier(PROCSIGNAL_BARRIER_SMGRRELEASE));
@@ -2252,7 +2252,7 @@ movedb(const char *dbname, const char *tblspcname)
22522252
* any unlogged operations done in the new DB tablespace before the
22532253
* next checkpoint.
22542254
*/
2255-
RequestCheckpoint(CHECKPOINT_IMMEDIATE | CHECKPOINT_FORCE | CHECKPOINT_WAIT);
2255+
RequestCheckpoint(CHECKPOINT_FAST | CHECKPOINT_FORCE | CHECKPOINT_WAIT);
22562256

22572257
/*
22582258
* Force synchronous commit, thus minimizing the window between

src/backend/commands/tablespace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ DropTableSpace(DropTableSpaceStmt *stmt)
500500
* mustn't delete. So instead, we force a checkpoint which will clean
501501
* out any lingering files, and try again.
502502
*/
503-
RequestCheckpoint(CHECKPOINT_IMMEDIATE | CHECKPOINT_FORCE | CHECKPOINT_WAIT);
503+
RequestCheckpoint(CHECKPOINT_FAST | CHECKPOINT_FORCE | CHECKPOINT_WAIT);
504504

505505
/*
506506
* On Windows, an unlinked file persists in the directory listing

src/backend/parser/gram.y

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2034,6 +2034,13 @@ CheckPointStmt:
20342034

20352035
$$ = (Node *) n;
20362036
}
2037+
| CHECKPOINT '(' utility_option_list ')'
2038+
{
2039+
CheckPointStmt *n = makeNode(CheckPointStmt);
2040+
2041+
$$ = (Node *) n;
2042+
n->options = $3;
2043+
}
20372044
;
20382045

20392046

0 commit comments

Comments
 (0)