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

Commit fab13dc

Browse files
committed
Make pg_basebackup ask the server to estimate the total backup size, by default.
This commit changes pg_basebackup so that it specifies PROGRESS option in BASE_BACKUP replication command whether --progress is specified or not. This causes the server to estimate the total backup size and report it in pg_stat_progress_basebackup.backup_total, by default. This is reasonable default because the time required for the estimation would not be so large in most cases. Also this commit adds new option --no-estimate-size to pg_basebackup. This option prevents the server from the estimation, and so is useful to avoid such estimation time if it's too long. Author: Fujii Masao Reviewed-by: Magnus Hagander, Amit Langote Discussion: https://postgr.es/m/CABUevEyDPPSjP7KRvfTXPdqOdY5aWNkqsB5aAXs3bco5ZwtGHg@mail.gmail.com
1 parent c314c14 commit fab13dc

File tree

3 files changed

+44
-21
lines changed

3 files changed

+44
-21
lines changed

doc/src/sgml/monitoring.sgml

+5-5
Original file line numberDiff line numberDiff line change
@@ -4392,18 +4392,18 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS pid,
43924392
<entry><structfield>backup_total</structfield></entry>
43934393
<entry><type>bigint</type></entry>
43944394
<entry>
4395-
Total amount of data that will be streamed. If progress reporting
4396-
is not enabled in <application>pg_basebackup</application>
4397-
(i.e., <literal>--progress</literal> option is not specified),
4398-
this is <literal>0</literal>. Otherwise, this is estimated and
4395+
Total amount of data that will be streamed. This is estimated and
43994396
reported as of the beginning of
44004397
<literal>streaming database files</literal> phase. Note that
44014398
this is only an approximation since the database
44024399
may change during <literal>streaming database files</literal> phase
44034400
and WAL log may be included in the backup later. This is always
44044401
the same value as <structfield>backup_streamed</structfield>
44054402
once the amount of data streamed exceeds the estimated
4406-
total size.
4403+
total size. If the estimation is disabled in
4404+
<application>pg_basebackup</application>
4405+
(i.e., <literal>--no-estimate-size</literal> option is specified),
4406+
this is <literal>0</literal>.
44074407
</entry>
44084408
</row>
44094409
<row>

doc/src/sgml/ref/pg_basebackup.sgml

+24-15
Original file line numberDiff line numberDiff line change
@@ -460,21 +460,6 @@ PostgreSQL documentation
460460
in this case the estimated target size will increase once it passes the
461461
total estimate without WAL.
462462
</para>
463-
<para>
464-
When this is enabled, the backup will start by enumerating the size of
465-
the entire database, and then go back and send the actual contents.
466-
This may make the backup take slightly longer, and in particular it
467-
will take longer before the first data is sent.
468-
</para>
469-
<para>
470-
Whether this is enabled or not, the
471-
<structname>pg_stat_progress_basebackup</structname> view
472-
report the progress of the backup in the server side. But note
473-
that the total amount of data that will be streamed is estimated
474-
and reported only when this option is enabled. In other words,
475-
<literal>backup_total</literal> column in the view always
476-
indicates <literal>0</literal> if this option is disabled.
477-
</para>
478463
</listitem>
479464
</varlistentry>
480465

@@ -552,6 +537,30 @@ PostgreSQL documentation
552537
</para>
553538
</listitem>
554539
</varlistentry>
540+
541+
<varlistentry>
542+
<term><option>--no-estimate-size</option></term>
543+
<listitem>
544+
<para>
545+
This option prevents the server from estimating the total
546+
amount of backup data that will be streamed, resulting in the
547+
<literal>backup_total</literal> column in the
548+
<structname>pg_stat_progress_basebackup</structname>
549+
to be <literal>0</literal>.
550+
</para>
551+
<para>
552+
Without this option, the backup will start by enumerating
553+
the size of the entire database, and then go back and send
554+
the actual contents. This may make the backup take slightly
555+
longer, and in particular it will take longer before the first
556+
data is sent. This option is useful to avoid such estimation
557+
time if it's too long.
558+
</para>
559+
<para>
560+
This option is not allowed when using <option>--progress</option>.
561+
</para>
562+
</listitem>
563+
</varlistentry>
555564
</variablelist>
556565
</para>
557566

src/bin/pg_basebackup/pg_basebackup.c

+15-1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ static char *label = "pg_basebackup base backup";
121121
static bool noclean = false;
122122
static bool checksum_failure = false;
123123
static bool showprogress = false;
124+
static bool estimatesize = true;
124125
static int verbose = 0;
125126
static int compresslevel = 0;
126127
static IncludeWal includewal = STREAM_WAL;
@@ -386,6 +387,7 @@ usage(void)
386387
printf(_(" --no-slot prevent creation of temporary replication slot\n"));
387388
printf(_(" --no-verify-checksums\n"
388389
" do not verify checksums\n"));
390+
printf(_(" --no-estimate-size do not estimate backup size in server side\n"));
389391
printf(_(" -?, --help show this help, then exit\n"));
390392
printf(_("\nConnection options:\n"));
391393
printf(_(" -d, --dbname=CONNSTR connection string\n"));
@@ -1741,7 +1743,7 @@ BaseBackup(void)
17411743
basebkp =
17421744
psprintf("BASE_BACKUP LABEL '%s' %s %s %s %s %s %s %s",
17431745
escaped_label,
1744-
showprogress ? "PROGRESS" : "",
1746+
estimatesize ? "PROGRESS" : "",
17451747
includewal == FETCH_WAL ? "WAL" : "",
17461748
fastcheckpoint ? "FAST" : "",
17471749
includewal == NO_WAL ? "" : "NOWAIT",
@@ -2066,6 +2068,7 @@ main(int argc, char **argv)
20662068
{"waldir", required_argument, NULL, 1},
20672069
{"no-slot", no_argument, NULL, 2},
20682070
{"no-verify-checksums", no_argument, NULL, 3},
2071+
{"no-estimate-size", no_argument, NULL, 4},
20692072
{NULL, 0, NULL, 0}
20702073
};
20712074
int c;
@@ -2234,6 +2237,9 @@ main(int argc, char **argv)
22342237
case 3:
22352238
verify_checksums = false;
22362239
break;
2240+
case 4:
2241+
estimatesize = false;
2242+
break;
22372243
default:
22382244

22392245
/*
@@ -2356,6 +2362,14 @@ main(int argc, char **argv)
23562362
}
23572363
#endif
23582364

2365+
if (showprogress && !estimatesize)
2366+
{
2367+
pg_log_error("--progress and --no-estimate-size are incompatible options");
2368+
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
2369+
progname);
2370+
exit(1);
2371+
}
2372+
23592373
/* connection in replication mode to server */
23602374
conn = GetConnection();
23612375
if (!conn)

0 commit comments

Comments
 (0)