]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Add backup_type column to pg_stat_progress_basebackup.
authorMasahiko Sawada <msawada@postgresql.org>
Tue, 5 Aug 2025 17:50:45 +0000 (10:50 -0700)
committerMasahiko Sawada <msawada@postgresql.org>
Tue, 5 Aug 2025 17:50:45 +0000 (10:50 -0700)
This commit introduces a new column backup_type that indicates the
type of backup being performed: either 'full' or 'incremental'.

Bump catalog version.

Author: Shinya Kato <shinya11.kato@gmail.com>
Reviewed-by: Yugo Nagata <nagata@sraoss.co.jp>
Discussion: https://postgr.es/m/CAOzEurQuzbHwTj1ehk1a+eeQDidJPyrE5s6mYumkjwjZnurhkQ@mail.gmail.com

doc/src/sgml/monitoring.sgml
src/backend/backup/basebackup.c
src/backend/backup/basebackup_progress.c
src/backend/catalog/system_views.sql
src/include/backup/basebackup_sink.h
src/include/catalog/catversion.h
src/include/commands/progress.h
src/test/regress/expected/rules.out

index fa78031ccbbf08ea9d7654a0d80d70a025d318fb..3f4a27a736e272013a5aaa148dd0c4da5e1daa9f 100644 (file)
@@ -6791,6 +6791,16 @@ FROM pg_stat_get_backend_idset() AS backendid;
        advances when the phase is <literal>streaming database files</literal>.
       </para></entry>
      </row>
+
+     <row>
+      <entry role="catalog_table_entry"><para role="column_definition">
+       <structfield>backup_type</structfield> <type>text</type>
+      </para>
+      <para>
+        Backup type. Either <literal>full</literal> or
+        <literal>incremental</literal>.
+      </para></entry>
+     </row>
     </tbody>
    </tgroup>
   </table>
index f0f88838dc21aa3d7e906176ef50ca6d0cef4114..bb7d90aa5d9637d61b554d99fff062a1bf176d4f 100644 (file)
@@ -1048,7 +1048,7 @@ SendBaseBackup(BaseBackupCmd *cmd, IncrementalBackupInfo *ib)
                sink = bbsink_zstd_new(sink, &opt.compression_specification);
 
        /* Set up progress reporting. */
-       sink = bbsink_progress_new(sink, opt.progress);
+       sink = bbsink_progress_new(sink, opt.progress, opt.incremental);
 
        /*
         * Perform the base backup, but make sure we clean up the bbsink even if
index 1d22b541f89af1e9281d32c2f9851f7c0c1e230d..dac205936229bbe930c3ade0aa3b684f03b96534 100644 (file)
@@ -56,7 +56,7 @@ static const bbsink_ops bbsink_progress_ops = {
  * forwards data to a successor sink.
  */
 bbsink *
-bbsink_progress_new(bbsink *next, bool estimate_backup_size)
+bbsink_progress_new(bbsink *next, bool estimate_backup_size, bool incremental)
 {
        bbsink     *sink;
 
@@ -69,10 +69,15 @@ bbsink_progress_new(bbsink *next, bool estimate_backup_size)
        /*
         * Report that a base backup is in progress, and set the total size of the
         * backup to -1, which will get translated to NULL. If we're estimating
-        * the backup size, we'll insert the real estimate when we have it.
+        * the backup size, we'll insert the real estimate when we have it. Also,
+        * the backup type is set.
         */
        pgstat_progress_start_command(PROGRESS_COMMAND_BASEBACKUP, InvalidOid);
        pgstat_progress_update_param(PROGRESS_BASEBACKUP_BACKUP_TOTAL, -1);
+       pgstat_progress_update_param(PROGRESS_BASEBACKUP_BACKUP_TYPE,
+                                                                incremental
+                                                                ? PROGRESS_BASEBACKUP_BACKUP_TYPE_INCREMENTAL
+                                                                : PROGRESS_BASEBACKUP_BACKUP_TYPE_FULL);
 
        return sink;
 }
