v17-0001-pg_waldump-Add-quiet-option.patch

application/octet-stream

Filename: v17-0001-pg_waldump-Add-quiet-option.patch
Type: application/octet-stream
Part: 1
Message: Re: backup manifests

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: format-patch
Series: patch v17-0001
Subject: pg_waldump: Add --quiet option.
File+
doc/src/sgml/ref/pg_waldump.sgml 12 0
src/bin/pg_waldump/pg_waldump.c 16 6
From 7121aed863b68596b71aad21d60718e075781ff0 Mon Sep 17 00:00:00 2001
From: Robert Haas <rhaas@postgresql.org>
Date: Tue, 31 Mar 2020 08:13:25 -0400
Subject: [PATCH v17 1/3] pg_waldump: Add --quiet option.

Andres Freund and Robert Haas
---
 doc/src/sgml/ref/pg_waldump.sgml | 12 ++++++++++++
 src/bin/pg_waldump/pg_waldump.c  | 22 ++++++++++++++++------
 2 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/doc/src/sgml/ref/pg_waldump.sgml b/doc/src/sgml/ref/pg_waldump.sgml
index 667093f060..431f6af9d2 100644
--- a/doc/src/sgml/ref/pg_waldump.sgml
+++ b/doc/src/sgml/ref/pg_waldump.sgml
@@ -125,6 +125,18 @@ PostgreSQL documentation
       </listitem>
      </varlistentry>
 
+     <varlistentry>
+      <term><option>-q</option></term>
+      <term><option>--quiet</option></term>
+      <listitem>
+       <para>
+        Do not print any output, except for errors. This option can be useful
+        when you want to know whether a range of WAL records can be
+        succesfully parsed but don't care about the record contents.
+       </para>
+      </listitem>
+     </varlistentry>
+
      <varlistentry>
       <term><option>-r <replaceable>rmgr</replaceable></option></term>
       <term><option>--rmgr=<replaceable>rmgr</replaceable></option></term>
diff --git a/src/bin/pg_waldump/pg_waldump.c b/src/bin/pg_waldump/pg_waldump.c
index 279acfa044..7c80b5288f 100644
--- a/src/bin/pg_waldump/pg_waldump.c
+++ b/src/bin/pg_waldump/pg_waldump.c
@@ -40,6 +40,7 @@ typedef struct XLogDumpPrivate
 typedef struct XLogDumpConfig
 {
 	/* display options */
+	bool		quiet;
 	bool		bkp_details;
 	int			stop_after_records;
 	int			already_displayed_records;
@@ -720,6 +721,7 @@ usage(void)
 	printf(_("  -p, --path=PATH        directory in which to find log segment files or a\n"
 			 "                         directory with a ./pg_wal that contains such files\n"
 			 "                         (default: current directory, ./pg_wal, $PGDATA/pg_wal)\n"));
+	printf(_("  -q, --quiet            do not print any output, except for errors\n"));
 	printf(_("  -r, --rmgr=RMGR        only show records generated by resource manager RMGR;\n"
 			 "                         use --rmgr=list to list valid resource manager names\n"));
 	printf(_("  -s, --start=RECPTR     start reading at WAL location RECPTR\n"));
@@ -755,6 +757,7 @@ main(int argc, char **argv)
 		{"help", no_argument, NULL, '?'},
 		{"limit", required_argument, NULL, 'n'},
 		{"path", required_argument, NULL, 'p'},
+		{"quiet", no_argument, NULL, 'q'},
 		{"rmgr", required_argument, NULL, 'r'},
 		{"start", required_argument, NULL, 's'},
 		{"timeline", required_argument, NULL, 't'},
@@ -794,6 +797,7 @@ main(int argc, char **argv)
 	private.endptr = InvalidXLogRecPtr;
 	private.endptr_reached = false;
 
+	config.quiet = false;
 	config.bkp_details = false;
 	config.stop_after_records = -1;
 	config.already_displayed_records = 0;
@@ -810,7 +814,7 @@ main(int argc, char **argv)
 		goto bad_argument;
 	}
 
-	while ((option = getopt_long(argc, argv, "be:fn:p:r:s:t:x:z",
+	while ((option = getopt_long(argc, argv, "be:fn:p:qr:s:t:x:z",
 								 long_options, &optindex)) != -1)
 	{
 		switch (option)
@@ -840,6 +844,9 @@ main(int argc, char **argv)
 			case 'p':
 				waldir = pg_strdup(optarg);
 				break;
+			case 'q':
+				config.quiet = true;
+				break;
 			case 'r':
 				{
 					int			i;
@@ -1075,11 +1082,14 @@ main(int argc, char **argv)
 			config.filter_by_xid != record->xl_xid)
 			continue;
 
-		/* process the record */
-		if (config.stats == true)
-			XLogDumpCountRecord(&config, &stats, xlogreader_state);
-		else
-			XLogDumpDisplayRecord(&config, xlogreader_state);
+		/* perform any per-record work */
+		if (!config.quiet)
+		{
+			if (config.stats == true)
+				XLogDumpCountRecord(&config, &stats, xlogreader_state);
+			else
+				XLogDumpDisplayRecord(&config, xlogreader_state);
+		}
 
 		/* check whether we printed enough */
 		config.already_displayed_records++;
-- 
2.17.2 (Apple Git-113)