Add backup_type to pg_stat_progress_basebackup

Started by Shinya Kato6 months ago8 messages
#1Shinya Kato
shinya11.kato@gmail.com
1 attachment(s)

Hi hackers,

Starting with PostgreSQL 17, pg_basebackup supports incremental
backups. However, the pg_stat_progress_basebackup view doesn't
currently show the backup type (i.e., whether it's a full or
incremental backup).

Therefore, I propose adding a backup_type column to this view. While
this information is available in pg_stat_activity, the backup type is
important for monitoring the progress of pg_basebackup, and including
it directly in the progress view would be very useful.

Thoughts?

--
Best regards,
Shinya Kato
NTT OSS Center

Attachments:

v1-0001-Add-backup_type-to-pg_stat_progress_basebackup.patchapplication/octet-stream; name=v1-0001-Add-backup_type-to-pg_stat_progress_basebackup.patchDownload
From 742d9e424a85df8e4be0189193f67a81fdd0b5dd Mon Sep 17 00:00:00 2001
From: Shinya Kato <shinya11.kato@gmail.com>
Date: Tue, 8 Jul 2025 18:08:50 +0900
Subject: [PATCH v1] Add backup_type to pg_stat_progress_basebackup

This commit adds a new column, backup_type, to the
pg_stat_progress_basebackup view. This column displays 'full' for a full
backup and 'incremental' for an incremental backup.

With the introduction of incremental backups in PostgreSQL 17, being
able to distinguish between backup types is useful for monitoring
progress.
---
 doc/src/sgml/monitoring.sgml             | 10 ++++++++++
 src/backend/backup/basebackup.c          |  2 +-
 src/backend/backup/basebackup_progress.c |  6 +++++-
 src/backend/catalog/system_views.sql     |  5 ++++-
 src/include/backup/basebackup_sink.h     |  3 ++-
 src/include/commands/progress.h          |  5 +++++
 src/test/regress/expected/rules.out      |  7 ++++++-
 7 files changed, 33 insertions(+), 5 deletions(-)

diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml
index 823afe1b30b..3f1c72ee255 100644
--- a/doc/src/sgml/monitoring.sgml
+++ b/doc/src/sgml/monitoring.sgml
@@ -6780,6 +6780,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>bigint</type>
+      </para>
+      <para>
+        Backup type. Either <literal>full</literal> or
+        <literal>incremental</literal>.
+      </para></entry>
+     </row>
     </tbody>
    </tgroup>
   </table>
diff --git a/src/backend/backup/basebackup.c b/src/backend/backup/basebackup.c
index f0f88838dc2..bb7d90aa5d9 100644
--- a/src/backend/backup/basebackup.c
+++ b/src/backend/backup/basebackup.c
@@ -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
diff --git a/src/backend/backup/basebackup_progress.c b/src/backend/backup/basebackup_progress.c
index 1d22b541f89..9e1eccab60c 100644
--- a/src/backend/backup/basebackup_progress.c
+++ b/src/backend/backup/basebackup_progress.c
@@ -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;
 
@@ -73,6 +73,10 @@ bbsink_progress_new(bbsink *next, bool estimate_backup_size)
 	 */
 	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;
 }
diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql
index b2d5332effc..e8f923c485c 100644
--- a/src/backend/catalog/system_views.sql
+++ b/src/backend/catalog/system_views.sql
@@ -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;
 
 
diff --git a/src/include/backup/basebackup_sink.h b/src/include/backup/basebackup_sink.h
index 8a5ee996a45..310d92b8b9d 100644
--- a/src/include/backup/basebackup_sink.h
+++ b/src/include/backup/basebackup_sink.h
@@ -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);
 
diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h
index 7c736e7b03b..1cde4bd9bcf 100644
--- a/src/include/commands/progress.h
+++ b/src/include/commands/progress.h
@@ -130,6 +130,7 @@
 #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
@@ -138,6 +139,10 @@
 #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
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out
index dce8c672b40..90f94d33e3c 100644
--- a/src/test/regress/expected/rules.out
+++ b/src/test/regress/expected/rules.out
@@ -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,
-- 
2.47.1