index 77c693f630e4b9f6dc2ebc9319bbd450658c98bb..1b3c5a55882dff95a4b7df7126591ce2ace29c21 100644 (file)
@@ -1327,7 +1327,10 @@ CREATE VIEW pg_stat_progress_basebackup AS
         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
+        S.param5 AS tablespaces_streamed,
+        CASE S.param6 WHEN 1 THEN 'full'
+                      WHEN 2 THEN 'incremental'
+                      END AS backup_type
     FROM pg_stat_get_progress_info('BASEBACKUP') AS S;
 
 
index 8a5ee996a45ed14e20062973296f51f25dcbff89..310d92b8b9d452a617bc851ea9ecda26b28174bc 100644 (file)
@@ -287,7 +287,8 @@ extern bbsink *bbsink_copystream_new(bool send_to_client);
 extern bbsink *bbsink_gzip_new(bbsink *next, pg_compress_specification *);
 extern bbsink *bbsink_lz4_new(bbsink *next, pg_compress_specification *);
 extern bbsink *bbsink_zstd_new(bbsink *next, pg_compress_specification *);
-extern bbsink *bbsink_progress_new(bbsink *next, bool estimate_backup_size);
+extern bbsink *bbsink_progress_new(bbsink *next, bool estimate_backup_size,
+                                                                  bool incremental);
 extern bbsink *bbsink_server_new(bbsink *next, char *pathname);
 extern bbsink *bbsink_throttle_new(bbsink *next, uint32 maxrate);
 
index 750a9d8a09b25978f4d949c886854d6aad7b1c76..c4fe8b991af469712cd5b4fa8bd55b062f84d39d 100644 (file)
@@ -57,6 +57,6 @@
  */
 
 /*                                                     yyyymmddN */
-#define CATALOG_VERSION_NO     202508041
+#define CATALOG_VERSION_NO     202508051
 
 #endif
index 7c736e7b03bcf251fea929ff2edfa3ed0b27004f..1cde4bd9bcf14a50c5ce7e1309841a9d2e5ad28a 100644 (file)
 #define PROGRESS_BASEBACKUP_BACKUP_STREAMED                    2
 #define PROGRESS_BASEBACKUP_TBLSPC_TOTAL                       3
 #define PROGRESS_BASEBACKUP_TBLSPC_STREAMED                    4
+#define PROGRESS_BASEBACKUP_BACKUP_TYPE                                5
 
 /* Phases of pg_basebackup (as advertised via PROGRESS_BASEBACKUP_PHASE) */
 #define PROGRESS_BASEBACKUP_PHASE_WAIT_CHECKPOINT              1
 #define PROGRESS_BASEBACKUP_PHASE_WAIT_WAL_ARCHIVE             4
 #define PROGRESS_BASEBACKUP_PHASE_TRANSFER_WAL                 5
 
+/* Types of pg_basebackup (as advertised via PROGRESS_BASEBACKUP_BACKUP_TYPE) */
+#define PROGRESS_BASEBACKUP_BACKUP_TYPE_FULL                   1
+#define PROGRESS_BASEBACKUP_BACKUP_TYPE_INCREMENTAL            2
+
 /* Progress parameters for PROGRESS_COPY */
 #define PROGRESS_COPY_BYTES_PROCESSED 0
 #define PROGRESS_COPY_BYTES_TOTAL 1
index 6509fda77a994ccf849f2aafaf486c56c10af7c6..35e8aad7701be12eaec6a3a28d015049e098b3b4 100644 (file)
@@ -1977,7 +1977,12 @@ pg_stat_progress_basebackup| SELECT pid,
         END AS backup_total,
     param3 AS backup_streamed,
     param4 AS tablespaces_total,
-    param5 AS tablespaces_streamed
+    param5 AS tablespaces_streamed,
+        CASE param6
+            WHEN 1 THEN 'full'::text
+            WHEN 2 THEN 'incremental'::text
+            ELSE NULL::text
+        END AS backup_type
    FROM pg_stat_get_progress_info('BASEBACKUP'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20);
 pg_stat_progress_cluster| SELECT s.pid,
     s.datid,