PostgreSQL 7.3.2 running as NT service under Windows XP not always clearing PID file on restart

From: Frank Seesink <frank(at)mail(dot)wvnet(dot)edu>
To: pgsql-cygwin(at)postgresql(dot)org
Subject: PostgreSQL 7.3.2 running as NT service under Windows XP not always clearing PID file on restart
Date: 2003-05-22 20:44:30
Message-ID: bajco4$hjs$1@main.gmane.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-cygwin

Jason,

I'm noticing that my suggestion in the writeup I did--regarding
deleting the postmaster.pid file on startup--isn't working properly all
the time. Took some investigating, but basically what I'm finding is
that sometimes, after a Windows shutdown/start or restart, for reasons
I'm not 100% clear on, the file

/usr/share/postgresql/data/postmaster.pid

is left behind. Needless to say, this is a problem, as postmaster will
fail to startup automatically if that file lingers. And just as
important, does this indicate that PostgreSQL is not being given the
time it needs to clean house prior to reboot?

My suggestion to add lines to /etc/rc.d/rc.sysinit were based on the
presumption that somehow Cygwin (via cygwin1.dll??) made sure this
script was run after a restart and before any Cygwin compiled apps
kicked in. But this does not appear to be the case.

I'm not sure, but I believe the fact that postmaster is configured via
cygrunsrv as an NT service may have something to do with it. That is,
unless my hunch is wrong, postmaster in this kind of configuration acts
like any NT service. But the init scripts aren't really executed until
someone fires up a BASH shell. This, of course, won't work for having
PostgreSQL automatically fire up on a Windows restart.

[Further testing is showing that rc.init is not fired up at all on
restart, but rather rc.local is. The only problem is that rc.local
doesn't seem to kick in until AFTER the NT services have been fired up,
making it useless for the purposes here.]

I've spent the better part of my time trying to find a nice, clean,
simple way to delete a file on Windows startup (but prior to NT services
kicking in), and I'll be darned...it's a lot more difficult than I would
have imagined. It seems Microsoft didn't really provide a nice clean
boot order mechanism like *nix where you can add commands where needed.
I mean, in Linux, you have the bootstrap process, the kernel loading,
then init, which uses inittab, which then leads to the rc.* files. If
you need to have commands executed at a certain point in the startup
procedure, just add the commands to the relevant portion of the bootup
process.

But Windows appears not to have such functionality. They have their
StartUp folder, but that's useless unless you only need something done
AFTER everything like NT services are fired up AND someone has logged
in. But there are no obvious built-in mechanisms for running
scripts/commands/apps on startup or shutdown at various stages of the
processes. At least none I have found so far.

Any thoughts? Also, just as importantly, does the fact a
postmaster.pid file exists indicate any issues with the whole
cygrunsrv/postmaster configuration? For example, the Windows NT
Resource Kit always had a utility called 'srvany.exe', which one could
use to do what cygrunsrv is doing (making a non NT service act like
one), but they're basically 'wrappers' as it were. When one shuts down
Windows, Windows turns around and sends out kill signals to the running
apps/services, and in the case of srvany.exe or cygrunsrv, they must
then turn around and shutdown the apps under their control.

Is cygrunsrv replying to the Windows kill signal before postmaster has
fully shutdown? I honestly don't know. I know that if I manually do a
'net start postmaster' and 'net stop postmaster', PostgreSQL properly
creates and deletes the postmaster.pid file without incident. What does
it indicate if I do a simple Windows restart when the postmaster.pid
file is still there on reboot? And how can I be sure PostgreSQL has
properly shutdown (other than checking /var/log/postmaster.log...which
doesn't timestamp all its messages)?

Responses

Browse pgsql-cygwin by date

  From Date Subject
Next Message Frank Seesink 2003-05-23 16:58:49 Re: PostgreSQL 7.3.2 running as NT service under Windows XP not always
Previous Message Jason Tishler 2003-05-20 19:10:24 Re: Updated Cygwin Package: postgresql-7.3.2-2 --still