Thread: Re: [BUGS] Problems with "-w" option on pg_ctl.exe running as a windows

Re: [BUGS] Problems with "-w" option on pg_ctl.exe running as a windows

From
Bruce Momjian
Date:
Steve McWilliams wrote:
> Hello,
>
> I tried sending this the other week but for some reason it hasn't gone
> through, so I am resending:
>
> I am using Postgresql-8.0.0beta4 on Windows XP Pro and have noticed that
> attempts to run pg_ctl as a service fail when the "-w" option is included.
>  So if I register the service as follows:
>
> pg_ctl.exe -N my_svc -w -U my_user -P my_pword -D my_dir -o "-i -p 15432"
>
> then try to start the service via the GUI service manager panel, it pops
> up an error dialog saying the service started but then stopped
> immediately.  If I remove the "-w" option from the above line when it is
> registered, then I am able to start the service just file.
>
> The usage documentation for pg_ctl indicates you are supposed to be able
> to include the "-w" option when you register it as a service.  I would
> like to be able to use it, so that when Windows launches postgres, it is
> not declared to be in the fully running state prematurely.  We have
> another service that we launch which declares a dependency on postgres,
> however that dependency declaration is meaningless if postgres announces
> that it is fully running before it is truly able to accept clients.
>
> Any suggestions?  For a temporary work around I have hacked my pg_ctl.c to
> wait 5 seconds before declaring the service to be in the running state.
> Thanks in advance.

I have not forgotten this bug report.  I see now that there is no error
checking by pg_ctl for RunAsService so this patch adds the required
checking.

Hopefully the past two changes will generate some error codes we can use
to debug this, or will fix your problem.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
Index: src/bin/pg_ctl/pg_ctl.c
===================================================================
RCS file: /cvsroot/pgsql/src/bin/pg_ctl/pg_ctl.c,v
retrieving revision 1.50
diff -c -c -r1.50 pg_ctl.c
*** src/bin/pg_ctl/pg_ctl.c    21 Dec 2004 17:38:01 -0000    1.50
--- src/bin/pg_ctl/pg_ctl.c    21 Dec 2004 17:52:14 -0000
***************
*** 1078,1084 ****
      SERVICE_TABLE_ENTRY st[] = {{register_servicename, pgwin32_ServiceMain},
      {NULL, NULL}};

!     StartServiceCtrlDispatcher(st);
  }
  #endif

--- 1078,1088 ----
      SERVICE_TABLE_ENTRY st[] = {{register_servicename, pgwin32_ServiceMain},
      {NULL, NULL}};

!     if (StartServiceCtrlDispatcher(st)) == 0)
!     {
!         write_stderr(_("%s: could not start service \"%s\": error code %d\n"), progname, register_servicename, (int)
GetLastError());
!         exit(1);
!     }
  }
  #endif