Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3870609

Browse files
committed
Add an optional parameter to pg_start_backup() that specifies whether to do
the checkpoint in immediate or lazy mode. This is to address complaintsthat pg_start_backup() takes a long time even when there's no need to minimizeits I/O consumption.
1 parent80df9c4 commit3870609

File tree

6 files changed

+54
-27
lines changed

6 files changed

+54
-27
lines changed

‎doc/src/sgml/backup.sgml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/backup.sgml,v 2.123 2009/03/05 19:50:03 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/backup.sgml,v 2.124 2009/04/07 00:31:25 tgl Exp $ -->
22

33
<chapter id="backup">
44
<title>Backup and Restore</title>
@@ -730,19 +730,19 @@ SELECT pg_start_backup('label');
730730
</para>
731731

732732
<para>
733-
<function>pg_start_backup</> can take a long time to finish.
733+
By default,<function>pg_start_backup</> can take a long time to finish.
734734
This is because it performs a checkpoint, and the I/O
735-
required fora checkpoint will be spread out over a significant
735+
required forthe checkpoint will be spread out over a significant
736736
period of time, by default half your inter-checkpoint interval
737737
(see the configuration parameter
738738
<xref linkend="guc-checkpoint-completion-target">). Usually
739-
this is what you want because it minimizes the impact on query
739+
this is what you want, because it minimizes the impact on query
740740
processing. If you just want to start the backup as soon as
741-
possible,execute a <command>CHECKPOINT</> command
742-
(which performs a checkpoint as quickly as possible) and then
743-
immediately execute <function>pg_start_backup</>. Then there
744-
will be very little for <function>pg_start_backup</>'s checkpoint
745-
todo, and it won't take long.
741+
possible,use:
742+
<programlisting>
743+
SELECTpg_start_backup('label', true);
744+
</programlisting>
745+
This forces the checkpointtobe done as quickly as possible.
746746
</para>
747747
</listitem>
748748
<listitem>
@@ -769,9 +769,9 @@ SELECT pg_stop_backup();
769769
<para>
770770
Once the WAL segment files used during the backup are archived, you are
771771
done. The file identified by <function>pg_stop_backup</>'s result is
772-
the last segment that is required to form a complete set of backup files.
772+
the last segment that is required to form a complete set of backup files.
773773
<function>pg_stop_backup</> does not return until the last segment has
774-
been archived.
774+
been archived.
775775
Archiving of these files happens automatically since you have
776776
already configured <varname>archive_command</>. In most cases this
777777
happens quickly, but you are advised to monitor your archive

‎doc/src/sgml/func.sgml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.474 2009/04/01 03:32:29 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.475 2009/04/07 00:31:25 tgl Exp $ -->
22

33
<chapter id="functions">
44
<title>Functions and Operators</title>
@@ -12880,10 +12880,10 @@ SELECT set_config('log_statement_stats', 'off', false);
1288012880
<tbody>
1288112881
<row>
1288212882
<entry>
12883-
<literal><function>pg_start_backup</function>(<parameter>label</> <type>text</>)</literal>
12883+
<literal><function>pg_start_backup</function>(<parameter>label</> <type>text</> <optional>, <parameter>fast</> <type>boolean</> </optional>)</literal>
1288412884
</entry>
1288512885
<entry><type>text</type></entry>
12886-
<entry>Set up for performing on-line backup</entry>
12886+
<entry>Prepare for performing on-line backup</entry>
1288712887
</row>
1288812888
<row>
1288912889
<entry>
@@ -12932,20 +12932,25 @@ SELECT set_config('log_statement_stats', 'off', false);
1293212932
</table>
1293312933

1293412934
<para>
12935-
<function>pg_start_backup</> accepts asingle parameter which is an
12935+
<function>pg_start_backup</> accepts atext parameter which is an
1293612936
arbitrary user-defined label for the backup. (Typically this would be
1293712937
the name under which the backup dump file will be stored.) The function
1293812938
writes a backup label file into the database cluster's data directory,
12939-
and then returns the backup's starting transaction log location as text. The user
12940-
need not pay any attention to this result value, but it is provided in
12941-
case it is of use.
12939+
performs a checkpoint,
12940+
and then returns the backup's starting transaction log location as text.
12941+
The user need not pay any attention to this result value, but it is
12942+
provided in case it is of use.
1294212943
<programlisting>
1294312944
postgres=# select pg_start_backup('label_goes_here');
1294412945
pg_start_backup
1294512946
-----------------
1294612947
0/D4445B8
1294712948
(1 row)
1294812949
</programlisting>
12950+
There is an optional boolean second parameter. If <literal>true</>,
12951+
it specifies executing <function>pg_start_backup</> as quickly as
12952+
possible. This forces an immediate checkpoint which will cause a
12953+
spike in I/O operations, slowing any concurrently executing queries.
1294912954
</para>
1295012955

1295112956
<para>
@@ -12961,7 +12966,7 @@ postgres=# select pg_start_backup('label_goes_here');
1296112966
</para>
1296212967

