0002-Support-toggling-of-pg_checksums-progress-reporting-.patch
text/x-patch
Filename: 0002-Support-toggling-of-pg_checksums-progress-reporting-.patch
Type: text/x-patch
Part: 1
Patch
Format: format-patch
Series: patch 0002
Subject: Support toggling of pg_checksums progress reporting via SIGUSR1.
| File | + | − |
|---|---|---|
| doc/src/sgml/ref/pg_checksums.sgml | 3 | 1 |
| src/bin/pg_checksums/pg_checksums.c | 37 | 14 |
From 78d551ec7e5151dceee2d182a8f258fdc4b59554 Mon Sep 17 00:00:00 2001
From: Michael Banck <mbanck@debian.org>
Date: Thu, 28 Mar 2019 10:57:11 +0100
Subject: [PATCH 2/2] Support toggling of pg_checksums progress reporting via
SIGUSR1.
This feature does not work on Windows.
Author: Bernd Helmle, Michael Banck
Reviewed-by: Fabien Coelho, Alvaro Herrera, Michael Paquier, Kyotaro HORIGUCHI
---
doc/src/sgml/ref/pg_checksums.sgml | 4 ++-
src/bin/pg_checksums/pg_checksums.c | 51 +++++++++++++++++++++++++++----------
2 files changed, 40 insertions(+), 15 deletions(-)
diff --git a/doc/src/sgml/ref/pg_checksums.sgml b/doc/src/sgml/ref/pg_checksums.sgml
index 0934426e58..9f5cbc79ff 100644
--- a/doc/src/sgml/ref/pg_checksums.sgml
+++ b/doc/src/sgml/ref/pg_checksums.sgml
@@ -141,7 +141,9 @@ PostgreSQL documentation
<listitem>
<para>
Enable progress reporting. Turning this on will deliver a progress
- report while checking or enabling checksums.
+ report while checking or enabling checksums. Sending the
+ <systemitem>SIGUSR1</systemitem> signal will toggle progress reporting
+ on or off during the verification run (not available on Windows).
</para>
</listitem>
</varlistentry>
diff --git a/src/bin/pg_checksums/pg_checksums.c b/src/bin/pg_checksums/pg_checksums.c
index d09cf8068d..bc7f29c3c4 100644
--- a/src/bin/pg_checksums/pg_checksums.c
+++ b/src/bin/pg_checksums/pg_checksums.c
@@ -15,6 +15,7 @@
#include "postgres_fe.h"
#include <dirent.h>
+#include <signal.h>
#include <time.h>
#include <sys/stat.h>
#include <unistd.h>
@@ -109,6 +110,23 @@ static const char *const skip[] = {
NULL,
};
+static void
+toggle_progress_report(int signum)
+{
+
+ /* we handle SIGUSR1 only, and toggle the value of show_progress */
+ if (signum == SIGUSR1)
+ {
+ /*
+ * Skip to the next line in order to avoid overwriting half of
+ * the progress report line with the final output.
+ */
+ if (show_progress && isatty(fileno(stderr)))
+ fprintf(stderr, "\n");
+ show_progress = !show_progress;
+ }
+}
+
/*
* Report current progress status. Parts borrowed from
* PostgreSQLs' src/bin/pg_basebackup.c
@@ -529,23 +547,28 @@ main(int argc, char *argv[])
exit(1);
}
+#ifndef WIN32
/*
- * If progress status information is requested, we need to scan the
- * directory tree(s) twice, once to get the idea how much data we need to
- * scan and finally to do the real legwork.
+ * Assign SIGUSR1 signal handler to toggle progress status information
*/
- if (show_progress)
- {
- total_size = scan_directory(DataDir, "global", true);
- total_size += scan_directory(DataDir, "base", true);
- total_size += scan_directory(DataDir, "pg_tblspc", true);
+ pqsignal(SIGUSR1, toggle_progress_report);
+#endif
- /*
- * Remember start time. Required to calculate the current speed in
- * report_progress().
- */
- INSTR_TIME_SET_CURRENT(scan_started);
- }
+ /*
+ * As progress status information may be requested even after start of
+ * operation, we need to scan the directory tree(s) twice, once to get
+ * the idea how much data we need to scan and finally to do the real
+ * legwork.
+ */
+ total_size = scan_directory(DataDir, "global", true);
+ total_size += scan_directory(DataDir, "base", true);
+ total_size += scan_directory(DataDir, "pg_tblspc", true);
+
+ /*
+ * Remember start time. Required to calculate the current speed in
+ * report_progress()
+ */
+ INSTR_TIME_SET_CURRENT(scan_started);
if (ControlFile->data_checksum_version == 0 &&
mode == PG_MODE_DISABLE)
--
2.11.0