Thread: Service startup delay
We are incorporating the win32 port into our product, and have run into a problem with the timing of the startup of the windows service. What is happening is that we have setup a dependency between our service and the postgres service so that our service starts after the postgres one. However this sometimes still fails, as it appears the postgres service returns control to windows before the database is actually fully started and ready to accept connections as we are getting an error in our app (org.postgresql.util.PSQLException: A connection error has occurred: org.postgresql.util.PSQLException: FATAL: the database system is starting up). Can this be fixed? We can hack around this in our code, but it would be nice (and I am sure others will run into this as well) if this was fixed properly in the postgres service itself.
thanks,
--Barry
Barry Lind wrote: > We are incorporating the win32 port into our product, and have run into > a problem with the timing of the startup of the windows service. What > is happening is that we have setup a dependency between our service and > the postgres service so that our service starts after the postgres one. > However this sometimes still fails, as it appears the postgres service > returns control to windows before the database is actually fully started > and ready to accept connections as we are getting an error in our app > (org.postgresql.util.PSQLException: A connection error has occurred: > org.postgresql.util.PSQLException: FATAL: the database system is > starting up). Can this be fixed? We can hack around this in our code, > but it would be nice (and I am sure others will run into this as well) > if this was fixed properly in the postgres service itself. I think you need to use 'pg_ctl -w' to wait for it to start. -- 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
> -----Original Message----- > From: pgsql-hackers-win32-owner@postgresql.org > [mailto:pgsql-hackers-win32-owner@postgresql.org] On Behalf > Of Bruce Momjian > Sent: 20 August 2004 19:00 > To: Barry Lind > Cc: pgsql-hackers-win32@postgresql.org; Max Dunn > Subject: Re: [pgsql-hackers-win32] Service startup delay > > > I think you need to use 'pg_ctl -w' to wait for it to start. > Does -w work when starting in service mode? Aside from that, one possible problem with this is what happens if the database goes into recovery mode at startup. Whilst waiting for that to run, I would think it's possible that the service control manager would timeout waiting for the service to complete startup. Regards, Dave.
I tried adding the "-w" option to the registry entry for starting the Postgres service(see below) but it didn't help; Tomcat still started before Postgres was ready: c:\Program Files\Xythos\WebFile Server Evaluation\pgsql\bin>sc qc postgresql [SC] GetServiceConfig SUCCESS SERVICE_NAME: postgresql TYPE : 10 WIN32_OWN_PROCESS START_TYPE : 2 AUTO_START ERROR_CONTROL : 1 NORMAL BINARY_PATH_NAME : C:/Program Files/Xythos/WebFile Server Evaluation/p gsql/bin/pg_ctl.exe runservice -w -N "PostgreSQL" -D "C:/Program Files/Xythos/We bFile Server Evaluation/pgsql/data" -o "-i" LOAD_ORDER_GROUP : TAG : 0 DISPLAY_NAME : PostgreSQL DEPENDENCIES : RPCSS SERVICE_START_NAME : .\postgres --Max -----Original Message----- From: Dave Page [mailto:dpage@vale-housing.co.uk] Sent: Friday, August 20, 2004 4:09 PM To: Bruce Momjian; Barry Lind Cc: pgsql-hackers-win32@postgresql.org; Max Dunn Subject: RE: [pgsql-hackers-win32] Service startup delay > -----Original Message----- > From: pgsql-hackers-win32-owner@postgresql.org > [mailto:pgsql-hackers-win32-owner@postgresql.org] On Behalf Of Bruce > Momjian > Sent: 20 August 2004 19:00 > To: Barry Lind > Cc: pgsql-hackers-win32@postgresql.org; Max Dunn > Subject: Re: [pgsql-hackers-win32] Service startup delay > > > I think you need to use 'pg_ctl -w' to wait for it to start. > Does -w work when starting in service mode? Aside from that, one possible problem with this is what happens if the database goes into recovery mode at startup. Whilst waiting for that to run, I would think it's possible that the service control manager would timeout waiting for the service to complete startup. Regards, Dave.
I found a bug in pg_ctl -w handling and am working on a patch right now. --------------------------------------------------------------------------- Max Dunn wrote: > I tried adding the "-w" option to the registry entry for starting the > Postgres service(see below) but it didn't help; Tomcat still started before > Postgres was ready: > > c:\Program Files\Xythos\WebFile Server Evaluation\pgsql\bin>sc qc postgresql > [SC] GetServiceConfig SUCCESS > > SERVICE_NAME: postgresql > TYPE : 10 WIN32_OWN_PROCESS > START_TYPE : 2 AUTO_START > ERROR_CONTROL : 1 NORMAL > BINARY_PATH_NAME : C:/Program Files/Xythos/WebFile Server > Evaluation/p > gsql/bin/pg_ctl.exe runservice -w -N "PostgreSQL" -D "C:/Program > Files/Xythos/We > bFile Server Evaluation/pgsql/data" -o "-i" > LOAD_ORDER_GROUP : > TAG : 0 > DISPLAY_NAME : PostgreSQL > DEPENDENCIES : RPCSS > SERVICE_START_NAME : .\postgres > > --Max > > -----Original Message----- > From: Dave Page [mailto:dpage@vale-housing.co.uk] > Sent: Friday, August 20, 2004 4:09 PM > To: Bruce Momjian; Barry Lind > Cc: pgsql-hackers-win32@postgresql.org; Max Dunn > Subject: RE: [pgsql-hackers-win32] Service startup delay > > > > > -----Original Message----- > > From: pgsql-hackers-win32-owner@postgresql.org > > [mailto:pgsql-hackers-win32-owner@postgresql.org] On Behalf Of Bruce > > Momjian > > Sent: 20 August 2004 19:00 > > To: Barry Lind > > Cc: pgsql-hackers-win32@postgresql.org; Max Dunn > > Subject: Re: [pgsql-hackers-win32] Service startup delay > > > > > > I think you need to use 'pg_ctl -w' to wait for it to start. > > > > Does -w work when starting in service mode? Aside from that, one possible > problem with this is what happens if the database goes into recovery mode at > startup. Whilst waiting for that to run, I would think it's possible that > the service control manager would timeout waiting for the service to > complete startup. > > Regards, Dave. > > > ---------------------------(end of broadcast)--------------------------- > TIP 9: the planner will ignore your desire to choose an index scan if your > joining column's datatypes do not match > -- 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
Bruce, I installed the build compiled on 8/21 (which I assume contains this patch) and added the -w option, but it didn't solve the problem. The first two reboots worked fine, but on the third reboot, the subsequent service (Tomcat) started up before Postgres was ready. (Besides our applet not starting, the postmaster.pid timestamp was 2 seconds after Tomcat started.) Another issue is that when installing the Postgres service with "pg_ctl register -w ...." the "-w" parameter was not put in the registry "ImagePath" value for the Postgres service. (I added it manually to test.) So I suspect that "pg_ctl register" will need to be enhanced to add the "-w" parameter to the registry settings. --Max -----Original Message----- From: Bruce Momjian [mailto:pgman@candle.pha.pa.us] Sent: Friday, August 20, 2004 8:12 PM To: Max Dunn Cc: 'Dave Page'; 'Barry Lind'; pgsql-hackers-win32@postgresql.org; PostgreSQL-patches Subject: Re: [pgsql-hackers-win32] Service startup delay OK, I started running tests with pg_ctl -w and found it did not work even on Unix. I found that the code was not checking the return value of PQsetdbLogin(), and wasn't looping properly using a sleep. The attached applied patch should fix should fix your reported problem. --------------------------------------------------------------------------- Max Dunn wrote: > I tried adding the "-w" option to the registry entry for starting the > Postgres service(see below) but it didn't help; Tomcat still started > before Postgres was ready: > > c:\Program Files\Xythos\WebFile Server Evaluation\pgsql\bin>sc qc > postgresql [SC] GetServiceConfig SUCCESS > > SERVICE_NAME: postgresql > TYPE : 10 WIN32_OWN_PROCESS > START_TYPE : 2 AUTO_START > ERROR_CONTROL : 1 NORMAL > BINARY_PATH_NAME : C:/Program Files/Xythos/WebFile Server > Evaluation/p > gsql/bin/pg_ctl.exe runservice -w -N "PostgreSQL" -D "C:/Program > Files/Xythos/We bFile Server Evaluation/pgsql/data" -o "-i" > LOAD_ORDER_GROUP : > TAG : 0 > DISPLAY_NAME : PostgreSQL > DEPENDENCIES : RPCSS > SERVICE_START_NAME : .\postgres > > --Max > > -----Original Message----- > From: Dave Page [mailto:dpage@vale-housing.co.uk] > Sent: Friday, August 20, 2004 4:09 PM > To: Bruce Momjian; Barry Lind > Cc: pgsql-hackers-win32@postgresql.org; Max Dunn > Subject: RE: [pgsql-hackers-win32] Service startup delay > > > > > -----Original Message----- > > From: pgsql-hackers-win32-owner@postgresql.org > > [mailto:pgsql-hackers-win32-owner@postgresql.org] On Behalf Of Bruce > > Momjian > > Sent: 20 August 2004 19:00 > > To: Barry Lind > > Cc: pgsql-hackers-win32@postgresql.org; Max Dunn > > Subject: Re: [pgsql-hackers-win32] Service startup delay > > > > > > I think you need to use 'pg_ctl -w' to wait for it to start. > > > > Does -w work when starting in service mode? Aside from that, one > possible problem with this is what happens if the database goes into > recovery mode at startup. Whilst waiting for that to run, I would > think it's possible that the service control manager would timeout > waiting for the service to complete startup. > > Regards, Dave. > > > ---------------------------(end of > broadcast)--------------------------- > TIP 9: the planner will ignore your desire to choose an index scan if your > joining column's datatypes do not match > -- 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
Max Dunn wrote: > Bruce, > > I installed the build compiled on 8/21 (which I assume contains this patch) The patch was applied around midnight on 8/21 so I suggest you try an newer download. I wish I could give you an easy to see if the -w is working but I can't on Win32. On unix I changed the system call to do "sh -c "sleep 40; postmastger ..." & but that doesn't work on Win32. If you have source put a sleep call at the top of the postmaster code and see if the -w hangs printing does while waiting for the system to start. > and added the -w option, but it didn't solve the problem. The first two > reboots worked fine, but on the third reboot, the subsequent service > (Tomcat) started up before Postgres was ready. (Besides our applet not > starting, the postmaster.pid timestamp was 2 seconds after Tomcat started.) > > Another issue is that when installing the Postgres service with "pg_ctl > register -w ...." the "-w" parameter was not put in the registry "ImagePath" > value for the Postgres service. (I added it manually to test.) So I suspect > that "pg_ctl register" will need to be enhanced to add the "-w" parameter to > the registry settings. Would a Win32 guy look at this? -- 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
Your patch has been added to the PostgreSQL unapplied patches list at: http://momjian.postgresql.org/cgi-bin/pgpatches It will be applied as soon as one of the PostgreSQL committers reviews and approves it. --------------------------------------------------------------------------- Dave Page wrote: > > > > -----Original Message----- > > From: Bruce Momjian [mailto:pgman@candle.pha.pa.us] > > Sent: 26 August 2004 02:44 > > To: Max Dunn > > Cc: Dave Page; 'Barry Lind'; pgsql-hackers-win32@postgresql.org > > Subject: Re: [pgsql-hackers-win32] Service startup delay > > > > > Another issue is that when installing the Postgres service with > > > "pg_ctl register -w ...." the "-w" parameter was not put in > > the registry "ImagePath" > > > value for the Postgres service. (I added it manually to test.) So I > > > suspect that "pg_ctl register" will need to be enhanced to add the > > > "-w" parameter to the registry settings. > > > > Would a Win32 guy look at this? > > No problem. > > Regards, Dave. > > =================================================================== > RCS file: /projects/cvsroot/pgsql-server/src/bin/pg_ctl/pg_ctl.c,v > retrieving revision 1.25 > diff -u -r1.25 pg_ctl.c > --- pg_ctl.c 21 Aug 2004 03:12:55 -0000 1.25 > +++ pg_ctl.c 26 Aug 2004 14:37:13 -0000 > @@ -832,6 +832,9 @@ > strcat(cmdLine,"\""); > } > > + if (do_wait) > + strcat(cmdLine, " -w"); > + > if (post_opts) > { > strcat(cmdLine," "); > @@ -1038,7 +1041,7 @@ > printf(_(" %s status [-D DATADIR]\n"), progname); > printf(_(" %s kill SIGNALNAME PROCESSID\n"), progname); > #ifdef WIN32 > - printf(_(" %s register [-N servicename] [-U username] [-P > password] [-D DATADIR] [-o \"OPTIONS\"]\n"), progname); > + printf(_(" %s register [-N servicename] [-U username] [-P > password] [-D DATADIR] [-w] [-o \"OPTIONS\"]\n"), progname); > printf(_(" %s unregister [-N servicename]\n"), progname); > #endif > printf(_("Common options:\n")); > -- 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