#2Yugo Nagata
nagata@sraoss.co.jp
In reply to: Shinya Kato (#1)
Re: Add backup_type to pg_stat_progress_basebackup

On Tue, 22 Jul 2025 17:48:35 +0900
Shinya Kato <shinya11.kato@gmail.com> wrote:

Hi hackers,

Starting with PostgreSQL 17, pg_basebackup supports incremental
backups. However, the pg_stat_progress_basebackup view doesn't
currently show the backup type (i.e., whether it's a full or
incremental backup).

Therefore, I propose adding a backup_type column to this view. While
this information is available in pg_stat_activity, the backup type is
important for monitoring the progress of pg_basebackup, and including
it directly in the progress view would be very useful.

Thoughts?

That seems reasonable to me.

Just one minor comment on the patch:

+
+     <row>
+      <entry role="catalog_table_entry"><para role="column_definition">
+       <structfield>backup_type</structfield> <type>bigint</type>
+      </para>
+      <para>
+        Backup type. Either <literal>full</literal> or
+        <literal>incremental</literal>.
+      </para></entry>
+     </row>

The type should be text rather than bigint.

Regards,
Yugo Nagata

--
Yugo Nagata <nagata@sraoss.co.jp>

#3Shinya Kato
shinya11.kato@gmail.com
In reply to: Yugo Nagata (#2)
1 attachment(s)
Re: Add backup_type to pg_stat_progress_basebackup

On Tue, Jul 22, 2025 at 6:06 PM Yugo Nagata <nagata@sraoss.co.jp> wrote:

On Tue, 22 Jul 2025 17:48:35 +0900
Shinya Kato <shinya11.kato@gmail.com> wrote:

Hi hackers,

Starting with PostgreSQL 17, pg_basebackup supports incremental
backups. However, the pg_stat_progress_basebackup view doesn't
currently show the backup type (i.e., whether it's a full or
incremental backup).

Therefore, I propose adding a backup_type column to this view. While
this information is available in pg_stat_activity, the backup type is
important for monitoring the progress of pg_basebackup, and including
it directly in the progress view would be very useful.

Thoughts?

That seems reasonable to me.

Just one minor comment on the patch:

+
+     <row>
+      <entry role="catalog_table_entry"><para role="column_definition">
+       <structfield>backup_type</structfield> <type>bigint</type>
+      </para>
+      <para>
+        Backup type. Either <literal>full</literal> or
+        <literal>incremental</literal>.
+      </para></entry>
+     </row>

The type should be text rather than bigint.

Thank you for the review.
I made a careless mistake. Fixed.

--
Best regards,
Shinya Kato
NTT OSS Center

Attachments:

v2-0001-Add-backup_type-to-pg_stat_progress_basebackup.patchapplication/octet-stream; name=v2-0001-Add-backup_type-to-pg_stat_progress_basebackup.patchDownload
From dd2447460287cc8187fde43868ff2e5da3e41058 Mon Sep 17 00:00:00 2001
From: Shinya Kato <shinya11.kato@gmail.com>
Date: Tue, 8 Jul 2025 18:08:50 +0900
Subject: [PATCH v2] Add backup_type to pg_stat_progress_basebackup

This commit adds a new column, backup_type, to the
pg_stat_progress_basebackup view. This column displays 'full' for a full
backup and 'incremental' for an incremental backup.

With the introduction of incremental backups in PostgreSQL 17, being
able to distinguish between backup types is useful for monitoring
progress.
---
 doc/src/sgml/monitoring.sgml             | 10 ++++++++++
 src/backend/backup/basebackup.c          |  2 +-
 src/backend/backup/basebackup_progress.c |  6 +++++-
 src/backend/catalog/system_views.sql     |  5 ++++-
 src/include/backup/basebackup_sink.h     |  3 ++-
 src/include/commands/progress.h          |  5 +++++
 src/test/regress/expected/rules.out      |  7 ++++++-
 7 files changed, 33 insertions(+), 5 deletions(-)

diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml
index 823afe1b30b..cb657da06cf 100644
--- a/doc/src/sgml/monitoring.sgml
+++ b/doc/src/sgml/monitoring.sgml
@@ -6780,6 +6780,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>
diff --git a/src/backend/backup/basebackup.c b/src/backend/backup/basebackup.c
index f0f88838dc2..bb7d90aa5d9 100644
--- a/src/backend/backup/basebackup.c
+++ b/src/backend/backup/basebackup.c
@@ -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
diff --git a/src/backend/backup/basebackup_progress.c b/src/backend/backup/basebackup_progress.c
index 1d22b541f89..9e1eccab60c 100644
--- a/src/backend/backup/basebackup_progress.c
+++ b/src/backend/backup/basebackup_progress.c
@@ -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;
 
@@ -73,6 +73,10 @@ bbsink_progress_new(bbsink *next, bool estimate_backup_size)
 	 */
 	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;
 }
diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql
index b2d5332effc..e8f923c485c 100644
--- a/src/backend/catalog/system_views.sql
+++ b/src/backend/catalog/system_views.sql
@@ -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;
 
 
diff --git a/src/include/backup/basebackup_sink.h b/src/include/backup/basebackup_sink.h
index 8a5ee996a45..310d92b8b9d 100644
--- a/src/include/backup/basebackup_sink.h
+++ b/src/include/backup/basebackup_sink.h
@@ -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);
 
diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h
index 7c736e7b03b..1cde4bd9bcf 100644
--- a/src/include/commands/progress.h
+++ b/src/include/commands/progress.h
@@ -130,6 +130,7 @@
 #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
@@ -138,6 +139,10 @@
 #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
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out
index dce8c672b40..90f94d33e3c 100644
--- a/src/test/regress/expected/rules.out
+++ b/src/test/regress/expected/rules.out
@@ -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,
-- 
2.47.1

#4Masahiko Sawada
sawada.mshk@gmail.com
In reply to: Shinya Kato (#3)
1 attachment(s)
Re: Add backup_type to pg_stat_progress_basebackup

On Tue, Jul 22, 2025 at 2:42 AM Shinya Kato <shinya11.kato@gmail.com> wrote:

On Tue, Jul 22, 2025 at 6:06 PM Yugo Nagata <nagata@sraoss.co.jp> wrote:

On Tue, 22 Jul 2025 17:48:35 +0900
Shinya Kato <shinya11.kato@gmail.com> wrote:

Hi hackers,

Starting with PostgreSQL 17, pg_basebackup supports incremental
backups. However, the pg_stat_progress_basebackup view doesn't
currently show the backup type (i.e., whether it's a full or
incremental backup).

Therefore, I propose adding a backup_type column to this view. While
this information is available in pg_stat_activity, the backup type is
important for monitoring the progress of pg_basebackup, and including
it directly in the progress view would be very useful.

Thoughts?

That seems reasonable to me.

I like this idea.

Thank you for the review.
I made a careless mistake. Fixed.

The patch seems reasonably simple and looks good to me. I've updated
the comment in bbsink_progress_new() and attached the modified version
patch (with the commit message). Please review it.

Regards,

--
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com

Attachments:

v3-0001-Add-backup_type-column-to-pg_stat_progress_baseba.patchapplication/octet-stream; name=v3-0001-Add-backup_type-column-to-pg_stat_progress_baseba.patchDownload
From d9e52a6fdc2397478df9325869fe86b2d95ccae2 Mon Sep 17 00:00:00 2001
From: Masahiko Sawada <sawada.mshk@gmail.com>
Date: Fri, 1 Aug 2025 23:04:04 +0000
Subject: [PATCH v3] Add backup_type column to pg_stat_progress_basebackup.

This commit introduces a new column backup_type that indicates the
type of backup being performed: either 'full' or 'incremental'.

XXX: 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             | 10 ++++++++++
 src/backend/backup/basebackup.c          |  2 +-
 src/backend/backup/basebackup_progress.c | 13 +++++++++----
 src/backend/catalog/system_views.sql     |  5 ++++-
 src/include/backup/basebackup_sink.h     |  3 ++-
 src/include/commands/progress.h          |  5 +++++
 src/test/regress/expected/rules.out      |  7 ++++++-
 7 files changed, 37 insertions(+), 8 deletions(-)

diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml
index 823afe1b30b..cb657da06cf 100644
--- a/doc/src/sgml/monitoring.sgml
+++ b/doc/src/sgml/monitoring.sgml
@@ -6780,6 +6780,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>
diff --git a/src/backend/backup/basebackup.c b/src/backend/backup/basebackup.c
index f0f88838dc2..bb7d90aa5d9 100644
--- a/src/backend/backup/basebackup.c
+++ b/src/backend/backup/basebackup.c
@@ -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
diff --git a/src/backend/backup/basebackup_progress.c b/src/backend/backup/basebackup_progress.c
index 1d22b541f89..7080990e1dd 100644
--- a/src/backend/backup/basebackup_progress.c
+++ b/src/backend/backup/basebackup_progress.c
@@ -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;
 
@@ -67,12 +67,17 @@ bbsink_progress_new(bbsink *next, bool estimate_backup_size)
 	sink->bbs_next = next;
 
 	/*
-	 * 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.
+	 * Report that a base backup is in progress, and set the backup type and
+	 * the total size of the backup to -1, which will get translated to NULL,
+	 * and backup. If we're estimating the backup size, we'll insert the real
+	 * estimate when we have it.
 	 */
 	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;
 }
diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql
index f6eca09ee15..e6f3db2502f 100644
--- a/src/backend/catalog/system_views.sql
+++ b/src/backend/catalog/system_views.sql
@@ -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;
 
 
diff --git a/src/include/backup/basebackup_sink.h b/src/include/backup/basebackup_sink.h
index 8a5ee996a45..310d92b8b9d 100644
--- a/src/include/backup/basebackup_sink.h
+++ b/src/include/backup/basebackup_sink.h
@@ -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);
 
diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h
index 7c736e7b03b..1cde4bd9bcf 100644
--- a/src/include/commands/progress.h
+++ b/src/include/commands/progress.h
@@ -130,6 +130,7 @@
 #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
@@ -138,6 +139,10 @@
 #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
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out
index dce8c672b40..90f94d33e3c 100644
--- a/src/test/regress/expected/rules.out
+++ b/src/test/regress/expected/rules.out
@@ -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,
-- 
2.47.3

#5Shinya Kato
shinya11.kato@gmail.com
In reply to: Masahiko Sawada (#4)
Re: Add backup_type to pg_stat_progress_basebackup

On Sat, Aug 2, 2025 at 8:12 AM Masahiko Sawada <sawada.mshk@gmail.com> wrote:

On Tue, Jul 22, 2025 at 2:42 AM Shinya Kato <shinya11.kato@gmail.com> wrote:

On Tue, Jul 22, 2025 at 6:06 PM Yugo Nagata <nagata@sraoss.co.jp> wrote:

On Tue, 22 Jul 2025 17:48:35 +0900
Shinya Kato <shinya11.kato@gmail.com> wrote:

Hi hackers,

Starting with PostgreSQL 17, pg_basebackup supports incremental
backups. However, the pg_stat_progress_basebackup view doesn't
currently show the backup type (i.e., whether it's a full or
incremental backup).

Therefore, I propose adding a backup_type column to this view. While
this information is available in pg_stat_activity, the backup type is
important for monitoring the progress of pg_basebackup, and including
it directly in the progress view would be very useful.

Thoughts?

That seems reasonable to me.

I like this idea.

Thank you for reviewing my patch!

Thank you for the review.
I made a careless mistake. Fixed.

The patch seems reasonably simple and looks good to me. I've updated
the comment in bbsink_progress_new() and attached the modified version
patch (with the commit message). Please review it.

Thanks for the patch. I reviewed it, and LGTM.

--
Best regards,
Shinya Kato
NTT OSS Center

#6Yugo Nagata
nagata@sraoss.co.jp
In reply to: Masahiko Sawada (#4)
Re: Add backup_type to pg_stat_progress_basebackup

On Fri, 1 Aug 2025 16:12:15 -0700
Masahiko Sawada <sawada.mshk@gmail.com> wrote:

The patch seems reasonably simple and looks good to me. I've updated
the comment in bbsink_progress_new() and attached the modified version
patch (with the commit message). Please review it.

 	/*
-	 * 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.
+	 * Report that a base backup is in progress, and set the backup type and
+	 * the total size of the backup to -1, which will get translated to NULL,
+	 * and backup. If we're estimating the backup size, we'll insert the real
+	 * estimate when we have it.
 	 */

It seems to me that "set the backup type and the total size of the backup to -1"
is a bit confusing because it could be read that the backup type would be also set
to -1, and the subsequent sentence describes just the total size.

Therefore, I think it is better to just add "Also, the backup type is set."
(or similar) to the end of the comment block.

That said, I'm not a native English speaker, so if no one else sees a problem,
I'm fine with it.

Regards,
Yugo Nagata

--
Yugo Nagata <nagata@sraoss.co.jp>

#7Masahiko Sawada
sawada.mshk@gmail.com
In reply to: Yugo Nagata (#6)
Re: Add backup_type to pg_stat_progress_basebackup

On Mon, Aug 4, 2025 at 1:57 AM Yugo Nagata <nagata@sraoss.co.jp> wrote:

On Fri, 1 Aug 2025 16:12:15 -0700
Masahiko Sawada <sawada.mshk@gmail.com> wrote:

The patch seems reasonably simple and looks good to me. I've updated
the comment in bbsink_progress_new() and attached the modified version
patch (with the commit message). Please review it.

/*
-        * 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.
+        * Report that a base backup is in progress, and set the backup type and
+        * the total size of the backup to -1, which will get translated to NULL,
+        * and backup. If we're estimating the backup size, we'll insert the real
+        * estimate when we have it.
*/

It seems to me that "set the backup type and the total size of the backup to -1"
is a bit confusing because it could be read that the backup type would be also set
to -1, and the subsequent sentence describes just the total size.

Therefore, I think it is better to just add "Also, the backup type is set."
(or similar) to the end of the comment block.

That said, I'm not a native English speaker, so if no one else sees a problem,
I'm fine with it.

Agreed. I've changed the comment and pushed the patch.

Regards,

--
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com

#8Shinya Kato
shinya11.kato@gmail.com
In reply to: Masahiko Sawada (#7)
Re: Add backup_type to pg_stat_progress_basebackup

On Wed, Aug 6, 2025 at 3:06 AM Masahiko Sawada <sawada.mshk@gmail.com> wrote:

On Mon, Aug 4, 2025 at 1:57 AM Yugo Nagata <nagata@sraoss.co.jp> wrote:

On Fri, 1 Aug 2025 16:12:15 -0700
Masahiko Sawada <sawada.mshk@gmail.com> wrote:

The patch seems reasonably simple and looks good to me. I've updated
the comment in bbsink_progress_new() and attached the modified version
patch (with the commit message). Please review it.

/*
-        * 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.
+        * Report that a base backup is in progress, and set the backup type and
+        * the total size of the backup to -1, which will get translated to NULL,
+        * and backup. If we're estimating the backup size, we'll insert the real
+        * estimate when we have it.
*/

It seems to me that "set the backup type and the total size of the backup to -1"
is a bit confusing because it could be read that the backup type would be also set
to -1, and the subsequent sentence describes just the total size.

Therefore, I think it is better to just add "Also, the backup type is set."
(or similar) to the end of the comment block.

That said, I'm not a native English speaker, so if no one else sees a problem,
I'm fine with it.

Agreed. I've changed the comment and pushed the patch.

Regards,

--
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com

Thanks for pushing it!

--
Best regards,
Shinya Kato
NTT OSS Center