Accept pg_ctl timeout from the PGCTLTIMEOUT environment variable.
authorNoah Misch <[email protected]>
Thu, 11 Feb 2016 01:34:02 +0000 (20:34 -0500)
committerNoah Misch <[email protected]>
Thu, 11 Feb 2016 01:34:24 +0000 (20:34 -0500)
Many automated test suites call pg_ctl.  Buildfarm members axolotl,
hornet, mandrill, shearwater, sungazer and tern have failed when server
shutdown took longer than the pg_ctl default 60s timeout.  This addition
permits slow hosts to easily raise the timeout without us editing a
--timeout argument into every test suite pg_ctl call.  Back-patch to 9.1
(all supported versions) for the sake of automated testing.

Reviewed by Tom Lane.

doc/src/sgml/ref/pg_ctl-ref.sgml
src/bin/pg_ctl/pg_ctl.c

index eaa0cc8b3701e09038a1f69063216026976d7d60..6ceb7816dc87b06a43e84a81ae0e08b69cbe9b03 100644 (file)
@@ -362,7 +362,9 @@ PostgreSQL documentation
       <listitem>
        <para>
         The maximum number of seconds to wait when waiting for startup or
-        shutdown to complete.  The default is 60 seconds.
+        shutdown to complete.  Defaults to the value of the
+        <envar>PGCTLTIMEOUT</> environment variable or, if not set, to 60
+        seconds.
        </para>
       </listitem>
      </varlistentry>
@@ -486,6 +488,17 @@ PostgreSQL documentation
   <title>Environment</title>
 
   <variablelist>
+   <varlistentry>
+    <term><envar>PGCTLTIMEOUT</envar></term>
+
+    <listitem>
+     <para>
+      Default limit on the number of seconds to wait when waiting for startup
+      or shutdown to complete.  If not set, the default is 60 seconds.
+     </para>
+    </listitem>
+   </varlistentry>
+
    <varlistentry>
     <term><envar>PGDATA</envar></term>
 
index 5d5511d38ca64ad3c725295869090b8c03df49ff..76f0f9c6131d9f53224e3351b1b50c8293b914dd 100644 (file)
@@ -79,6 +79,7 @@ typedef enum
 static bool do_wait = false;
 static bool wait_set = false;
 static int wait_seconds = DEFAULT_WAIT;
+static bool wait_seconds_arg = false;
 static bool silent_mode = false;
 static ShutdownMode shutdown_mode = FAST_MODE;
 static int sig = SIGINT;       /* default */
@@ -1456,7 +1457,8 @@ pgwin32_CommandLine(bool registration)
    if (registration && do_wait)
        appendPQExpBuffer(cmdLine, " -w");
 
-   if (registration && wait_seconds != DEFAULT_WAIT)
+   /* Don't propagate a value from an environment variable. */
+   if (registration && wait_seconds_arg && wait_seconds != DEFAULT_WAIT)
        appendPQExpBuffer(cmdLine, " -t %d", wait_seconds);
 
    if (registration && silent_mode)
@@ -2312,6 +2314,7 @@ main(int argc, char **argv)
        {NULL, 0, NULL, 0}
    };
 
+   char       *env_wait;
    int         option_index;
    int         c;
    pgpid_t     killproc = 0;
@@ -2362,6 +2365,10 @@ main(int argc, char **argv)
    }
 #endif
 
+   env_wait = getenv("PGCTLTIMEOUT");
+   if (env_wait != NULL)
+       wait_seconds = atoi(env_wait);
+
    /*
     * 'Action' can be before or after args so loop over both. Some
     * getopt_long() implementations will reorder argv[] to place all flags
@@ -2439,6 +2446,7 @@ main(int argc, char **argv)
                    break;
                case 't':
                    wait_seconds = atoi(optarg);
+                   wait_seconds_arg = true;
                    break;
                case 'U':
                    if (strchr(optarg, '\\'))