diff --git a/doc/src/sgml/ref/pgbench.sgml b/doc/src/sgml/ref/pgbench.sgml index 850028557d..ea6f49304e 100644 --- a/doc/src/sgml/ref/pgbench.sgml +++ b/doc/src/sgml/ref/pgbench.sgml @@ -461,7 +461,6 @@ pgbench options d - diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c index c1134eae5b..00aeb202ee 100644 --- a/src/bin/pgbench/pgbench.c +++ b/src/bin/pgbench/pgbench.c @@ -929,7 +929,8 @@ usage(void) " --show-script=NAME show builtin script code, then exit\n" " --verbose-errors print messages of all errors\n" "\nCommon options:\n" - " -d, --debug print debugging output\n" + " --debug print debugging output\n" + " -d, --dbname=DBNAME database name to connect to\n" " -h, --host=HOSTNAME database server host or socket directory\n" " -p, --port=PORT database server port number\n" " -U, --username=USERNAME connect as specified database user\n" @@ -6562,7 +6563,7 @@ main(int argc, char **argv) {"builtin", required_argument, NULL, 'b'}, {"client", required_argument, NULL, 'c'}, {"connect", no_argument, NULL, 'C'}, - {"debug", no_argument, NULL, 'd'}, + {"dbname", required_argument, NULL, 'd'}, {"define", required_argument, NULL, 'D'}, {"file", required_argument, NULL, 'f'}, {"fillfactor", required_argument, NULL, 'F'}, @@ -6602,6 +6603,7 @@ main(int argc, char **argv) {"failures-detailed", no_argument, NULL, 13}, {"max-tries", required_argument, NULL, 14}, {"verbose-errors", no_argument, NULL, 15}, + {"debug", no_argument, NULL, 16}, {NULL, 0, NULL, 0} }; @@ -6673,7 +6675,7 @@ main(int argc, char **argv) if (!set_random_seed(getenv("PGBENCH_RANDOM_SEED"))) pg_fatal("error while setting random seed from PGBENCH_RANDOM_SEED environment variable"); - while ((c = getopt_long(argc, argv, "b:c:CdD:f:F:h:iI:j:lL:M:nNp:P:qrR:s:St:T:U:v", long_options, &optindex)) != -1) + while ((c = getopt_long(argc, argv, "b:c:Cd:D:f:F:h:iI:j:lL:M:nNp:P:qrR:s:St:T:U:v", long_options, &optindex)) != -1) { char *script; @@ -6714,7 +6716,7 @@ main(int argc, char **argv) is_connect = true; break; case 'd': - pg_logging_increase_verbosity(); + dbName = pg_strdup(optarg); break; case 'D': { @@ -6939,6 +6941,9 @@ main(int argc, char **argv) benchmarking_option_set = true; verbose_errors = true; break; + case 16: /* debug */ + pg_logging_increase_verbosity(); + break; default: /* getopt_long already emitted a complaint */ pg_log_error_hint("Try \"%s --help\" for more information.", progname); @@ -6989,16 +6994,19 @@ main(int argc, char **argv) */ throttle_delay *= nthreads; - if (argc > optind) - dbName = argv[optind++]; - else + if (dbName == NULL) { - if ((env = getenv("PGDATABASE")) != NULL && *env != '\0') - dbName = env; - else if ((env = getenv("PGUSER")) != NULL && *env != '\0') - dbName = env; + if (argc > optind) + dbName = argv[optind++]; else - dbName = get_user_name_or_exit(progname); + { + if ((env = getenv("PGDATABASE")) != NULL && *env != '\0') + dbName = env; + else if ((env = getenv("PGUSER")) != NULL && *env != '\0') + dbName = env; + else + dbName = get_user_name_or_exit(progname); + } } if (optind < argc) diff --git a/src/bin/pgbench/t/001_pgbench_with_server.pl b/src/bin/pgbench/t/001_pgbench_with_server.pl index 8c9a08e446..1db35a0aa2 100644 --- a/src/bin/pgbench/t/001_pgbench_with_server.pl +++ b/src/bin/pgbench/t/001_pgbench_with_server.pl @@ -1281,7 +1281,7 @@ my $err_pattern = . "\\1"; $node->pgbench( - "-n -c 2 -t 1 -d --verbose-errors --max-tries 2", + "-n -c 2 -t 1 --debug --verbose-errors --max-tries 2", 0, [ qr{processed: 2/2\b}, diff --git a/src/bin/pgbench/t/002_pgbench_no_server.pl b/src/bin/pgbench/t/002_pgbench_no_server.pl index 0ec54fbb03..3e293cb86a 100644 --- a/src/bin/pgbench/t/002_pgbench_no_server.pl +++ b/src/bin/pgbench/t/002_pgbench_no_server.pl @@ -67,9 +67,14 @@ my @options = ( # name, options, stderr checks [ 'bad option', - '-h home -p 5432 -U calvin -d --bad-option', + '-h home -p 5432 -U calvin ---debug --bad-option', [qr{--help.*more information}] ], + [ + 'invalid database', + '-d nosuchdbname', + [qr{database "nosuchdbname" does not exist}] + ], [ 'no file', '-f no-such-file',