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

Commit3144c33

Browse files
committed
Implement NOWAIT option for BASE_BACKUP command
Specifying this option makes the server not wait for thexlog to be archived, or emit a warning that it can't,instead leaving the responsibility with the client.This is useful when the log is being streamed usingthe streaming protocol in parallel with the backup,without having log archiving enabled.
1 parent375e5b0 commit3144c33

File tree

6 files changed

+39
-8
lines changed

6 files changed

+39
-8
lines changed

‎doc/src/sgml/protocol.sgml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1473,7 +1473,7 @@ The commands accepted in walsender mode are:
14731473
</varlistentry>
14741474

14751475
<varlistentry>
1476-
<term>BASE_BACKUP [<literal>LABEL</literal> <replaceable>'label'</replaceable>] [<literal>PROGRESS</literal>] [<literal>FAST</literal>] [<literal>WAL</literal>]</term>
1476+
<term>BASE_BACKUP [<literal>LABEL</literal> <replaceable>'label'</replaceable>] [<literal>PROGRESS</literal>] [<literal>FAST</literal>] [<literal>WAL</literal>] [<literal>NOWAIT</literal>]</term>
14771477
<listitem>
14781478
<para>
14791479
Instructs the server to start streaming a base backup.
@@ -1530,6 +1530,19 @@ The commands accepted in walsender mode are:
15301530
</para>
15311531
</listitem>
15321532
</varlistentry>
1533+
1534+
<varlistentry>
1535+
<term><literal>NOWAIT</literal></term>
1536+
<listitem>
1537+
<para>
1538+
By default, the backup will wait until the last required xlog
1539+
segment has been archived, or emit a warning if log archiving is
1540+
not enabled. Specifying <literal>NOWAIT</literal> disables both
1541+
the waiting and the warning, leaving the client responsible for
1542+
ensuring the required log is available.
1543+
</para>
1544+
</listitem>
1545+
</varlistentry>
15331546
</variablelist>
15341547
</para>
15351548
<para>

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8865,7 +8865,7 @@ pg_stop_backup(PG_FUNCTION_ARGS)
88658865
XLogRecPtrstoppoint;
88668866
charstopxlogstr[MAXFNAMELEN];
88678867

8868-
stoppoint=do_pg_stop_backup(NULL);
8868+
stoppoint=do_pg_stop_backup(NULL, true);
88698869

88708870
snprintf(stopxlogstr,sizeof(stopxlogstr),"%X/%X",
88718871
stoppoint.xlogid,stoppoint.xrecoff);
@@ -8880,7 +8880,7 @@ pg_stop_backup(PG_FUNCTION_ARGS)
88808880
* the non-exclusive backup specified by 'labelfile'.
88818881
*/
88828882
XLogRecPtr
8883-
do_pg_stop_backup(char*labelfile)
8883+
do_pg_stop_backup(char*labelfile,boolwaitforarchive)
88848884
{
88858885
boolexclusive= (labelfile==NULL);
88868886
XLogRecPtrstartpoint;
@@ -9079,7 +9079,7 @@ do_pg_stop_backup(char *labelfile)
90799079
* wish to wait, you can set statement_timeout. Also, some notices are
90809080
* issued to clue in anyone who might be doing this interactively.
90819081
*/
9082-
if (XLogArchivingActive())
9082+
if (waitforarchive&&XLogArchivingActive())
90839083
{
90849084
XLByteToPrevSeg(stoppoint,_logId,_logSeg);
90859085
XLogFileName(lastxlogfilename,ThisTimeLineID,_logId,_logSeg);
@@ -9120,7 +9120,7 @@ do_pg_stop_backup(char *labelfile)
91209120
ereport(NOTICE,
91219121
(errmsg("pg_stop_backup complete, all required WAL segments have been archived")));
91229122
}
9123-
else
9123+
elseif (waitforarchive)
91249124
ereport(NOTICE,
91259125
(errmsg("WAL archiving is not enabled; you must ensure that all required WAL segments are copied through other means to complete the backup")));
91269126

‎src/backend/replication/basebackup.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ typedef struct
3737
constchar*label;
3838
boolprogress;
3939
boolfastcheckpoint;
40+
boolnowait;
4041
boolincludewal;
4142
}basebackup_options;
4243

