Re: PostgreSQL 7.3.2 running as NT service under Windows XP

From: Frank Seesink <frank(at)mail(dot)wvnet(dot)edu>
To: pgsql-cygwin(at)postgresql(dot)org
Subject: Re: PostgreSQL 7.3.2 running as NT service under Windows XP
Date: 2003-05-28 22:26:59
Message-ID: bb3d00$vff$1@main.gmane.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-cygwin

Jason Tishler wrote:
...
>>Now the big $64K question: Why? :-)
>
>
> Looking at the following Cygwin DLL code:
>
> static BOOL WINAPI
> ctrl_c_handler (DWORD type)
> {
> if (type == CTRL_LOGOFF_EVENT)
> return TRUE;
>
> /* Return FALSE to prevent an "End task" dialog box from appearing
> for each Cygwin process window that's open when the computer
> is shut down or console window is closed. */
> ***>if (type == CTRL_SHUTDOWN_EVENT)
> ***> {
> ***> sig_send (NULL, SIGTERM);
> ***> return FALSE;
> ***> }
> if (type == CTRL_CLOSE_EVENT)
> {
> sig_send (NULL, SIGHUP);
> return FALSE;
> }
> ...
> }
>
> I'm concerned that the Cygwin DLL is actually sending a SIGTERM to the
> postmaster even though cygrunsrv is going to send a SIGINT too. Does
> the postmaster log indicate a "smart shutdown" or "fast shutdown" when
> the pid file is not deleted?

I did the following:

* PostgreSQL was running
* I deleted /var/log/postmaster.log
* manually shutdown/restarted PostgreSQL using 'net stop postmaster' and
'net start postmaster' to generate the first few entries
* then rebooted.

The following is the contents of /var/log/postmaster.log:
____________________________________________________________
LOG: database system was shut down at 2003-05-28 16:14:19 EDT
LOG: checkpoint record is at 0/C782D8
LOG: redo record is at 0/C782D8; undo record is at 0/0; shutdown TRUE
LOG: next transaction id: 9882; next oid: 20212
LOG: database system is ready
LOG: smart shutdown request
LOG: shutting down
LOG: fast shutdown request
LOG: database system is shut down
LOG: database system was shut down at 2003-05-28 17:57:51 EDT
LOG: checkpoint record is at 0/C78318
LOG: redo record is at 0/C78318; undo record is at 0/0; shutdown TRUE
LOG: next transaction id: 9882; next oid: 20212
LOG: database system is ready
____________________________________________________________

From the above, it appears that PostgreSQL first receives a "smart
shutdown request", followed by a "fast shutdown request". Are we
getting closer? :-)

>>>Why not wrap postmaster in a shell script,
>>>/usr/local/bin/postmaster.sh?
>>>
>>> #!/bin/sh
>>> rm -f /usr/share/postgresql/data/postmaster.pid
>>> /usr/bin/postmaster $*
>>>
>>>And then install postmaster.sh as the "service".
>>
>>Uh...I think this would fall under the category of "BAD Idea",
>>wouldn't it? I mean, the whole point of postmaster.pid is to prevent
>>MULTIPLE copies of postmaster from firing up against the same data
>>set. All I want to do is make sure no such file exists on startup,
>>and ONLY on startup. The above defeats the purpose by deleting it
>>regardless.
>
>
> I would call the above "quick and dirty". I wasn't clear but I assumed
> the following:
>
> 1. It would only be invoked via net start which will prevent
> multiple instances.

Actually, I understand what you mean, but technically, no this is not
true. If I do a 'net start postmaster' from the command line when a
copy is already running, this script will delete postmaster.pid and fire
up a 2nd copy.

> 2. The script was a starting point *not* the the final version.
> One could add something like the following check:
>
> pg_ctl -D /usr/share/postgresql/data status
> if [ $? -eq 0 ]
> then
> exit 1
> fi
> ...

This would help.

>>>I can only recommend checking the log file. Even without the
>>>timestamps, you should be able to figure out if PostgreSQL shut and
>>>started up cleanly. You can always start with a fresh log file to
>>>facilitate the analysis.
>>
>>I've done that. Still not much use. PostgreSQL isn't very verbose in
>>its logging.
>
>
> Did you add "-d 5" to the postmaster options? Maybe this will give you
> a better idea of how far postmaster is getting in its shutdown process.
> Another option is the hack postmaster to log with timestamps...

I'll try the "-d 5" when I get the chance. As for the option to "hack
postmaster", I don't feel comfortable enough with the code to go that
route. That requires recompiling from source, getting into a whole mess
of things that, though I wish I could, I really don't have time to do.
My FireDaemon hack isn't great, but it's working just fine for me as a
"spit & nails" patch.

I just wanted to determine if PostgreSQL was shutting down ok (which
your comments above and the log seem to indicate may or may not be the
case as it's getting 2 termination signals...so who wins?), and also to
make sure those new to PostgreSQL under Cygwin are aware of the
limitations of the environment (in this case, more so in Windows than
anything). I guess some could argue that maybe there should be some
kind of Cygwin NT service that all other Cygwin packages that run as NT
services should depend on, where that Cygwin service made sure all the
/etc/rc.d init scripts were run prior to things like PostgreSQL firing
up, giving a "truer" Unix experience. But this is beyond the scope of
where this all started, and may require discussion on a different
mailing list. I'm in deeper here than I intended.

In response to

Responses

Browse pgsql-cygwin by date

  From Date Subject
Next Message Jason Tishler 2003-05-29 15:01:40 Re: PostgreSQL 7.3.2 running as NT service under Windows XP
Previous Message Jason Tishler 2003-05-28 16:21:59 Re: PostgreSQL 7.3.2 running as NT service under Windows XP