1296312968
<para>
12964-
<function>pg_switch_xlog</> moves to the next transaction log file, allowing the
12969+
<function>pg_switch_xlog</> moves to the next transaction log file, allowing the
1296512970
current file to be archived (assuming you are using continuous archiving).
1296612971
The result is the ending transaction log location + 1 within the just-completed transaction log file.
1296712972
If there has been no transaction log activity since the last transaction log switch,

‎src/backend/access/transam/xlog.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.334 2009/03/11 23:19:24 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.335 2009/04/07 00:31:26 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -6914,6 +6914,7 @@ Datum
69146914
pg_start_backup(PG_FUNCTION_ARGS)
69156915
{
69166916
text*backupid=PG_GETARG_TEXT_P(0);
6917+
boolfast=PG_GETARG_BOOL(1);
69176918
char*backupidstr;
69186919
XLogRecPtrcheckpointloc;
69196920
XLogRecPtrstartpoint;
@@ -6983,9 +6984,11 @@ pg_start_backup(PG_FUNCTION_ARGS)
69836984
* have different checkpoint positions and hence different history
69846985
* file names, even if nothing happened in between.
69856986
*
6986-
* We don't use CHECKPOINT_IMMEDIATE, hence this can take awhile.
6987+
* We use CHECKPOINT_IMMEDIATE only if requested by user (via
6988+
* passing fast = true). Otherwise this can take awhile.
69876989
*/
6988-
RequestCheckpoint(CHECKPOINT_FORCE |CHECKPOINT_WAIT);
6990+
RequestCheckpoint(CHECKPOINT_FORCE |CHECKPOINT_WAIT |
6991+
(fast ?CHECKPOINT_IMMEDIATE :0));
69896992

69906993
/*
69916994
* Now we need to fetch the checkpoint record location, and also its

‎src/backend/catalog/system_views.sql

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 1996-2009, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/backend/catalog/system_views.sql,v 1.59 2009/02/06 21:15:11 tgl Exp $
6+
* $PostgreSQL: pgsql/src/backend/catalog/system_views.sql,v 1.60 2009/04/07 00:31:26 tgl Exp $
77
*/
88

99
CREATEVIEWpg_rolesAS
@@ -403,6 +403,12 @@ CREATE VIEW pg_user_mappings AS
403403

404404
REVOKE ALLon pg_user_mappingFROM public;
405405

406+
--
407+
-- We have a few function definitions in here, too.
408+
-- At some point there might be enough to justify breaking them out into
409+
-- a separate "system_functions.sql" file.
410+
--
411+
406412
-- Tsearch debug function. Defined here because it'd be pretty unwieldy
407413
-- to put it into pg_proc.h
408414

@@ -464,3 +470,16 @@ LANGUAGE SQL STRICT STABLE;
464470

465471
COMMENT ON FUNCTION ts_debug(text) IS
466472
'debug function for current text search configuration';
473+
474+
--
475+
-- Redeclare built-in functions that need default values attached to their
476+
-- arguments. It's impractical to set those up directly in pg_proc.h because
477+
-- of the complexity and platform-dependency of the expression tree
478+
-- representation. (Note that internal functions still have to have entries
479+
-- in pg_proc.h; we are merely causing their proargnames and proargdefaults
480+
-- to get filled in.)
481+
--
482+
483+
CREATEOR REPLACE FUNCTION
484+
pg_start_backup(labeltext, fastboolean DEFAULT false)
485+
RETURNStext STRICT VOLATILE LANGUAGE internalAS'pg_start_backup';

‎src/include/catalog/catversion.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
3838
* Portions Copyright (c) 1994, Regents of the University of California
3939
*
40-
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.528 2009/04/05 22:28:59 tgl Exp $
40+
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.529 2009/04/07 00:31:26 tgl Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/*yyyymmddN */
56-
#defineCATALOG_VERSION_NO200904051
56+
#defineCATALOG_VERSION_NO200904061
5757

5858
#endif

‎src/include/catalog/pg_proc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.540 2009/04/05 22:28:59 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.541 2009/04/07 00:31:26 tgl Exp $
1111
*
1212
* NOTES
1313
* The script catalog/genbki.sh reads this file and generates .bki
@@ -3252,7 +3252,7 @@ DATA(insert OID = 2171 ( pg_cancel_backendPGNSP PGUID 12 1 0 0 f f f t f v 1 0
32523252
DESCR("cancel a server process' current query");
32533253
DATA(insertOID=2096 (pg_terminate_backendPGNSPPGUID12100ffftfv1016"23"_null__null__null__null_pg_terminate_backend_null__null__null_ ));
32543254
DESCR("terminate a server process");
3255-
DATA(insertOID=2172 (pg_start_backupPGNSPPGUID12100ffftfv1025"25"_null__null__null__null_pg_start_backup_null__null__null_ ));
3255+
DATA(insertOID=2172 (pg_start_backupPGNSPPGUID12100ffftfv2025"25 16"_null__null__null__null_pg_start_backup_null__null__null_ ));
32563256
DESCR("prepare for taking an online backup");
32573257
DATA(insertOID=2173 (pg_stop_backupPGNSPPGUID12100ffftfv0025""_null__null__null__null_pg_stop_backup_null__null__null_ ));
32583258
DESCR("finish taking an online backup");

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp