Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Adjust pgbench option for debug mode.
authorNathan Bossart <nathan@postgresql.org>
Mon, 25 Mar 2024 16:08:53 +0000 (11:08 -0500)
committerNathan Bossart <nathan@postgresql.org>
Mon, 25 Mar 2024 16:08:53 +0000 (11:08 -0500)
Many other utilities use -d to specify the database to use, but
pgbench uses it to enable debug mode.  This is causing some users
to accidentally enable it.  This commit changes -d to accept the
database name and introduces --dbname.  Debug mode can still be
enabled with --debug.  This is a backward-incompatible change, but
it has been judged to be worth the trade-off, i.e., some scripts
that use pgbench will need to be updated.

Author: Greg Sabino Mullane
Reviewed-by: Tomas Vondra, Euler Taveira, Alvaro Herrera, David Christensen
Discussion: https://postgr.es/m/CAKAnmmLjAzwVtb%3DVEaeuCtnmOLpzkJ1uJ_XiQ362YdD9B72HSg%40mail.gmail.com

doc/src/sgml/ref/pgbench.sgml
src/bin/pgbench/pgbench.c
src/bin/pgbench/t/001_pgbench_with_server.pl
src/bin/pgbench/t/002_pgbench_no_server.pl

index 279bb0ad7df4113f4e81ed315b5f67d79984c1c6..c3d0ec240b1c34d09ebcf035b2a9c495bdd6379f 100644 (file)
@@ -162,7 +162,8 @@ pgbench <optional> <replaceable>options</replaceable> </optional> <replaceable>d
     <variablelist>
 
      <varlistentry id="pgbench-option-dbname">
-      <term><replaceable class="parameter">dbname</replaceable></term>
+      <term><option><optional>-d</optional> <replaceable class="parameter">dbname</replaceable></option></term>
+      <term><option><optional>--dbname=</optional><replaceable class="parameter">dbname</replaceable></option></term>
       <listitem>
        <para>
         Specifies the name of the database to test in. If this is
@@ -463,7 +464,6 @@ pgbench <optional> <replaceable>options</replaceable> </optional> <replaceable>d
      </varlistentry>
 
      <varlistentry id="pgbench-option-debug">
-      <term><option>-d</option></term>
       <term><option>--debug</option></term>
       <listitem>
        <para>
index af1f75257ff0a72f56cdef4bb2b798188c6ed058..af776b31d8f785ececc091b8f5a90216a296ca9e 100644 (file)
@@ -933,7 +933,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"
@@ -6620,7 +6621,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'},
@@ -6661,6 +6662,7 @@ main(int argc, char **argv)
        {"max-tries", required_argument, NULL, 14},
        {"verbose-errors", no_argument, NULL, 15},
        {"exit-on-abort", no_argument, NULL, 16},
+       {"debug", no_argument, NULL, 17},
        {NULL, 0, NULL, 0}
    };
 
@@ -6732,7 +6734,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;
 
@@ -6773,7 +6775,7 @@ main(int argc, char **argv)
                is_connect = true;
                break;
            case 'd':
-               pg_logging_increase_verbosity();
+               dbName = pg_strdup(optarg);
                break;
            case 'D':
                {
@@ -6998,6 +7000,9 @@ main(int argc, char **argv)
                benchmarking_option_set = true;
                exit_on_abort = true;
                break;
+           case 17:            /* debug */
+               pg_logging_increase_verbosity();
+               break;
            default:
                /* getopt_long already emitted a complaint */
                pg_log_error_hint("Try \"%s --help\" for more information.", progname);
@@ -7048,16 +7053,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)
index 5d2341a203531a08fbe3e65cb94273adf09e7599..d0a86a280cdadf23019636804916f35f4031fb08 100644 (file)
@@ -1352,7 +1352,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},
index e0e4d92b06ee123371cea46b0b0f3fb3d1d68714..a04b3531f42d36589b74eaaf2e86de5149145b25 100644 (file)
@@ -66,7 +66,7 @@ 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}]
    ],
    [