pg_verify_checksums -r option

Started by Peter Eisentrautover 7 years ago25 messages
#1Peter Eisentraut
peter.eisentraut@2ndquadrant.com

I'm curious about this option:

-r RELFILENODE check only relation with specified relfilenode

but there is no facility to specify a database.

Also, referring to the relfilenode of a mapped relation seems a bit
inaccurate.

Maybe reframing this in terms of the file name of the file you want
checked would be better?

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

#2Yugo Nagata
nagata@sraoss.co.jp
In reply to: Peter Eisentraut (#1)
Re: pg_verify_checksums -r option

On Fri, 24 Aug 2018 18:01:09 +0200
Peter Eisentraut <peter.eisentraut@2ndquadrant.com> wrote:

I'm curious about this option:

-r RELFILENODE check only relation with specified relfilenode

but there is no facility to specify a database.

Also, referring to the relfilenode of a mapped relation seems a bit
inaccurate.

Maybe reframing this in terms of the file name of the file you want
checked would be better?

If we specified 1234 to -r option, pg_verify_shceksums checks not only 1234
but also 1234_vm, 1234_fsm, and 1234.1, 1234.2, ... and so on, so I think
it makes senses to allow to specify a relfilenode instead of a file name.

I think it is reasonable to add a option to specify a database, although
I don't know which character is good because both -d and -D are already used....

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

#3Michael Banck
michael.banck@credativ.de
In reply to: Yugo Nagata (#2)
pg_verify_checksums -d option (was: Re: pg_verify_checksums -r option)

Hi,

On Mon, Aug 27, 2018 at 07:53:36PM +0900, Yugo Nagata wrote:

On Fri, 24 Aug 2018 18:01:09 +0200
Peter Eisentraut <peter.eisentraut@2ndquadrant.com> wrote:

I'm curious about this option:

-r RELFILENODE check only relation with specified relfilenode

but there is no facility to specify a database.

Also, referring to the relfilenode of a mapped relation seems a bit
inaccurate.

Maybe reframing this in terms of the file name of the file you want
checked would be better?

If we specified 1234 to -r option, pg_verify_shceksums checks not only 1234
but also 1234_vm, 1234_fsm, and 1234.1, 1234.2, ... and so on, so I think
it makes senses to allow to specify a relfilenode instead of a file name.

I think it is reasonable to add a option to specify a database, although
I don't know which character is good because both -d and -D are already used....

Maybe the -d (debug) option should be revisited as well. Mentioning
every scanned block generates a huge amount of output which might be
useful during development but does not seem very useful for a stable
release. AFAICT there is no other debug output for now.

So it could be renamed to -v (verbose) and only mention each scanned
file, e.g. (errors/checksum mismatches are still reported of course).

Then -d could (in the future, I guess that is too late for v11) be used
for -d/--dbname (or make that only a long option, if the above does not
work).

Michael

--
Michael Banck
Projektleiter / Senior Berater
Tel.: +49 2166 9901-171
Fax: +49 2166 9901-100
Email: michael.banck@credativ.de

credativ GmbH, HRB M�nchengladbach 12080
USt-ID-Nummer: DE204566209
Trompeterallee 108, 41189 M�nchengladbach
Gesch�ftsf�hrung: Dr. Michael Meskes, J�rg Folz, Sascha Heuer

Unser Umgang mit personenbezogenen Daten unterliegt
folgenden Bestimmungen: https://www.credativ.de/datenschutz

#4Yugo Nagata
nagata@sraoss.co.jp
In reply to: Michael Banck (#3)
Re: pg_verify_checksums -d option (was: Re: pg_verify_checksums -r option)

On Mon, 27 Aug 2018 13:34:12 +0200
Michael Banck <michael.banck@credativ.de> wrote:

Hi,

On Mon, Aug 27, 2018 at 07:53:36PM +0900, Yugo Nagata wrote:

On Fri, 24 Aug 2018 18:01:09 +0200
Peter Eisentraut <peter.eisentraut@2ndquadrant.com> wrote:

I'm curious about this option:

-r RELFILENODE check only relation with specified relfilenode

but there is no facility to specify a database.

Also, referring to the relfilenode of a mapped relation seems a bit
inaccurate.

Maybe reframing this in terms of the file name of the file you want
checked would be better?

If we specified 1234 to -r option, pg_verify_shceksums checks not only 1234
but also 1234_vm, 1234_fsm, and 1234.1, 1234.2, ... and so on, so I think
it makes senses to allow to specify a relfilenode instead of a file name.

I think it is reasonable to add a option to specify a database, although
I don't know which character is good because both -d and -D are already used....

Maybe the -d (debug) option should be revisited as well. Mentioning
every scanned block generates a huge amount of output which might be
useful during development but does not seem very useful for a stable
release. AFAICT there is no other debug output for now.

So it could be renamed to -v (verbose) and only mention each scanned
file, e.g. (errors/checksum mismatches are still reported of course).

Then -d could (in the future, I guess that is too late for v11) be used
for -d/--dbname (or make that only a long option, if the above does not
work).

I realized after sending the previous post that we can not specify a database
by name because pg_verify_checksum is run in offline and this can not get the
OID from the database name. Also, there are global and pg_tblspc directories
not only base/<database OID>. So, it seems to me good to specify a directories
to scan which is under PGDATA. We would be able to use -d ( or --directory ?)
for this purpose.

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

#5Daniel Gustafsson
daniel@yesql.se
In reply to: Yugo Nagata (#4)
Re: pg_verify_checksums -d option (was: Re: pg_verify_checksums -r option)

On 27 Aug 2018, at 14:05, Yugo Nagata <nagata@sraoss.co.jp> wrote:

On Mon, 27 Aug 2018 13:34:12 +0200
Michael Banck <michael.banck@credativ.de> wrote:

Hi,

On Mon, Aug 27, 2018 at 07:53:36PM +0900, Yugo Nagata wrote:

On Fri, 24 Aug 2018 18:01:09 +0200
Peter Eisentraut <peter.eisentraut@2ndquadrant.com> wrote:

I'm curious about this option:

-r RELFILENODE check only relation with specified relfilenode

but there is no facility to specify a database.

Also, referring to the relfilenode of a mapped relation seems a bit
inaccurate.

Maybe reframing this in terms of the file name of the file you want
checked would be better?

If we specified 1234 to -r option, pg_verify_shceksums checks not only 1234
but also 1234_vm, 1234_fsm, and 1234.1, 1234.2, ... and so on, so I think
it makes senses to allow to specify a relfilenode instead of a file name.

I think it is reasonable to add a option to specify a database, although
I don't know which character is good because both -d and -D are already used....

Maybe the -d (debug) option should be revisited as well. Mentioning
every scanned block generates a huge amount of output which might be
useful during development but does not seem very useful for a stable
release. AFAICT there is no other debug output for now.

So it could be renamed to -v (verbose) and only mention each scanned
file, e.g. (errors/checksum mismatches are still reported of course).

Then -d could (in the future, I guess that is too late for v11) be used
for -d/--dbname (or make that only a long option, if the above does not
work).

I realized after sending the previous post that we can not specify a database
by name because pg_verify_checksum is run in offline and this can not get the
OID from the database name. Also, there are global and pg_tblspc directories
not only base/<database OID>. So, it seems to me good to specify a directories
to scan which is under PGDATA. We would be able to use -d ( or --directory ?)
for this purpose.

Changing functionality to the above discussed is obviously 12 material, but
since we are discussing changing the command line API of the tool by
repurposing -d; do we want to rename the current use of -d to -v (with the
accompanying —-verbose) before 11 ships? It’s clearly way way too late in the
cycle but it seems worth to at least bring up since 11 will be the first
version pg_verify_checksums ship in. I’m happy to do the work asap if so.

FWIW, personally I think verbose makes more sense for the output than debug.

cheers ./daniel

#6Yugo Nagata
nagata@sraoss.co.jp
In reply to: Daniel Gustafsson (#5)
1 attachment(s)
Re: pg_verify_checksums -d option (was: Re: pg_verify_checksums -r option)

On Wed, 29 Aug 2018 10:28:33 +0200
Daniel Gustafsson <daniel@yesql.se> wrote:

On 27 Aug 2018, at 14:05, Yugo Nagata <nagata@sraoss.co.jp> wrote:

On Mon, 27 Aug 2018 13:34:12 +0200
Michael Banck <michael.banck@credativ.de> wrote:

Hi,

On Mon, Aug 27, 2018 at 07:53:36PM +0900, Yugo Nagata wrote:

On Fri, 24 Aug 2018 18:01:09 +0200
Peter Eisentraut <peter.eisentraut@2ndquadrant.com> wrote:

I'm curious about this option:

-r RELFILENODE check only relation with specified relfilenode

but there is no facility to specify a database.

Also, referring to the relfilenode of a mapped relation seems a bit
inaccurate.

Maybe reframing this in terms of the file name of the file you want
checked would be better?

If we specified 1234 to -r option, pg_verify_shceksums checks not only 1234
but also 1234_vm, 1234_fsm, and 1234.1, 1234.2, ... and so on, so I think
it makes senses to allow to specify a relfilenode instead of a file name.

I think it is reasonable to add a option to specify a database, although
I don't know which character is good because both -d and -D are already used....

Maybe the -d (debug) option should be revisited as well. Mentioning
every scanned block generates a huge amount of output which might be
useful during development but does not seem very useful for a stable
release. AFAICT there is no other debug output for now.

So it could be renamed to -v (verbose) and only mention each scanned
file, e.g. (errors/checksum mismatches are still reported of course).

Then -d could (in the future, I guess that is too late for v11) be used
for -d/--dbname (or make that only a long option, if the above does not
work).

I realized after sending the previous post that we can not specify a database
by name because pg_verify_checksum is run in offline and this can not get the
OID from the database name. Also, there are global and pg_tblspc directories
not only base/<database OID>. So, it seems to me good to specify a directories
to scan which is under PGDATA. We would be able to use -d ( or --directory ?)
for this purpose.

Changing functionality to the above discussed is obviously 12 material, but
since we are discussing changing the command line API of the tool by
repurposing -d; do we want to rename the current use of -d to -v (with the
accompanying —-verbose) before 11 ships? It’s clearly way way too late in the
cycle but it seems worth to at least bring up since 11 will be the first
version pg_verify_checksums ship in. I’m happy to do the work asap if so.

I agree with this. Almost other commands doesn't use -d as debug mode
although there a few exception, and instead -v is used for verbose mode.
If we can change the command line of pg_veriry_checksums, before release of
PG 11 is best. Attached is the patch to do this.

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

Attachments:

01_pg_veriify_checksum_debug_to_verbose.patchtext/x-diff; name=01_pg_veriify_checksum_debug_to_verbose.patchDownload
commit 452f981c30c9d9c7263e6006dc4cda51278ff376
Author: Yugo Nagata <nagata@sraoss.co.jp>
Date:   Wed Aug 29 19:37:13 2018 +0900

    Raname pg_verity_checksums debug option -d to -v / verbose

diff --git a/src/bin/pg_verify_checksums/pg_verify_checksums.c b/src/bin/pg_verify_checksums/pg_verify_checksums.c
index 938b92282a..0f931b7579 100644
--- a/src/bin/pg_verify_checksums/pg_verify_checksums.c
+++ b/src/bin/pg_verify_checksums/pg_verify_checksums.c
@@ -31,7 +31,7 @@ static int64 badblocks = 0;
 static ControlFileData *ControlFile;
 
 static char *only_relfilenode = NULL;
-static bool debug = false;
+static bool verbose = false;
 
 static const char *progname;
 
@@ -43,7 +43,7 @@ usage()
 	printf(_("  %s [OPTION]... [DATADIR]\n"), progname);
 	printf(_("\nOptions:\n"));
 	printf(_(" [-D, --pgdata=]DATADIR  data directory\n"));
-	printf(_("  -d                     debug output, list all checked blocks\n"));
+	printf(_("  -v, --verbose          output verbose messages, list all checked blocks\n"));
 	printf(_("  -r RELFILENODE         check only relation with specified relfilenode\n"));
 	printf(_("  -V, --version          output version information, then exit\n"));
 	printf(_("  -?, --help             show this help, then exit\n"));
@@ -120,7 +120,7 @@ scan_file(char *fn, int segmentno)
 						progname, fn, blockno, csum, header->pd_checksum);
 			badblocks++;
 		}
-		else if (debug)
+		else if (verbose)
 			fprintf(stderr, _("%s: checksum verified in file \"%s\", block %d: %X\n"),
 					progname, fn, blockno, csum);
 	}
@@ -208,6 +208,7 @@ main(int argc, char *argv[])
 {
 	static struct option long_options[] = {
 		{"pgdata", required_argument, NULL, 'D'},
+		{"verbose", no_argument, NULL, 'v'},
 		{NULL, 0, NULL, 0}
 	};
 
@@ -234,12 +235,12 @@ main(int argc, char *argv[])
 		}
 	}
 
-	while ((c = getopt_long(argc, argv, "D:r:d", long_options, &option_index)) != -1)
+	while ((c = getopt_long(argc, argv, "D:r:v", long_options, &option_index)) != -1)
 	{
 		switch (c)
 		{
-			case 'd':
-				debug = true;
+			case 'v':
+				verbose = true;
 				break;
 			case 'D':
 				DataDir = optarg;
#7Michael Banck
michael.banck@credativ.de
In reply to: Yugo Nagata (#6)
Re: pg_verify_checksums -d option (was: Re: pg_verify_checksums -r option)

Hi,

On Wed, Aug 29, 2018 at 08:33:43PM +0900, Yugo Nagata wrote:

On Wed, 29 Aug 2018 10:28:33 +0200
Daniel Gustafsson <daniel@yesql.se> wrote:

On 27 Aug 2018, at 14:05, Yugo Nagata <nagata@sraoss.co.jp> wrote:
On Mon, 27 Aug 2018 13:34:12 +0200
Michael Banck <michael.banck@credativ.de> wrote:

On Mon, Aug 27, 2018 at 07:53:36PM +0900, Yugo Nagata wrote:

On Fri, 24 Aug 2018 18:01:09 +0200
Peter Eisentraut <peter.eisentraut@2ndquadrant.com> wrote:

I'm curious about this option:

-r RELFILENODE check only relation with specified relfilenode

but there is no facility to specify a database.

Also, referring to the relfilenode of a mapped relation seems a bit
inaccurate.

Maybe reframing this in terms of the file name of the file you want
checked would be better?

If we specified 1234 to -r option, pg_verify_shceksums checks not only 1234
but also 1234_vm, 1234_fsm, and 1234.1, 1234.2, ... and so on, so I think
it makes senses to allow to specify a relfilenode instead of a file name.

I think it is reasonable to add a option to specify a database, although
I don't know which character is good because both -d and -D are already used....

Maybe the -d (debug) option should be revisited as well. Mentioning
every scanned block generates a huge amount of output which might be
useful during development but does not seem very useful for a stable
release. AFAICT there is no other debug output for now.

So it could be renamed to -v (verbose) and only mention each scanned
file, e.g. (errors/checksum mismatches are still reported of course).

I still think this should be changed as well, i.e. -v should not report
every block scanned, as that really is debug output and IMO not useful
in general? AFAICT your page does not change the output at all, just
renames the option.

Michael

--
Michael Banck
Projektleiter / Senior Berater
Tel.: +49 2166 9901-171
Fax: +49 2166 9901-100
Email: michael.banck@credativ.de

credativ GmbH, HRB M�nchengladbach 12080
USt-ID-Nummer: DE204566209
Trompeterallee 108, 41189 M�nchengladbach
Gesch�ftsf�hrung: Dr. Michael Meskes, J�rg Folz, Sascha Heuer

Unser Umgang mit personenbezogenen Daten unterliegt
folgenden Bestimmungen: https://www.credativ.de/datenschutz

#8Magnus Hagander
magnus@hagander.net
In reply to: Michael Banck (#7)
Re: pg_verify_checksums -d option (was: Re: pg_verify_checksums -r option)

On Wed, Aug 29, 2018 at 1:37 PM, Michael Banck <michael.banck@credativ.de>
wrote:

Hi,

On Wed, Aug 29, 2018 at 08:33:43PM +0900, Yugo Nagata wrote:

On Wed, 29 Aug 2018 10:28:33 +0200
Daniel Gustafsson <daniel@yesql.se> wrote:

On 27 Aug 2018, at 14:05, Yugo Nagata <nagata@sraoss.co.jp> wrote:
On Mon, 27 Aug 2018 13:34:12 +0200
Michael Banck <michael.banck@credativ.de> wrote:

On Mon, Aug 27, 2018 at 07:53:36PM +0900, Yugo Nagata wrote:

On Fri, 24 Aug 2018 18:01:09 +0200
Peter Eisentraut <peter.eisentraut@2ndquadrant.com> wrote:

I'm curious about this option:

-r RELFILENODE check only relation with specified

relfilenode

but there is no facility to specify a database.

Also, referring to the relfilenode of a mapped relation seems a

bit

inaccurate.

Maybe reframing this in terms of the file name of the file you

want

checked would be better?

If we specified 1234 to -r option, pg_verify_shceksums checks not

only 1234

but also 1234_vm, 1234_fsm, and 1234.1, 1234.2, ... and so on, so

I think

it makes senses to allow to specify a relfilenode instead of a

file name.

I think it is reasonable to add a option to specify a database,

although

I don't know which character is good because both -d and -D are

already used....

Maybe the -d (debug) option should be revisited as well. Mentioning
every scanned block generates a huge amount of output which might be
useful during development but does not seem very useful for a stable
release. AFAICT there is no other debug output for now.

So it could be renamed to -v (verbose) and only mention each scanned
file, e.g. (errors/checksum mismatches are still reported of

course).

I still think this should be changed as well, i.e. -v should not report
every block scanned, as that really is debug output and IMO not useful
in general? AFAICT your page does not change the output at all, just
renames the option.

I agree with this (though it's my fault initially :P). Per-page output is
going to be useless in pretty much all production cases. It makes sense to
also change it to be per-file.

--
Magnus Hagander
Me: https://www.hagander.net/ <http://www.hagander.net/&gt;
Work: https://www.redpill-linpro.com/ <http://www.redpill-linpro.com/&gt;

#9Yugo Nagata
nagata@sraoss.co.jp
In reply to: Magnus Hagander (#8)
1 attachment(s)
Re: pg_verify_checksums -d option (was: Re: pg_verify_checksums -r option)

On Wed, 29 Aug 2018 13:46:38 +0200
Magnus Hagander <magnus@hagander.net> wrote:

On Wed, Aug 29, 2018 at 1:37 PM, Michael Banck <michael.banck@credativ.de>
wrote:

Hi,

On Wed, Aug 29, 2018 at 08:33:43PM +0900, Yugo Nagata wrote:

On Wed, 29 Aug 2018 10:28:33 +0200
Daniel Gustafsson <daniel@yesql.se> wrote:

On 27 Aug 2018, at 14:05, Yugo Nagata <nagata@sraoss.co.jp> wrote:
On Mon, 27 Aug 2018 13:34:12 +0200
Michael Banck <michael.banck@credativ.de> wrote:

On Mon, Aug 27, 2018 at 07:53:36PM +0900, Yugo Nagata wrote:

On Fri, 24 Aug 2018 18:01:09 +0200
Peter Eisentraut <peter.eisentraut@2ndquadrant.com> wrote:

I'm curious about this option:

-r RELFILENODE check only relation with specified

relfilenode

but there is no facility to specify a database.

Also, referring to the relfilenode of a mapped relation seems a

bit

inaccurate.

Maybe reframing this in terms of the file name of the file you

want

checked would be better?

If we specified 1234 to -r option, pg_verify_shceksums checks not

only 1234

but also 1234_vm, 1234_fsm, and 1234.1, 1234.2, ... and so on, so

I think

it makes senses to allow to specify a relfilenode instead of a

file name.

I think it is reasonable to add a option to specify a database,

although

I don't know which character is good because both -d and -D are

already used....

Maybe the -d (debug) option should be revisited as well. Mentioning
every scanned block generates a huge amount of output which might be
useful during development but does not seem very useful for a stable
release. AFAICT there is no other debug output for now.

So it could be renamed to -v (verbose) and only mention each scanned
file, e.g. (errors/checksum mismatches are still reported of

course).

I still think this should be changed as well, i.e. -v should not report
every block scanned, as that really is debug output and IMO not useful
in general? AFAICT your page does not change the output at all, just
renames the option.

I agree with this (though it's my fault initially :P). Per-page output is
going to be useless in pretty much all production cases. It makes sense to
also change it to be per-file.

I updated the patch to output only per-file information in the verbose mode.
Does this behavior match you expect?

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

Attachments:

01_pg_veriify_checksum_debug_to_verbose-v2.patchtext/x-diff; name=01_pg_veriify_checksum_debug_to_verbose-v2.patchDownload
commit ec21c608cd78f65747916487b56a197c685649c8
Author: Yugo Nagata <nagata@sraoss.co.jp>
Date:   Wed Aug 29 19:37:13 2018 +0900

    Raname pg_verity_checksums debug option -d to -v / verbose
    
    Also, change to only mention each scanced file not every block.

diff --git a/src/bin/pg_verify_checksums/pg_verify_checksums.c b/src/bin/pg_verify_checksums/pg_verify_checksums.c
index 938b92282a..0f931b7579 100644
--- a/src/bin/pg_verify_checksums/pg_verify_checksums.c
+++ b/src/bin/pg_verify_checksums/pg_verify_checksums.c
@@ -31,7 +31,7 @@ static int64 badblocks = 0;
 static ControlFileData *ControlFile;
 
 static char *only_relfilenode = NULL;
-static bool debug = false;
+static bool verbose = false;
 
 static const char *progname;
 
@@ -43,7 +43,7 @@ usage()
 	printf(_("  %s [OPTION]... [DATADIR]\n"), progname);
 	printf(_("\nOptions:\n"));
 	printf(_(" [-D, --pgdata=]DATADIR  data directory\n"));
-	printf(_("  -d                     debug output, list all checked blocks\n"));
+	printf(_("  -v, --verbose          output verbose messages, list all checked blocks\n"));
 	printf(_("  -r RELFILENODE         check only relation with specified relfilenode\n"));
 	printf(_("  -V, --version          output version information, then exit\n"));
 	printf(_("  -?, --help             show this help, then exit\n"));
@@ -120,7 +120,7 @@ scan_file(char *fn, int segmentno)
 						progname, fn, blockno, csum, header->pd_checksum);
 			badblocks++;
 		}
-		else if (debug)
+		else if (verbose)
 			fprintf(stderr, _("%s: checksum verified in file \"%s\", block %d: %X\n"),
 					progname, fn, blockno, csum);
 	}
@@ -208,6 +208,7 @@ main(int argc, char *argv[])
 {
 	static struct option long_options[] = {
 		{"pgdata", required_argument, NULL, 'D'},
+		{"verbose", no_argument, NULL, 'v'},
 		{NULL, 0, NULL, 0}
 	};
 
@@ -234,12 +235,12 @@ main(int argc, char *argv[])
 		}
 	}
 
-	while ((c = getopt_long(argc, argv, "D:r:d", long_options, &option_index)) != -1)
+	while ((c = getopt_long(argc, argv, "D:r:v", long_options, &option_index)) != -1)
 	{
 		switch (c)
 		{
-			case 'd':
-				debug = true;
+			case 'v':
+				verbose = true;
 				break;
 			case 'D':
 				DataDir = optarg;
#10Yugo Nagata
nagata@sraoss.co.jp
In reply to: Yugo Nagata (#9)
1 attachment(s)
Re: pg_verify_checksums -d option (was: Re: pg_verify_checksums -r option)

On Wed, 29 Aug 2018 21:09:03 +0900
Yugo Nagata <nagata@sraoss.co.jp> wrote:

On Wed, 29 Aug 2018 13:46:38 +0200
Magnus Hagander <magnus@hagander.net> wrote:

On Wed, Aug 29, 2018 at 1:37 PM, Michael Banck <michael.banck@credativ.de>
wrote:

Hi,

On Wed, Aug 29, 2018 at 08:33:43PM +0900, Yugo Nagata wrote:

On Wed, 29 Aug 2018 10:28:33 +0200
Daniel Gustafsson <daniel@yesql.se> wrote:

On 27 Aug 2018, at 14:05, Yugo Nagata <nagata@sraoss.co.jp> wrote:
On Mon, 27 Aug 2018 13:34:12 +0200
Michael Banck <michael.banck@credativ.de> wrote:

On Mon, Aug 27, 2018 at 07:53:36PM +0900, Yugo Nagata wrote:

On Fri, 24 Aug 2018 18:01:09 +0200
Peter Eisentraut <peter.eisentraut@2ndquadrant.com> wrote:

I'm curious about this option:

-r RELFILENODE check only relation with specified

relfilenode

but there is no facility to specify a database.

Also, referring to the relfilenode of a mapped relation seems a

bit

inaccurate.

Maybe reframing this in terms of the file name of the file you

want

checked would be better?

If we specified 1234 to -r option, pg_verify_shceksums checks not

only 1234

but also 1234_vm, 1234_fsm, and 1234.1, 1234.2, ... and so on, so

I think

it makes senses to allow to specify a relfilenode instead of a

file name.

I think it is reasonable to add a option to specify a database,

although

I don't know which character is good because both -d and -D are

already used....

Maybe the -d (debug) option should be revisited as well. Mentioning
every scanned block generates a huge amount of output which might be
useful during development but does not seem very useful for a stable
release. AFAICT there is no other debug output for now.

So it could be renamed to -v (verbose) and only mention each scanned
file, e.g. (errors/checksum mismatches are still reported of

course).

I still think this should be changed as well, i.e. -v should not report
every block scanned, as that really is debug output and IMO not useful
in general? AFAICT your page does not change the output at all, just
renames the option.

I agree with this (though it's my fault initially :P). Per-page output is
going to be useless in pretty much all production cases. It makes sense to
also change it to be per-file.

I updated the patch to output only per-file information in the verbose mode.
Does this behavior match you expect?

I am sorry but I attached a wrong file in the previous post.
Attached is the correct version of the updated patch.

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

Attachments:

01_pg_veriify_checksum_debug_to_verbose-v2.patchtext/x-diff; name=01_pg_veriify_checksum_debug_to_verbose-v2.patchDownload
commit 7c673e1d712c74c51c708ddc4a151b6fb8cc2a8f
Author: Yugo Nagata <nagata@sraoss.co.jp>
Date:   Wed Aug 29 19:37:13 2018 +0900

    Raname pg_verity_checksums debug option -d to -v / verbose
    
    Also, change to only mention each scanced file not every block.

diff --git a/doc/src/sgml/ref/pg_verify_checksums.sgml b/doc/src/sgml/ref/pg_verify_checksums.sgml
index ecc5501eae..a1ff060c2b 100644
--- a/doc/src/sgml/ref/pg_verify_checksums.sgml
+++ b/doc/src/sgml/ref/pg_verify_checksums.sgml
@@ -64,8 +64,8 @@ PostgreSQL documentation
       <term><option>-d</option></term>
       <listitem>
        <para>
-        Enable debug output. Lists all checked blocks and their checksum.
-       </para>
+        Enable debug output. Lists all checked files.
+       <para>
       </listitem>
      </varlistentry>
 
diff --git a/src/bin/pg_verify_checksums/pg_verify_checksums.c b/src/bin/pg_verify_checksums/pg_verify_checksums.c
index 938b92282a..6be138eb75 100644
--- a/src/bin/pg_verify_checksums/pg_verify_checksums.c
+++ b/src/bin/pg_verify_checksums/pg_verify_checksums.c
@@ -31,7 +31,7 @@ static int64 badblocks = 0;
 static ControlFileData *ControlFile;
 
 static char *only_relfilenode = NULL;
-static bool debug = false;
+static bool verbose = false;
 
 static const char *progname;
 
@@ -43,7 +43,7 @@ usage()
 	printf(_("  %s [OPTION]... [DATADIR]\n"), progname);
 	printf(_("\nOptions:\n"));
 	printf(_(" [-D, --pgdata=]DATADIR  data directory\n"));
-	printf(_("  -d                     debug output, list all checked blocks\n"));
+	printf(_("  -v, --verbose          output verbose messages, list all checked files\n"));
 	printf(_("  -r RELFILENODE         check only relation with specified relfilenode\n"));
 	printf(_("  -V, --version          output version information, then exit\n"));
 	printf(_("  -?, --help             show this help, then exit\n"));
@@ -120,11 +120,11 @@ scan_file(char *fn, int segmentno)
 						progname, fn, blockno, csum, header->pd_checksum);
 			badblocks++;
 		}
-		else if (debug)
-			fprintf(stderr, _("%s: checksum verified in file \"%s\", block %d: %X\n"),
-					progname, fn, blockno, csum);
 	}
 
+	if (verbose)
+		fprintf(stderr, _("%s: checksum verified in file \"%s\"\n"), progname, fn);
+
 	close(f);
 }
 
@@ -208,6 +208,7 @@ main(int argc, char *argv[])
 {
 	static struct option long_options[] = {
 		{"pgdata", required_argument, NULL, 'D'},
+		{"verbose", no_argument, NULL, 'v'},
 		{NULL, 0, NULL, 0}
 	};
 
@@ -234,12 +235,12 @@ main(int argc, char *argv[])
 		}
 	}
 
-	while ((c = getopt_long(argc, argv, "D:r:d", long_options, &option_index)) != -1)
+	while ((c = getopt_long(argc, argv, "D:r:v", long_options, &option_index)) != -1)
 	{
 		switch (c)
 		{
-			case 'd':
-				debug = true;
+			case 'v':
+				verbose = true;
 				break;
 			case 'D':
 				DataDir = optarg;
#11Michael Banck
michael.banck@credativ.de
In reply to: Yugo Nagata (#10)
Re: pg_verify_checksums -d option (was: Re: pg_verify_checksums -r option)

Hi,

thanks for fixing this up!

On Wed, Aug 29, 2018 at 11:25:28PM +0900, Yugo Nagata wrote:

diff --git a/doc/src/sgml/ref/pg_verify_checksums.sgml b/doc/src/sgml/ref/pg_verify_checksums.sgml
index ecc5501eae..a1ff060c2b 100644
--- a/doc/src/sgml/ref/pg_verify_checksums.sgml
+++ b/doc/src/sgml/ref/pg_verify_checksums.sgml
@@ -64,8 +64,8 @@ PostgreSQL documentation
<term><option>-d</option></term>

This -d needs to be renamed to -v as well I guess.

<listitem>
<para>
-        Enable debug output. Lists all checked blocks and their checksum.
-       </para>
+        Enable debug output. Lists all checked files.

I'd say 'Enable verbose output.' would be more appropriate now.

Looks good to me otherwise.

Michael

--
Michael Banck
Projektleiter / Senior Berater
Tel.: +49 2166 9901-171
Fax: +49 2166 9901-100
Email: michael.banck@credativ.de

credativ GmbH, HRB M�nchengladbach 12080
USt-ID-Nummer: DE204566209
Trompeterallee 108, 41189 M�nchengladbach
Gesch�ftsf�hrung: Dr. Michael Meskes, J�rg Folz, Sascha Heuer

Unser Umgang mit personenbezogenen Daten unterliegt
folgenden Bestimmungen: https://www.credativ.de/datenschutz

#12Michael Banck
michael.banck@credativ.de
In reply to: Michael Banck (#3)
Re: pg_verify_checksums -d option (was: Re: pg_verify_checksums -r option)

Hi,

On Thu, Aug 30, 2018 at 05:35:09PM +0900, Yugo Nagata wrote:

--- a/doc/src/sgml/ref/pg_verify_checksums.sgml
+++ b/doc/src/sgml/ref/pg_verify_checksums.sgml
@@ -61,11 +61,11 @@ PostgreSQL documentation
</varlistentry>
<varlistentry>
-      <term><option>-d</option></term>
+      <term><option>-v</option></term>

Sorry that I did not catch this the first time, but as you have added
the --verbose long option, I think that should be documented here as
well, similar to -D/--pgdata.

Michael

--
Michael Banck
Projektleiter / Senior Berater
Tel.: +49 2166 9901-171
Fax: +49 2166 9901-100
Email: michael.banck@credativ.de

credativ GmbH, HRB M�nchengladbach 12080
USt-ID-Nummer: DE204566209
Trompeterallee 108, 41189 M�nchengladbach
Gesch�ftsf�hrung: Dr. Michael Meskes, J�rg Folz, Sascha Heuer

Unser Umgang mit personenbezogenen Daten unterliegt
folgenden Bestimmungen: https://www.credativ.de/datenschutz

#13Yugo Nagata
nagata@sraoss.co.jp
In reply to: Michael Banck (#11)
1 attachment(s)
Re: pg_verify_checksums -d option (was: Re: pg_verify_checksums -r option)

On Thu, 30 Aug 2018 10:13:31 +0200
Michael Banck <michael.banck@credativ.de> wrote:

Hi,

thanks for fixing this up!

On Wed, Aug 29, 2018 at 11:25:28PM +0900, Yugo Nagata wrote:

diff --git a/doc/src/sgml/ref/pg_verify_checksums.sgml b/doc/src/sgml/ref/pg_verify_checksums.sgml
index ecc5501eae..a1ff060c2b 100644
--- a/doc/src/sgml/ref/pg_verify_checksums.sgml
+++ b/doc/src/sgml/ref/pg_verify_checksums.sgml
@@ -64,8 +64,8 @@ PostgreSQL documentation
<term><option>-d</option></term>

This -d needs to be renamed to -v as well I guess.

<listitem>
<para>
-        Enable debug output. Lists all checked blocks and their checksum.
-       </para>
+        Enable debug output. Lists all checked files.

I'd say 'Enable verbose output.' would be more appropriate now.

Looks good to me otherwise.

Thank you for your review. I forgot the doc fix.
Attached is the updated patch.

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

Attachments:

01_pg_veriify_checksum_debug_to_verbose-v3.patchtext/x-diff; name=01_pg_veriify_checksum_debug_to_verbose-v3.patchDownload
From 7d577241ca1dc0df65de2a3614807270db8742b3 Mon Sep 17 00:00:00 2001
From: Yugo Nagata <nagata@sraoss.co.jp>
Date: Wed, 29 Aug 2018 19:37:13 +0900
Subject: [PATCH] Raname pg_verity_checksums debug option -d to -v / verbose

Also, change to only mention each scanced file not every block.
---
 doc/src/sgml/ref/pg_verify_checksums.sgml       |  6 +++---
 .../pg_verify_checksums/pg_verify_checksums.c   | 17 +++++++++--------
 2 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/doc/src/sgml/ref/pg_verify_checksums.sgml b/doc/src/sgml/ref/pg_verify_checksums.sgml
index ecc5501eae..af58b64b54 100644
--- a/doc/src/sgml/ref/pg_verify_checksums.sgml
+++ b/doc/src/sgml/ref/pg_verify_checksums.sgml
@@ -61,11 +61,11 @@ PostgreSQL documentation
      </varlistentry>
 
      <varlistentry>
-      <term><option>-d</option></term>
+      <term><option>-v</option></term>
       <listitem>
        <para>
-        Enable debug output. Lists all checked blocks and their checksum.
-       </para>
+        Enable verbose output. Lists all checked files.
+       <para>
       </listitem>
      </varlistentry>
 
diff --git a/src/bin/pg_verify_checksums/pg_verify_checksums.c b/src/bin/pg_verify_checksums/pg_verify_checksums.c
index 938b92282a..6be138eb75 100644
--- a/src/bin/pg_verify_checksums/pg_verify_checksums.c
+++ b/src/bin/pg_verify_checksums/pg_verify_checksums.c
@@ -31,7 +31,7 @@ static int64 badblocks = 0;
 static ControlFileData *ControlFile;
 
 static char *only_relfilenode = NULL;
-static bool debug = false;
+static bool verbose = false;
 
 static const char *progname;
 
@@ -43,7 +43,7 @@ usage()
 	printf(_("  %s [OPTION]... [DATADIR]\n"), progname);
 	printf(_("\nOptions:\n"));
 	printf(_(" [-D, --pgdata=]DATADIR  data directory\n"));
-	printf(_("  -d                     debug output, list all checked blocks\n"));
+	printf(_("  -v, --verbose          output verbose messages, list all checked files\n"));
 	printf(_("  -r RELFILENODE         check only relation with specified relfilenode\n"));
 	printf(_("  -V, --version          output version information, then exit\n"));
 	printf(_("  -?, --help             show this help, then exit\n"));
@@ -120,11 +120,11 @@ scan_file(char *fn, int segmentno)
 						progname, fn, blockno, csum, header->pd_checksum);
 			badblocks++;
 		}
-		else if (debug)
-			fprintf(stderr, _("%s: checksum verified in file \"%s\", block %d: %X\n"),
-					progname, fn, blockno, csum);
 	}
 
+	if (verbose)
+		fprintf(stderr, _("%s: checksum verified in file \"%s\"\n"), progname, fn);
+
 	close(f);
 }
 
@@ -208,6 +208,7 @@ main(int argc, char *argv[])
 {
 	static struct option long_options[] = {
 		{"pgdata", required_argument, NULL, 'D'},
+		{"verbose", no_argument, NULL, 'v'},
 		{NULL, 0, NULL, 0}
 	};
 
@@ -234,12 +235,12 @@ main(int argc, char *argv[])
 		}
 	}
 
-	while ((c = getopt_long(argc, argv, "D:r:d", long_options, &option_index)) != -1)
+	while ((c = getopt_long(argc, argv, "D:r:v", long_options, &option_index)) != -1)
 	{
 		switch (c)
 		{
-			case 'd':
-				debug = true;
+			case 'v':
+				verbose = true;
 				break;
 			case 'D':
 				DataDir = optarg;
-- 
2.17.1

#14Yugo Nagata
nagata@sraoss.co.jp
In reply to: Michael Banck (#12)
1 attachment(s)
Re: pg_verify_checksums -d option (was: Re: pg_verify_checksums -r option)

On Thu, 30 Aug 2018 10:34:06 +0200
Michael Banck <michael.banck@credativ.de> wrote:

Hi,

On Thu, Aug 30, 2018 at 05:35:09PM +0900, Yugo Nagata wrote:

--- a/doc/src/sgml/ref/pg_verify_checksums.sgml
+++ b/doc/src/sgml/ref/pg_verify_checksums.sgml
@@ -61,11 +61,11 @@ PostgreSQL documentation
</varlistentry>
<varlistentry>
-      <term><option>-d</option></term>
+      <term><option>-v</option></term>

Sorry that I did not catch this the first time, but as you have added
the --verbose long option, I think that should be documented here as
well, similar to -D/--pgdata.

Oops, It's my mistake. I updated the patch.

Thanks,

Michael

--
Michael Banck
Projektleiter / Senior Berater
Tel.: +49 2166 9901-171
Fax: +49 2166 9901-100
Email: michael.banck@credativ.de

credativ GmbH, HRB Mönchengladbach 12080
USt-ID-Nummer: DE204566209
Trompeterallee 108, 41189 Mönchengladbach
Geschäftsführung: Dr. Michael Meskes, Jörg Folz, Sascha Heuer

Unser Umgang mit personenbezogenen Daten unterliegt
folgenden Bestimmungen: https://www.credativ.de/datenschutz

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

Attachments:

01_pg_veriify_checksum_debug_to_verbose-v4.patchtext/x-diff; name=01_pg_veriify_checksum_debug_to_verbose-v4.patchDownload
From 996622af6442934b0f363cdb6037b81164d0dc4f Mon Sep 17 00:00:00 2001
From: Yugo Nagata <nagata@sraoss.co.jp>
Date: Wed, 29 Aug 2018 19:37:13 +0900
Subject: [PATCH] Raname pg_verity_checksums debug option -d to -v / verbose

Also, change to only mention each scanced file not every block.
---
 doc/src/sgml/ref/pg_verify_checksums.sgml       |  7 ++++---
 .../pg_verify_checksums/pg_verify_checksums.c   | 17 +++++++++--------
 2 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/doc/src/sgml/ref/pg_verify_checksums.sgml b/doc/src/sgml/ref/pg_verify_checksums.sgml
index ecc5501eae..3a3433b1c8 100644
--- a/doc/src/sgml/ref/pg_verify_checksums.sgml
+++ b/doc/src/sgml/ref/pg_verify_checksums.sgml
@@ -61,11 +61,12 @@ PostgreSQL documentation
      </varlistentry>
 
      <varlistentry>
-      <term><option>-d</option></term>
+      <term><option>-v</option></term>
+      <term><option>--verbose</option></term>
       <listitem>
        <para>
-        Enable debug output. Lists all checked blocks and their checksum.
-       </para>
+        Enable verbose output. Lists all checked files.
+       <para>
       </listitem>
      </varlistentry>
 
diff --git a/src/bin/pg_verify_checksums/pg_verify_checksums.c b/src/bin/pg_verify_checksums/pg_verify_checksums.c
index 938b92282a..6be138eb75 100644
--- a/src/bin/pg_verify_checksums/pg_verify_checksums.c
+++ b/src/bin/pg_verify_checksums/pg_verify_checksums.c
@@ -31,7 +31,7 @@ static int64 badblocks = 0;
 static ControlFileData *ControlFile;
 
 static char *only_relfilenode = NULL;
-static bool debug = false;
+static bool verbose = false;
 
 static const char *progname;
 
@@ -43,7 +43,7 @@ usage()
 	printf(_("  %s [OPTION]... [DATADIR]\n"), progname);
 	printf(_("\nOptions:\n"));
 	printf(_(" [-D, --pgdata=]DATADIR  data directory\n"));
-	printf(_("  -d                     debug output, list all checked blocks\n"));
+	printf(_("  -v, --verbose          output verbose messages, list all checked files\n"));
 	printf(_("  -r RELFILENODE         check only relation with specified relfilenode\n"));
 	printf(_("  -V, --version          output version information, then exit\n"));
 	printf(_("  -?, --help             show this help, then exit\n"));
@@ -120,11 +120,11 @@ scan_file(char *fn, int segmentno)
 						progname, fn, blockno, csum, header->pd_checksum);
 			badblocks++;
 		}
-		else if (debug)
-			fprintf(stderr, _("%s: checksum verified in file \"%s\", block %d: %X\n"),
-					progname, fn, blockno, csum);
 	}
 
+	if (verbose)
+		fprintf(stderr, _("%s: checksum verified in file \"%s\"\n"), progname, fn);
+
 	close(f);
 }
 
@@ -208,6 +208,7 @@ main(int argc, char *argv[])
 {
 	static struct option long_options[] = {
 		{"pgdata", required_argument, NULL, 'D'},
+		{"verbose", no_argument, NULL, 'v'},
 		{NULL, 0, NULL, 0}
 	};
 
@@ -234,12 +235,12 @@ main(int argc, char *argv[])
 		}
 	}
 
-	while ((c = getopt_long(argc, argv, "D:r:d", long_options, &option_index)) != -1)
+	while ((c = getopt_long(argc, argv, "D:r:v", long_options, &option_index)) != -1)
 	{
 		switch (c)
 		{
-			case 'd':
-				debug = true;
+			case 'v':
+				verbose = true;
 				break;
 			case 'D':
 				DataDir = optarg;
-- 
2.17.1

#15Michael Banck
michael.banck@credativ.de
In reply to: Yugo Nagata (#14)
Re: pg_verify_checksums -d option (was: Re: pg_verify_checksums -r option)

Hi,

On Thu, Aug 30, 2018 at 05:48:24PM +0900, Yugo Nagata wrote:

Oops, It's my mistake. I updated the patch.

Looks good to me now.

One could argue that the message could be 'checksums verified in file
FILE' (plural) rather than 'checksum verified in file FILE', but that is
quickly approaching bikeshed territory I guess.

Michael

--
Michael Banck
Projektleiter / Senior Berater
Tel.: +49 2166 9901-171
Fax: +49 2166 9901-100
Email: michael.banck@credativ.de

credativ GmbH, HRB M�nchengladbach 12080
USt-ID-Nummer: DE204566209
Trompeterallee 108, 41189 M�nchengladbach
Gesch�ftsf�hrung: Dr. Michael Meskes, J�rg Folz, Sascha Heuer

Unser Umgang mit personenbezogenen Daten unterliegt
folgenden Bestimmungen: https://www.credativ.de/datenschutz

#16Yugo Nagata
nagata@sraoss.co.jp
In reply to: Michael Banck (#15)
1 attachment(s)
Re: pg_verify_checksums -d option (was: Re: pg_verify_checksums -r option)

On Thu, 30 Aug 2018 10:54:08 +0200
Michael Banck <michael.banck@credativ.de> wrote:

Hi,

On Thu, Aug 30, 2018 at 05:48:24PM +0900, Yugo Nagata wrote:

Oops, It's my mistake. I updated the patch.

Looks good to me now.

One could argue that the message could be 'checksums verified in file
FILE' (plural) rather than 'checksum verified in file FILE', but that is
quickly approaching bikeshed territory I guess.

It seems to me reasonable. Although I'm not native English speaker, if this
is more natural for Westerners, it is better to fix.

Attached is the revised version.

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

Attachments:

01_pg_veriify_checksum_debug_to_verbose-v5.patchtext/x-diff; name=01_pg_veriify_checksum_debug_to_verbose-v5.patchDownload
From f44fbb942b49d8f2ddd3ee5e39e6aba83ce5fe64 Mon Sep 17 00:00:00 2001
From: Yugo Nagata <nagata@sraoss.co.jp>
Date: Wed, 29 Aug 2018 19:37:13 +0900
Subject: [PATCH] Raname pg_verity_checksums debug option -d to -v / verbose

Also, change to only mention each scanced file not every block.
---
 doc/src/sgml/ref/pg_verify_checksums.sgml       |  7 ++++---
 .../pg_verify_checksums/pg_verify_checksums.c   | 17 +++++++++--------
 2 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/doc/src/sgml/ref/pg_verify_checksums.sgml b/doc/src/sgml/ref/pg_verify_checksums.sgml
index ecc5501eae..3a3433b1c8 100644
--- a/doc/src/sgml/ref/pg_verify_checksums.sgml
+++ b/doc/src/sgml/ref/pg_verify_checksums.sgml
@@ -61,11 +61,12 @@ PostgreSQL documentation
      </varlistentry>
 
      <varlistentry>
-      <term><option>-d</option></term>
+      <term><option>-v</option></term>
+      <term><option>--verbose</option></term>
       <listitem>
        <para>
-        Enable debug output. Lists all checked blocks and their checksum.
-       </para>
+        Enable verbose output. Lists all checked files.
+       <para>
       </listitem>
      </varlistentry>
 
diff --git a/src/bin/pg_verify_checksums/pg_verify_checksums.c b/src/bin/pg_verify_checksums/pg_verify_checksums.c
index 938b92282a..1eb3bed2b9 100644
--- a/src/bin/pg_verify_checksums/pg_verify_checksums.c
+++ b/src/bin/pg_verify_checksums/pg_verify_checksums.c
@@ -31,7 +31,7 @@ static int64 badblocks = 0;
 static ControlFileData *ControlFile;
 
 static char *only_relfilenode = NULL;
-static bool debug = false;
+static bool verbose = false;
 
 static const char *progname;
 
@@ -43,7 +43,7 @@ usage()
 	printf(_("  %s [OPTION]... [DATADIR]\n"), progname);
 	printf(_("\nOptions:\n"));
 	printf(_(" [-D, --pgdata=]DATADIR  data directory\n"));
-	printf(_("  -d                     debug output, list all checked blocks\n"));
+	printf(_("  -v, --verbose          output verbose messages, list all checked files\n"));
 	printf(_("  -r RELFILENODE         check only relation with specified relfilenode\n"));
 	printf(_("  -V, --version          output version information, then exit\n"));
 	printf(_("  -?, --help             show this help, then exit\n"));
@@ -120,11 +120,11 @@ scan_file(char *fn, int segmentno)
 						progname, fn, blockno, csum, header->pd_checksum);
 			badblocks++;
 		}
-		else if (debug)
-			fprintf(stderr, _("%s: checksum verified in file \"%s\", block %d: %X\n"),
-					progname, fn, blockno, csum);
 	}
 
+	if (verbose)
+		fprintf(stderr, _("%s: checksums verified in file \"%s\"\n"), progname, fn);
+
 	close(f);
 }
 
@@ -208,6 +208,7 @@ main(int argc, char *argv[])
 {
 	static struct option long_options[] = {
 		{"pgdata", required_argument, NULL, 'D'},
+		{"verbose", no_argument, NULL, 'v'},
 		{NULL, 0, NULL, 0}
 	};
 
@@ -234,12 +235,12 @@ main(int argc, char *argv[])
 		}
 	}
 
-	while ((c = getopt_long(argc, argv, "D:r:d", long_options, &option_index)) != -1)
+	while ((c = getopt_long(argc, argv, "D:r:v", long_options, &option_index)) != -1)
 	{
 		switch (c)
 		{
-			case 'd':
-				debug = true;
+			case 'v':
+				verbose = true;
 				break;
 			case 'D':
 				DataDir = optarg;
-- 
2.17.1

#17Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Yugo Nagata (#16)
Re: pg_verify_checksums -d option (was: Re: pg_verify_checksums -r option)

Thanks! Pushed. There was a markup error in the documentation.

This should have been listed in the pg11 open items. Please list there
everything that should apply be applied branch 11 before release, so
that they get fixed (or at least considered) before we release.

https://wiki.postgresql.org/wiki/Open_Items

--
�lvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

#18Yugo Nagata
nagata@sraoss.co.jp
In reply to: Alvaro Herrera (#17)
Re: pg_verify_checksums -d option (was: Re: pg_verify_checksums -r option)

On Thu, 30 Aug 2018 06:52:58 -0300
Alvaro Herrera <alvherre@2ndquadrant.com> wrote:

Thanks! Pushed. There was a markup error in the documentation.

Thank you!

This should have been listed in the pg11 open items. Please list there
everything that should apply be applied branch 11 before release, so
that they get fixed (or at least considered) before we release.

https://wiki.postgresql.org/wiki/Open_Items

I don't have the editor privilege now, so I'll add this discussion to the
wiki (Fixed issues or Resolve issues?) after I get the privilege.

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

#19Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Yugo Nagata (#18)
Re: pg_verify_checksums -d option (was: Re: pg_verify_checksums -r option)

On 2018-Aug-30, Yugo Nagata wrote:

On Thu, 30 Aug 2018 06:52:58 -0300
Alvaro Herrera <alvherre@2ndquadrant.com> wrote:

This should have been listed in the pg11 open items. Please list there
everything that should apply be applied branch 11 before release, so
that they get fixed (or at least considered) before we release.

https://wiki.postgresql.org/wiki/Open_Items

I don't have the editor privilege now, so I'll add this discussion to the
wiki (Fixed issues or Resolve issues?) after I get the privilege.

You're an editor now, though IMO adding it as a resolved issue is
pointless. I meant if there are any items pending resolution, then
please add them.

--
�lvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

#20Yugo Nagata
nagata@sraoss.co.jp
In reply to: Alvaro Herrera (#19)
Re: pg_verify_checksums -d option (was: Re: pg_verify_checksums -r option)

On Thu, 30 Aug 2018 07:18:13 -0300
Alvaro Herrera <alvherre@2ndquadrant.com> wrote:

On 2018-Aug-30, Yugo Nagata wrote:

On Thu, 30 Aug 2018 06:52:58 -0300
Alvaro Herrera <alvherre@2ndquadrant.com> wrote:

This should have been listed in the pg11 open items. Please list there
everything that should apply be applied branch 11 before release, so
that they get fixed (or at least considered) before we release.

https://wiki.postgresql.org/wiki/Open_Items

I don't have the editor privilege now, so I'll add this discussion to the
wiki (Fixed issues or Resolve issues?) after I get the privilege.

You're an editor now, though IMO adding it as a resolved issue is
pointless. I meant if there are any items pending resolution, then
please add them.

Sure. I will do that from next time.

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

#21Yugo Nagata
nagata@sraoss.co.jp
In reply to: Yugo Nagata (#4)
1 attachment(s)
Re: pg_verify_checksums -d option (was: Re: pg_verify_checksums -r option)

On Mon, 27 Aug 2018 21:05:33 +0900
Yugo Nagata <nagata@sraoss.co.jp> wrote:

On Mon, 27 Aug 2018 13:34:12 +0200
Michael Banck <michael.banck@credativ.de> wrote:

Hi,

On Mon, Aug 27, 2018 at 07:53:36PM +0900, Yugo Nagata wrote:

On Fri, 24 Aug 2018 18:01:09 +0200
Peter Eisentraut <peter.eisentraut@2ndquadrant.com> wrote:

I'm curious about this option:

-r RELFILENODE check only relation with specified relfilenode

but there is no facility to specify a database.

Also, referring to the relfilenode of a mapped relation seems a bit
inaccurate.

Maybe reframing this in terms of the file name of the file you want
checked would be better?

If we specified 1234 to -r option, pg_verify_shceksums checks not only 1234
but also 1234_vm, 1234_fsm, and 1234.1, 1234.2, ... and so on, so I think
it makes senses to allow to specify a relfilenode instead of a file name.

I think it is reasonable to add a option to specify a database, although
I don't know which character is good because both -d and -D are already used....

Maybe the -d (debug) option should be revisited as well. Mentioning
every scanned block generates a huge amount of output which might be
useful during development but does not seem very useful for a stable
release. AFAICT there is no other debug output for now.

So it could be renamed to -v (verbose) and only mention each scanned
file, e.g. (errors/checksum mismatches are still reported of course).

Then -d could (in the future, I guess that is too late for v11) be used
for -d/--dbname (or make that only a long option, if the above does not
work).

I realized after sending the previous post that we can not specify a database
by name because pg_verify_checksum is run in offline and this can not get the
OID from the database name. Also, there are global and pg_tblspc directories
not only base/<database OID>. So, it seems to me good to specify a directories
to scan which is under PGDATA. We would be able to use -d ( or --directory ?)
for this purpose.

Attached is a patch to allow pg_verity_checksums to specify a database
to scan. This is usefule for users who want to verify checksums of relations
in a specific database. We can specify a database by OID using -d or --dboid option.
Also, when -g or --global-only is used only shared relations are scaned.

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

Attachments:

0001-Allow-pg_verify_checksums-to-specify-a-database.patchtext/x-diff; name=0001-Allow-pg_verify_checksums-to-specify-a-database.patchDownload
From 99135eec747b0f115b8fbdbf092c85808a70da85 Mon Sep 17 00:00:00 2001
From: Yugo Nagata <nagata@sraoss.co.jp>
Date: Thu, 30 Aug 2018 18:48:00 +0900
Subject: [PATCH] Allow pg_verify_checksums to specify a database to scan

---
 doc/src/sgml/ref/pg_verify_checksums.sgml     | 20 +++++++++++
 .../pg_verify_checksums/pg_verify_checksums.c | 35 ++++++++++++++++---
 2 files changed, 51 insertions(+), 4 deletions(-)

diff --git a/doc/src/sgml/ref/pg_verify_checksums.sgml b/doc/src/sgml/ref/pg_verify_checksums.sgml
index 3a3433b1c8..782cf35ca0 100644
--- a/doc/src/sgml/ref/pg_verify_checksums.sgml
+++ b/doc/src/sgml/ref/pg_verify_checksums.sgml
@@ -70,6 +70,26 @@ PostgreSQL documentation
       </listitem>
      </varlistentry>
 
+     <varlistentry>
+      <term><option>-d <replaceable>oid</replaceable></option></term>
+      <term><option>--dboid=<replaceable>oid</replaceable></option></term>
+      <listitem>
+       <para>
+        Only validate checksums in the relations in the database with specified OID.
+       </para>
+      </listitem>
+     </varlistentry>
+
+     <varlistentry>
+      <term><option>-g</option></term>
+      <term><option>--globel-only</option></term>
+      <listitem>
+       <para>
+        Only validate checksums in the relations in the shared database.
+       </para>
+      </listitem>
+     </varlistentry>
+
      <varlistentry>
       <term><option>-r <replaceable>relfilenode</replaceable></option></term>
       <listitem>
diff --git a/src/bin/pg_verify_checksums/pg_verify_checksums.c b/src/bin/pg_verify_checksums/pg_verify_checksums.c
index 1eb3bed2b9..0b9c03ac30 100644
--- a/src/bin/pg_verify_checksums/pg_verify_checksums.c
+++ b/src/bin/pg_verify_checksums/pg_verify_checksums.c
@@ -31,6 +31,8 @@ static int64 badblocks = 0;
 static ControlFileData *ControlFile;
 
 static char *only_relfilenode = NULL;
+static char *only_dboid = NULL;
+static bool only_global = false;
 static bool verbose = false;
 
 static const char *progname;
@@ -44,6 +46,8 @@ usage()
 	printf(_("\nOptions:\n"));
 	printf(_(" [-D, --pgdata=]DATADIR  data directory\n"));
 	printf(_("  -v, --verbose          output verbose messages, list all checked files\n"));
+	printf(_("  -d, --dboid=OID        check only relations in database with specified OID\n"));
+	printf(_("  -g, --global-only      check only shared relations\n"));
 	printf(_("  -r RELFILENODE         check only relation with specified relfilenode\n"));
 	printf(_("  -V, --version          output version information, then exit\n"));
 	printf(_("  -?, --help             show this help, then exit\n"));
@@ -198,7 +202,13 @@ scan_directory(char *basedir, char *subdir)
 #else
 		else if (S_ISDIR(st.st_mode) || pgwin32_is_junction(fn))
 #endif
+		{
+			if (atoi(de->d_name) != 0 && strcmp(subdir, "pg_tblspc") &&
+				only_dboid && strcmp(only_dboid, de->d_name) != 0)
+				continue;
+
 			scan_directory(path, de->d_name);
+		}
 	}
 	closedir(dir);
 }
@@ -208,6 +218,8 @@ main(int argc, char *argv[])
 {
 	static struct option long_options[] = {
 		{"pgdata", required_argument, NULL, 'D'},
+		{"dboid", required_argument, NULL, 'd'},
+		{"global-only", no_argument, NULL, 'g'},
 		{"verbose", no_argument, NULL, 'v'},
 		{NULL, 0, NULL, 0}
 	};
@@ -235,7 +247,7 @@ main(int argc, char *argv[])
 		}
 	}
 
-	while ((c = getopt_long(argc, argv, "D:r:v", long_options, &option_index)) != -1)
+	while ((c = getopt_long(argc, argv, "D:r:d:gv", long_options, &option_index)) != -1)
 	{
 		switch (c)
 		{
@@ -253,6 +265,17 @@ main(int argc, char *argv[])
 				}
 				only_relfilenode = pstrdup(optarg);
 				break;
+			case 'd':
+				if (atoi(optarg) <= 0)
+				{
+					fprintf(stderr, _("%s: invalid database oid specification, must be numeric: %s\n"), progname, optarg);
+					exit(1);
+				}
+				only_dboid = pstrdup(optarg);
+				break;
+			case 'g':
+				only_global = true;
+				break;
 			default:
 				fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
 				exit(1);
@@ -307,9 +330,13 @@ main(int argc, char *argv[])
 	}
 
 	/* Scan all files */
-	scan_directory(DataDir, "global");
-	scan_directory(DataDir, "base");
-	scan_directory(DataDir, "pg_tblspc");
+	if (!only_dboid)
+		scan_directory(DataDir, "global");
+	if (!only_global)
+	{
+		scan_directory(DataDir, "base");
+		scan_directory(DataDir, "pg_tblspc");
+	}
 
 	printf(_("Checksum scan completed\n"));
 	printf(_("Data checksum version: %d\n"), ControlFile->data_checksum_version);
-- 
2.17.1

#22Fabien COELHO
coelho@cri.ensmp.fr
In reply to: Yugo Nagata (#21)
Re: pg_verify_checksums -d option (was: Re: pg_verify_checksums -r option)

Hello Yugo-san,

Attached is a patch to allow pg_verity_checksums to specify a database
to scan. This is usefule for users who want to verify checksums of relations
in a specific database. We can specify a database by OID using -d or --dboid option.
Also, when -g or --global-only is used only shared relations are scaned.

It seems that the patch does not apply anymore. Could you rebase it?

--
Fabien.

#23Yugo Nagata
nagata@sraoss.co.jp
In reply to: Fabien COELHO (#22)
1 attachment(s)
Re: pg_verify_checksums -d option (was: Re: pg_verify_checksums -r option)

Hi,

On Sat, 1 Sep 2018 07:40:40 +0200 (CEST)
Fabien COELHO <coelho@cri.ensmp.fr> wrote:

Attached is a patch to allow pg_verity_checksums to specify a database
to scan. This is usefule for users who want to verify checksums of relations
in a specific database. We can specify a database by OID using -d or --dboid option.
Also, when -g or --global-only is used only shared relations are scaned.

It seems that the patch does not apply anymore. Could you rebase it?

I attached the rebased patch.

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

Attachments:

0001-Allow-pg_verify_checksums-to-specify-a-database-v2.patchtext/x-diff; name=0001-Allow-pg_verify_checksums-to-specify-a-database-v2.patchDownload
From f2141a28d1c1205aa9a79e159c23200b3ce29aa0 Mon Sep 17 00:00:00 2001
From: Yugo Nagata <nagata@sraoss.co.jp>
Date: Mon, 3 Sep 2018 21:59:07 +0900
Subject: [PATCH] Allow pg_verify_checksums to specify a database to scan

---
 doc/src/sgml/ref/pg_verify_checksums.sgml     | 20 +++++++++++
 .../pg_verify_checksums/pg_verify_checksums.c | 35 ++++++++++++++++---
 2 files changed, 51 insertions(+), 4 deletions(-)

diff --git a/doc/src/sgml/ref/pg_verify_checksums.sgml b/doc/src/sgml/ref/pg_verify_checksums.sgml
index 905b8f1222..688a18495d 100644
--- a/doc/src/sgml/ref/pg_verify_checksums.sgml
+++ b/doc/src/sgml/ref/pg_verify_checksums.sgml
@@ -70,6 +70,26 @@ PostgreSQL documentation
       </listitem>
      </varlistentry>
 
+     <varlistentry>
+      <term><option>-d <replaceable>oid</replaceable></option></term>
+      <term><option>--dboid=<replaceable>oid</replaceable></option></term>
+      <listitem>
+       <para>
+        Only validate checksums in the relations in the database with specified OID.
+       </para>
+      </listitem>
+     </varlistentry>
+
+     <varlistentry>
+      <term><option>-g</option></term>
+      <term><option>--globel-only</option></term>
+      <listitem>
+       <para>
+        Only validate checksums in the relations in the shared database.
+       </para>
+      </listitem>
+     </varlistentry>
+
      <varlistentry>
       <term><option>-r <replaceable>relfilenode</replaceable></option></term>
       <listitem>
diff --git a/src/bin/pg_verify_checksums/pg_verify_checksums.c b/src/bin/pg_verify_checksums/pg_verify_checksums.c
index d46bac2cd6..f671e6fd1b 100644
--- a/src/bin/pg_verify_checksums/pg_verify_checksums.c
+++ b/src/bin/pg_verify_checksums/pg_verify_checksums.c
@@ -28,6 +28,8 @@ static int64 badblocks = 0;
 static ControlFileData *ControlFile;
 
 static char *only_relfilenode = NULL;
+static char *only_dboid = NULL;
+static bool only_global = false;
 static bool verbose = false;
 
 static const char *progname;
@@ -41,6 +43,8 @@ usage(void)
 	printf(_("\nOptions:\n"));
 	printf(_(" [-D, --pgdata=]DATADIR  data directory\n"));
 	printf(_("  -v, --verbose          output verbose messages\n"));
+	printf(_("  -d, --dboid=OID        check only relations in database with specified OID\n"));
+	printf(_("  -g, --global-only      check only shared relations\n"));
 	printf(_("  -r RELFILENODE         check only relation with specified relfilenode\n"));
 	printf(_("  -V, --version          output version information, then exit\n"));
 	printf(_("  -?, --help             show this help, then exit\n"));
@@ -198,7 +202,13 @@ scan_directory(const char *basedir, const char *subdir)
 #else
 		else if (S_ISDIR(st.st_mode) || pgwin32_is_junction(fn))
 #endif
+		{
+			if (atoi(de->d_name) != 0 && strcmp(subdir, "pg_tblspc") &&
+				only_dboid && strcmp(only_dboid, de->d_name) != 0)
+				continue;
+
 			scan_directory(path, de->d_name);
+		}
 	}
 	closedir(dir);
 }
@@ -208,6 +218,8 @@ main(int argc, char *argv[])
 {
 	static struct option long_options[] = {
 		{"pgdata", required_argument, NULL, 'D'},
+		{"dboid", required_argument, NULL, 'd'},
+		{"global-only", no_argument, NULL, 'g'},
 		{"verbose", no_argument, NULL, 'v'},
 		{NULL, 0, NULL, 0}
 	};
@@ -235,7 +247,7 @@ main(int argc, char *argv[])
 		}
 	}
 
-	while ((c = getopt_long(argc, argv, "D:r:v", long_options, &option_index)) != -1)
+	while ((c = getopt_long(argc, argv, "D:r:d:gv", long_options, &option_index)) != -1)
 	{
 		switch (c)
 		{
@@ -253,6 +265,17 @@ main(int argc, char *argv[])
 				}
 				only_relfilenode = pstrdup(optarg);
 				break;
+			case 'd':
+				if (atoi(optarg) <= 0)
+				{
+					fprintf(stderr, _("%s: invalid database oid specification, must be numeric: %s\n"), progname, optarg);
+					exit(1);
+				}
+				only_dboid = pstrdup(optarg);
+				break;
+			case 'g':
+				only_global = true;
+				break;
 			default:
 				fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
 				exit(1);
@@ -307,9 +330,13 @@ main(int argc, char *argv[])
 	}
 
 	/* Scan all files */
-	scan_directory(DataDir, "global");
-	scan_directory(DataDir, "base");
-	scan_directory(DataDir, "pg_tblspc");
+	if (!only_dboid)
+		scan_directory(DataDir, "global");
+	if (!only_global)
+	{
+		scan_directory(DataDir, "base");
+		scan_directory(DataDir, "pg_tblspc");
+	}
 
 	printf(_("Checksum scan completed\n"));
 	printf(_("Data checksum version: %d\n"), ControlFile->data_checksum_version);
-- 
2.17.1

#24Fabien COELHO
coelho@cri.ensmp.fr
In reply to: Yugo Nagata (#23)
Re: pg_verify_checksums -d option (was: Re: pg_verify_checksums -r option)

Hello Yugo-san,

I attached the rebased patch.

Patch applies cleanly, compiles, "make check" is okay, although there are
no specific test for the feature. Indeed, after investigation there is not
a SINGLE test for the command:-(

I think that some minimal tap-testing should be done. It seems that
pg_basebackup tap test is the only one which enables checksums. Maybe a
pg_verify_checksum could be added to the "010_pg_basebackup.pl" script.

Anyway I tested that it works by hex-editing a file to trigger a fail.

Function "atoi" is quite lazy, it accepts "-d 1zzz" as "1". Maybe parsing
could be stricter.

When the command is started with both "-d 1 -g", it succeeds by checking
nothing, which is quite misleading. Probably it should complain that these
options are mutually exclusive, or it should check both under -g AND -d 1?

The oid of a database is not obvious... You have to query "SELECT oid, *",
it is not given by \l or \l+ or "psql -l".

About the documentation:

"Only validate checksums in the relations in the database with specified
OID."... I think that indexes and other possibly toasted values are also
checked. I'd suggest "Only validate checksums of objects in the database
specified by its OID".

"--globel-only" -> "--global-only".

ISTM that --help should show options in alphabetical order, however -v is
out of order.

--
Fabien.

#25Masahiko Sawada
sawada.mshk@gmail.com
In reply to: Yugo Nagata (#23)
Re: pg_verify_checksums -d option (was: Re: pg_verify_checksums -r option)

On Mon, Sep 3, 2018 at 10:06 PM, Yugo Nagata <nagata@sraoss.co.jp> wrote:

Hi,

On Sat, 1 Sep 2018 07:40:40 +0200 (CEST)
Fabien COELHO <coelho@cri.ensmp.fr> wrote:

Attached is a patch to allow pg_verity_checksums to specify a database
to scan. This is usefule for users who want to verify checksums of relations
in a specific database. We can specify a database by OID using -d or --dboid option.
Also, when -g or --global-only is used only shared relations are scaned.

It seems that the patch does not apply anymore. Could you rebase it?

I attached the rebased patch.

FWIW, I think it would be good if we can specify multiple database
oids to the -d option, like "pg_verify_checksums -d 12345 -d 23456".
Maybe it's the same for the -r option.

Regards,

--
Masahiko Sawada
NIPPON TELEGRAPH AND TELEPHONE CORPORATION
NTT Open Source Software Center