Re: [HACKERS] pg_ctl configurable timeout

Поиск
Список
Период
Сортировка
Искать

Re: [HACKERS] pg_ctl configurable timeout

От:
Bruce Momjian <bruce@momjian.us>
Дата:
bruce wrote:
> Tom Lane wrote:
> > Andrew Dunstan  writes:
> > > Bruce Momjian wrote:
> > >> How about an environment variable to control the timeout?  Is that
> > >> cleaner?
> > 
> > > I don't see why it should be. I think Peter's --timeout suggestion 
> > > should be just fine.
> > 
> > I wrote a moment ago that the user can hit control-C when he gets bored,
> > but that argument only works for interactive use of pg_ctl.  In a script
> > I think you'd want a --timeout option.  I don't see the advantage of
> > an environment variable in either scenario.
> 
> I have implemented pg_ctl -t secs timeout option with the attached
> patch.  It still defaults to 60.  I did not code the 'ping' option.

Modified patch applied.

-- 
  Bruce Momjian          http://momjian.us
  EnterpriseDB                             http://postgres.enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +
Index: doc/src/sgml/ref/pg_ctl-ref.sgml
===================================================================
RCS file: /cvsroot/pgsql/doc/src/sgml/ref/pg_ctl-ref.sgml,v
retrieving revision 1.43
diff -c -c -r1.43 pg_ctl-ref.sgml
*** doc/src/sgml/ref/pg_ctl-ref.sgml	10 Nov 2007 14:07:18 -0000	1.43
--- doc/src/sgml/ref/pg_ctl-ref.sgml	10 Nov 2007 21:42:26 -0000
***************
*** 21,29 ****
--- 21,31 ----
  
   
    
+ 
     pg_ctl
     start
     -w
+    -t seconds
     -s
     -D datadir
     -l filename
***************
*** 31,39 ****
--- 33,43 ----
     -p path
     -c
     
+ 
     pg_ctl
     stop
     -W
+    -t seconds
     -s
     -D datadir
     -m
***************
*** 44,52 ****
--- 48,58 ----
       
     
     
+ 
     pg_ctl
     restart
     -w
+    -t seconds
     -s
     -D datadir
     -c
***************
*** 59,78 ****
--- 65,88 ----
     
     -o options
     
+ 
     pg_ctl
     reload
     -s
     -D datadir
     
+ 
     pg_ctl
     status
     -D datadir
     
+ 
     pg_ctl
     kill
     signal_name
     process_id
     
+ 
     pg_ctl
     register
     -N servicename
***************
*** 80,90 ****
--- 90,103 ----
     -P password
     -D datadir
     -w
+    -t seconds
     -o options
     
+ 
     pg_ctl
     unregister
     -N servicename
+ 
    
   
  
***************
*** 262,272 ****
       
  
       
        
        
         
!         Wait for the start or shutdown to complete.  Times out after
!         60 seconds.  This is the default for shutdowns. A successful 
          shutdown is indicated by removal of the PID 
          file. For starting up, a successful psql -l 
          indicates success. pg_ctl will attempt to 
--- 275,295 ----
       
  
       
+       
+       
+        
+         The number of seconds to wait when waiting for start or shutdown
+         to complete.
+        
+       
+      
+ 
+      
        
        
         
!         Wait for the start or shutdown to complete.  The default wait time
!         is 60 seconds.  This is the default option for shutdowns. A successful 
          shutdown is indicated by removal of the PID 
          file. For starting up, a successful psql -l 
          indicates success. pg_ctl will attempt to 
Index: src/bin/pg_ctl/pg_ctl.c
===================================================================
RCS file: /cvsroot/pgsql/src/bin/pg_ctl/pg_ctl.c,v
retrieving revision 1.85
diff -c -c -r1.85 pg_ctl.c
*** src/bin/pg_ctl/pg_ctl.c	31 Oct 2007 10:55:25 -0000	1.85
--- src/bin/pg_ctl/pg_ctl.c	10 Nov 2007 21:42:27 -0000
***************
*** 1465,1485 ****
  	printf(_("%s is a utility to start, stop, restart, reload configuration files,\n"
  			 "report the status of a PostgreSQL server, or signal a PostgreSQL process.\n\n"), progname);
  	printf(_("Usage:\n"));
! 	printf(_("  %s start   [-w] [-D DATADIR] [-s] [-l FILENAME] [-o \"OPTIONS\"]\n"), progname);
  	printf(_("  %s stop    [-W] [-D DATADIR] [-s] [-m SHUTDOWN-MODE]\n"), progname);