@@ -173,7 +174,7 @@ perform_base_backup(basebackup_options *opt, DIR *tblspcdir)
173174
}
174175
PG_END_ENSURE_ERROR_CLEANUP(base_backup_cleanup, (Datum)0);
175176

176-
endptr=do_pg_stop_backup(labelfile);
177+
endptr=do_pg_stop_backup(labelfile, !opt->nowait);
177178

178179
if (opt->includewal)
179180
{
@@ -260,6 +261,7 @@ parse_basebackup_options(List *options, basebackup_options *opt)
260261
boolo_label= false;
261262
boolo_progress= false;
262263
boolo_fast= false;
264+
boolo_nowait= false;
263265
boolo_wal= false;
264266

265267
MemSet(opt,0,sizeof(*opt));
@@ -294,6 +296,15 @@ parse_basebackup_options(List *options, basebackup_options *opt)
294296
opt->fastcheckpoint= true;
295297
o_fast= true;
296298
}
299+
elseif (strcmp(defel->defname,"nowait")==0)
300+
{
301+
if (o_nowait)
302+
ereport(ERROR,
303+
(errcode(ERRCODE_SYNTAX_ERROR),
304+
errmsg("duplicate option \"%s\"",defel->defname)));
305+
opt->nowait= true;
306+
o_nowait= true;
307+
}
297308
elseif (strcmp(defel->defname,"wal")==0)
298309
{
299310
if (o_wal)

‎src/backend/replication/repl_gram.y

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ Node *replication_parse_result;
7171
%tokenK_LABEL
7272
%tokenK_PROGRESS
7373
%tokenK_FAST
74+
%tokenK_NOWAIT
7475
%tokenK_WAL
7576
%tokenK_START_REPLICATION
7677

@@ -107,7 +108,7 @@ identify_system:
107108
;
108109

109110
/*
110-
* BASE_BACKUP [LABEL '<label>'] [PROGRESS] [FAST] [WAL]
111+
* BASE_BACKUP [LABEL '<label>'] [PROGRESS] [FAST] [WAL] [NOWAIT]
111112
*/
112113
base_backup:
113114
K_BASE_BACKUPbase_backup_opt_list
@@ -142,6 +143,11 @@ base_backup_opt:
142143
$$ = makeDefElem("wal",
143144
(Node *)makeInteger(TRUE));
144145
}
146+
|K_NOWAIT
147+
{
148+
$$ = makeDefElem("nowait",
149+
(Node *)makeInteger(TRUE));
150+
}
145151
;
146152

147153
/*

‎src/backend/replication/repl_scanner.l

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ BASE_BACKUP{ return K_BASE_BACKUP; }
6060
FAST{return K_FAST; }
6161
IDENTIFY_SYSTEM{return K_IDENTIFY_SYSTEM; }
6262
LABEL{return K_LABEL; }
63+
NOWAIT{return K_NOWAIT; }
6364
PROGRESS{return K_PROGRESS; }
6465
WAL{return K_WAL; }
6566
START_REPLICATION{return K_START_REPLICATION; }

‎src/include/access/xlog.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ extern void WakeupRecovery(void);
318318
* Starting/stopping a base backup
319319
*/
320320
externXLogRecPtrdo_pg_start_backup(constchar*backupidstr,boolfast,char**labelfile);
321-
externXLogRecPtrdo_pg_stop_backup(char*labelfile);
321+
externXLogRecPtrdo_pg_stop_backup(char*labelfile,boolwaitforarchive);
322322
externvoiddo_pg_abort_backup(void);
323323

324324
/* File path names (all relative to $PGDATA) */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp