Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Report NULL as total backup size if it's not estimated.
authorFujii Masao <fujii@postgresql.org>
Tue, 24 Mar 2020 01:43:41 +0000 (10:43 +0900)
committerFujii Masao <fujii@postgresql.org>
Tue, 24 Mar 2020 01:43:41 +0000 (10:43 +0900)
Previously 0 was reported in pg_stat_progress_basebackup.total_backup
if the total backup size was not estimated. Per discussion, our consensus
is that NULL is better choise as the value in total_backup in that case.
So this commit makes pg_stat_progress_basebackup view report NULL
in total_backup column if the estimation is disabled.

Bump catversion.

Author: Fujii Masao
Reviewed-by: Amit Langote, Magnus Hagander, Alvaro Herrera
Discussion: https://postgr.es/m/CABUevExnhOD89zBDuPvfAAh243RzNpwCPEWNLtMYpKHMB8gbAQ@mail.gmail.com

doc/src/sgml/monitoring.sgml
doc/src/sgml/ref/pg_basebackup.sgml
src/backend/catalog/system_views.sql
src/backend/replication/basebackup.c
src/include/catalog/catversion.h
src/test/regress/expected/rules.out

index 5bffdcce10de269a0372d9ff127b6348ebe96377..2bf540f8dba911cd2cf2b3edbe1459aaaaaf5d73 100644 (file)
@@ -4403,7 +4403,7 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS pid,
       total size. If the estimation is disabled in
       <application>pg_basebackup</application>
       (i.e., <literal>--no-estimate-size</literal> option is specified),
-      this is <literal>0</literal>.
+      this is <literal>NULL</literal>.
      </entry>
     </row>
     <row>
index 90638aad0e20f6fa6455c2aeedf7782863a0801f..c8e040bacfc0b93cbdc2f87151b684afb261bc62 100644 (file)
@@ -546,7 +546,7 @@ PostgreSQL documentation
         amount of backup data that will be streamed, resulting in the
         <literal>backup_total</literal> column in the
         <structname>pg_stat_progress_basebackup</structname>
-        to be <literal>0</literal>.
+        to be <literal>NULL</literal>.
        </para>
        <para>
         Without this option, the backup will start by enumerating
index b8a3f46912d2f6718f2f6e407ff8b062dc16ec36..5a6dc616301656c935486667897e6c3e475b310d 100644 (file)
@@ -1070,7 +1070,7 @@ CREATE VIEW pg_stat_progress_basebackup AS
                       WHEN 4 THEN 'waiting for wal archiving to finish'
                       WHEN 5 THEN 'transferring wal files'
                       END AS phase,
-   S.param2 AS backup_total,
+   CASE S.param2 WHEN -1 THEN NULL ELSE S.param2 END AS backup_total,
    S.param3 AS backup_streamed,
    S.param4 AS tablespaces_total,
    S.param5 AS tablespaces_streamed
index 806d013108d4b7d8634759509cffe9f19c25e252..a2e28b064cdd8246f19b678619b190fb0b8a20c5 100644 (file)
@@ -123,7 +123,10 @@ static long long int total_checksum_failures;
 /* Do not verify checksums. */
 static bool noverify_checksums = false;
 
-/* Total amount of backup data that will be streamed */
+/*
+ * Total amount of backup data that will be streamed.
+ * -1 means that the size is not estimated.
+ */
 static int64 backup_total = 0;
 
 /* Amount of backup data already streamed */
@@ -258,6 +261,18 @@ perform_base_backup(basebackup_options *opt)
    backup_streamed = 0;
    pgstat_progress_start_command(PROGRESS_COMMAND_BASEBACKUP, InvalidOid);
 
+   /*
+    * If the estimation of the total backup size is disabled, make the
+    * backup_total column in the view return NULL by setting the parameter to
+    * -1.
+    */
+   if (!opt->progress)
+   {
+       backup_total = -1;
+       pgstat_progress_update_param(PROGRESS_BASEBACKUP_BACKUP_TOTAL,
+                                    backup_total);
+   }
+
    datadirpathlen = strlen(DataDir);
 
    backup_started_in_recovery = RecoveryInProgress();
@@ -1842,7 +1857,7 @@ update_basebackup_progress(int64 delta)
     * will always be wrong if WAL is included), but that's better than having
     * the done column be bigger than the total.
     */
-   if (backup_total > 0 && backup_streamed > backup_total)
+   if (backup_total > -1 && backup_streamed > backup_total)
    {
        backup_total = backup_streamed;
        val[nparam++] = backup_total;
index 50069bea0e1da21d9c58c5849b6cc012e72e8c69..8aa18483e4e9527887ac1038aa49c2d1a960d085 100644 (file)
@@ -53,6 +53,6 @@
  */
 
 /*                         yyyymmddN */
-#define CATALOG_VERSION_NO 202003191
+#define CATALOG_VERSION_NO 202003241
 
 #endif
index c7304611c3ad0a8b46fa0c76b0025f00f101add1..a2077bbad4d8e7b49efb98f0a479f54bacb88569 100644 (file)
@@ -1886,7 +1886,10 @@ pg_stat_progress_basebackup| SELECT s.pid,
             WHEN 5 THEN 'transferring wal files'::text
             ELSE NULL::text
         END AS phase,
-    s.param2 AS backup_total,
+        CASE s.param2
+            WHEN '-1'::integer THEN NULL::bigint
+            ELSE s.param2
+        END AS backup_total,
     s.param3 AS backup_streamed,
     s.param4 AS tablespaces_total,
     s.param5 AS tablespaces_streamed