! 	printf(_("  %s restart [-w] [-D DATADIR] [-s] [-m SHUTDOWN-MODE] [-o \"OPTIONS\"]\n"), progname);
  	printf(_("  %s reload  [-D DATADIR] [-s]\n"), progname);
  	printf(_("  %s status  [-D DATADIR]\n"), progname);
  	printf(_("  %s kill    SIGNALNAME PID\n"), progname);
  #if defined(WIN32) || defined(__CYGWIN__)
  	printf(_("  %s register   [-N SERVICENAME] [-U USERNAME] [-P PASSWORD] [-D DATADIR]\n"
! 			 "                    [-w] [-o \"OPTIONS\"]\n"), progname);
  	printf(_("  %s unregister [-N SERVICENAME]\n"), progname);
  #endif
  
  	printf(_("\nCommon options:\n"));
  	printf(_("  -D, --pgdata DATADIR   location of the database storage area\n"));
  	printf(_("  -s, --silent           only print errors, no informational messages\n"));
  	printf(_("  -w                     wait until operation completes\n"));
  	printf(_("  -W                     do not wait until operation completes\n"));
  	printf(_("  --help                 show this help, then exit\n"));
--- 1465,1486 ----
  	printf(_("%s is a utility to start, stop, restart, reload configuration files,\n"
  			 "report the status of a PostgreSQL server, or signal a PostgreSQL process.\n\n"), progname);
  	printf(_("Usage:\n"));
! 	printf(_("  %s start   [-w] [-t secs] [-D DATADIR] [-s] [-l FILENAME] [-o \"OPTIONS\"]\n"), progname);
  	printf(_("  %s stop    [-W] [-D DATADIR] [-s] [-m SHUTDOWN-MODE]\n"), progname);
! 	printf(_("  %s restart [-w] [-t secs] [-D DATADIR] [-s] [-m SHUTDOWN-MODE]\n                   [-o \"OPTIONS\"]\n"), progname);
  	printf(_("  %s reload  [-D DATADIR] [-s]\n"), progname);
  	printf(_("  %s status  [-D DATADIR]\n"), progname);
  	printf(_("  %s kill    SIGNALNAME PID\n"), progname);
  #if defined(WIN32) || defined(__CYGWIN__)
  	printf(_("  %s register   [-N SERVICENAME] [-U USERNAME] [-P PASSWORD] [-D DATADIR]\n"
! 			 "                    [-w] [-t timeout] [-o \"OPTIONS\"]\n"), progname);
  	printf(_("  %s unregister [-N SERVICENAME]\n"), progname);
  #endif
  
  	printf(_("\nCommon options:\n"));
  	printf(_("  -D, --pgdata DATADIR   location of the database storage area\n"));
  	printf(_("  -s, --silent           only print errors, no informational messages\n"));
+ 	printf(_("  -t secs                seconds to wait when using -w option\n"));
  	printf(_("  -w                     wait until operation completes\n"));
  	printf(_("  -W                     do not wait until operation completes\n"));
  	printf(_("  --help                 show this help, then exit\n"));
***************
*** 1592,1597 ****
--- 1593,1599 ----
  		{"mode", required_argument, NULL, 'm'},
  		{"pgdata", required_argument, NULL, 'D'},
  		{"silent", no_argument, NULL, 's'},
+ 		{"timeout", required_argument, NULL, 't'},
  		{"core-files", no_argument, NULL, 'c'},
  		{NULL, 0, NULL, 0}
  	};
***************
*** 1657,1663 ****
  	/* process command-line options */
  	while (optind < argc)
  	{
! 		while ((c = getopt_long(argc, argv, "cD:l:m:N:o:p:P:sU:wW", long_options, &option_index)) != -1)
  		{
  			switch (c)
  			{
--- 1659,1665 ----
  	/* process command-line options */
  	while (optind < argc)
  	{
! 		while ((c = getopt_long(argc, argv, "cD:l:m:N:o:p:P:st:U:wW", long_options, &option_index)) != -1)
  		{
  			switch (c)
  			{
***************
*** 1704,1709 ****
--- 1706,1714 ----
  				case 's':
  					silent_mode = true;
  					break;
+ 				case 't':
+ 					wait_seconds = atoi(optarg);
+ 					break;
  				case 'U':
  					if (strchr(optarg, '\\'))
  						register_username = xstrdup(optarg);
FAQ