Commit 2ffa8696 authored by Noah Misch's avatar Noah Misch

Accept pg_ctl timeout from the PGCTLTIMEOUT environment variable.

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.
parent 51e78ab4
...@@ -362,7 +362,9 @@ PostgreSQL documentation ...@@ -362,7 +362,9 @@ PostgreSQL documentation
<listitem> <listitem>
<para> <para>
The maximum number of seconds to wait when waiting for startup or 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> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -486,6 +488,17 @@ PostgreSQL documentation ...@@ -486,6 +488,17 @@ PostgreSQL documentation
<title>Environment</title> <title>Environment</title>
<variablelist> <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> <varlistentry>
<term><envar>PGDATA</envar></term> <term><envar>PGDATA</envar></term>
......
...@@ -72,6 +72,7 @@ typedef enum ...@@ -72,6 +72,7 @@ typedef enum
static bool do_wait = false; static bool do_wait = false;
static bool wait_set = false; static bool wait_set = false;
static int wait_seconds = DEFAULT_WAIT; static int wait_seconds = DEFAULT_WAIT;
static bool wait_seconds_arg = false;
static bool silent_mode = false; static bool silent_mode = false;
static ShutdownMode shutdown_mode = FAST_MODE; static ShutdownMode shutdown_mode = FAST_MODE;
static int sig = SIGINT; /* default */ static int sig = SIGINT; /* default */
...@@ -1431,7 +1432,8 @@ pgwin32_CommandLine(bool registration) ...@@ -1431,7 +1432,8 @@ pgwin32_CommandLine(bool registration)
if (registration && do_wait) if (registration && do_wait)
appendPQExpBuffer(cmdLine, " -w"); 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); appendPQExpBuffer(cmdLine, " -t %d", wait_seconds);
if (registration && silent_mode) if (registration && silent_mode)
...@@ -2128,6 +2130,7 @@ main(int argc, char **argv) ...@@ -2128,6 +2130,7 @@ main(int argc, char **argv)
{NULL, 0, NULL, 0} {NULL, 0, NULL, 0}
}; };
char *env_wait;
int option_index; int option_index;
int c; int c;
pgpid_t killproc = 0; pgpid_t killproc = 0;
...@@ -2178,6 +2181,10 @@ main(int argc, char **argv) ...@@ -2178,6 +2181,10 @@ main(int argc, char **argv)
} }
#endif #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 * 'Action' can be before or after args so loop over both. Some
* getopt_long() implementations will reorder argv[] to place all flags * getopt_long() implementations will reorder argv[] to place all flags
...@@ -2255,6 +2262,7 @@ main(int argc, char **argv) ...@@ -2255,6 +2262,7 @@ main(int argc, char **argv)
break; break;
case 't': case 't':
wait_seconds = atoi(optarg); wait_seconds = atoi(optarg);
wait_seconds_arg = true;
break; break;
case 'U': case 'U':
if (strchr(optarg, '\\')) if (strchr(optarg, '\\'))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment