Thread: how to terminate a process when kill fails

how to terminate a process when kill fails

From
"Johnson, Shaunn"
Date:

Running PostgreSQL 7.2.1 on RedHat Linux 7.2.

I think I may have asked before, but I never got an answer
that told me one way or another -

How can I kill processes without kill -9 <pid> and
ruining the database?

I've tried restarting postgreSQL hoping that it cleans up
a few things.  I've tried to simply kill the processes that
were running.  Nothing happens; nothing dies.  I don't see
much of anything in the messages / log files. 

Any suggestions?

-X

Re: how to terminate a process when kill fails

From
"Shridhar Daithankar"
Date:
On 30 Oct 2002 at 10:14, Johnson, Shaunn wrote:

>
> Running PostgreSQL 7.2.1 on RedHat Linux 7.2.
> I think I may have asked before, but I never got an answer
> that told me one way or another -
> How can I kill processes without kill -9 <pid> and
> ruining the database?

Just kill pid works. After that you should see postgresql shutdown subprocess
in ps listing. After all clients are done, it shuts down.

Postmaster man page lists signal and behaviour of postmaster. That should be
helpful.

HTH

Bye
 Shridhar

--
A man either lives life as it happens to him, meets it head-on andlicks it, or
he turns his back on it and starts to wither away.        -- Dr. Boyce, "The
Menagerie" ("The Cage"), stardate unknown


Re: how to terminate a process when kill fails

From
Mike Mascari
Date:
Johnson, Shaunn wrote:
 >
> Running PostgreSQL 7.2.1 on RedHat Linux 7.2.
>
> I think I may have asked before, but I never got an answer
> that told me one way or another -
>
> How can I kill processes without kill -9 <pid> and
> ruining the database?
>
> I've tried restarting postgreSQL hoping that it cleans up
> a few things.  I've tried to simply kill the processes that
> were running.  Nothing happens; nothing dies.  I don't see
> much of anything in the messages / log files.
>
> Any suggestions?

Use kill -9. Do a:

killall -9 postgres
killall -9 postmaster

The tip message

'Don't kill -9 the postmaster'

is old and was added when havoc could be caused by an old
postgres backend process. Consider the scenrio:

1. postmaster started
2. postgres started  (Session #1)
3. postmaster killed (-9)
4. postmaster restarted
5. postgres started (Session #2)

Now there isn't any synchronization between Sesison #1 and
Session #2 at all, which would lead to data corruption. This
scenario was fixed a long time ago (7.1?). The whole 'Don't kill
-9 the postmaster' comment was actually a tongue-in-cheek remark
by me regarding a parallel discussion of RedHat init scripts.
The corruption possibility has long-since been fixed. Since I've
seen FUD claiming PostgreSQL doesn't have sufficient
crash-recovery because of the tip, I suggest the tip be changed to:

'Feel free to kill -9 the postmaster'

Mike Mascari
mascarm@mascari.com


Re: how to terminate a process when kill fails

From
Medi Montaseri
Date:
How about

pg_ctl stop -m smart            # smart = wait for all clients to disconnect
pg_ctl stop -m fast               # fast = don't bother waiting,
rollback all transactions
pg_ctl stop -m immediate      # immediate = abort all server processes

See pg_ctl(1)

ohnson, Shaunn wrote:

> Running PostgreSQL 7.2.1 on RedHat Linux 7.2.
>
> I think I may have asked before, but I never got an answer
> that told me one way or another -
>
> How can I kill processes without kill -9 <pid> and
> ruining the database?
>
> I've tried restarting postgreSQL hoping that it cleans up
> a few things.  I've tried to simply kill the processes that
> were running.  Nothing happens; nothing dies.  I don't see
> much of anything in the messages / log files.
>
> Any suggestions?
>
> -X
>




Re: how to terminate a process when kill fails

From
Tom Lane
Date:
Mike Mascari <mascarm@mascari.com> writes:
> This scenario was fixed a long time ago (7.1?). The whole 'Don't kill
> -9 the postmaster' comment was actually a tongue-in-cheek remark
> by me regarding a parallel discussion of RedHat init scripts.
> The corruption possibility has long-since been fixed. Since I've
> seen FUD claiming PostgreSQL doesn't have sufficient
> crash-recovery because of the tip, I suggest the tip be changed to:
> 'Feel free to kill -9 the postmaster'

Yes, that TIP is very long obsolete.   However, kill -9 is still not
the *preferred* way to shut down the postmaster ;-).  You don't get
a checkpoint, and in some cases the shared memory block may not get
recycled when you try to restart the postmaster, leading to serious
memory wastage.

I'd suggest we just remove that TIP from the set of possible messages...

            regards, tom lane

Re: how to terminate a process when kill fails

From
Bruce Momjian
Date:
Woh, the prohibition to using kill -9 is still valid.  I can think of no
reason to use -9 unless something is broken in our code or in the OS.

pg_ctl code has:

    case "$shutdown_mode" in
        s|smart)
            sig="-TERM"
            ;;
        f|fast)
            sig="-INT"
            ;;
        i|immediate)
            sig="-QUIT"
            ;;
and the 7.3 postgres manual page has:

   To stop a running query use the SIGINT signal. To
   tell postgres to reread the config file,
   use a SIGHUP signal. The postmaster uses SIGTERM
   to tell a postgres process to quit normally and
   SIGQUIT to terminate without the normal cleanup.
   These should not be used by users.


---------------------------------------------------------------------------

Mike Mascari wrote:
> Johnson, Shaunn wrote:
>  >
> > Running PostgreSQL 7.2.1 on RedHat Linux 7.2.
> >
> > I think I may have asked before, but I never got an answer
> > that told me one way or another -
> >
> > How can I kill processes without kill -9 <pid> and
> > ruining the database?
> >
> > I've tried restarting postgreSQL hoping that it cleans up
> > a few things.  I've tried to simply kill the processes that
> > were running.  Nothing happens; nothing dies.  I don't see
> > much of anything in the messages / log files.
> >
> > Any suggestions?
>
> Use kill -9. Do a:
>
> killall -9 postgres
> killall -9 postmaster
>
> The tip message
>
> 'Don't kill -9 the postmaster'
>
> is old and was added when havoc could be caused by an old
> postgres backend process. Consider the scenrio:
>
> 1. postmaster started
> 2. postgres started  (Session #1)
> 3. postmaster killed (-9)
> 4. postmaster restarted
> 5. postgres started (Session #2)
>
> Now there isn't any synchronization between Sesison #1 and
> Session #2 at all, which would lead to data corruption. This
> scenario was fixed a long time ago (7.1?). The whole 'Don't kill
> -9 the postmaster' comment was actually a tongue-in-cheek remark
> by me regarding a parallel discussion of RedHat init scripts.
> The corruption possibility has long-since been fixed. Since I've
> seen FUD claiming PostgreSQL doesn't have sufficient
> crash-recovery because of the tip, I suggest the tip be changed to:
>
> 'Feel free to kill -9 the postmaster'
>
> Mike Mascari
> mascarm@mascari.com
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html
>

--
  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

Re: how to terminate a process when kill fails

From
Mike Mascari
Date:
Bruce Momjian wrote:
> Woh, the prohibition to using kill -9 is still valid.  I can think of no
> reason to use -9 unless something is broken in our code or in the OS.
>
> pg_ctl code has:
>
>     case "$shutdown_mode" in
>         s|smart)
>             sig="-TERM"
>             ;;
>         f|fast)
>             sig="-INT"
>             ;;
>         i|immediate)
>             sig="-QUIT"
>             ;;
> and the 7.3 postgres manual page has:
>
>    To stop a running query use the SIGINT signal. To
>    tell postgres to reread the config file,
>    use a SIGHUP signal. The postmaster uses SIGTERM
>    to tell a postgres process to quit normally and
>    SIGQUIT to terminate without the normal cleanup.
>    These should not be used by users.

I confess it might have been over-kill to suggest 'Feel free to
kill -9 the postmaster'. However, I have seen FUD stating that
PostgreSQL cannot recover from crashes because of the TIP. It
seemed that Shaunn (quite naturally) came to the same conclusion:

 >>>How can I kill processes without kill -9 <pid> and
 >>>ruining the database?
    ^^^^^^^^^^^^^^^^^^^^

Also, Shaunn seemed to suggest that the postmaster and postgres
processes were not responding to typical signals..at least
SIGINT and SIGTERM:

>>>I've tried restarting postgreSQL hoping that it cleans up
>>>a few things.  I've tried to simply kill the processes that
>>>were running.  Nothing happens; nothing dies.  I don't see
>>>much of anything in the messages / log files.

If Shaunn initially tried init scripts like those shipped with
Lamar's RPM, they do a fast shutdown - SIGINT. With those
signals ignored, Shaunn tried a (presumably) SIGTERM, which also
failed to shutdown the postmaster and postgres processes. I
should have first suggested that Shaunn also try SIGQUIT. But my
main point was that 'kill -9 <pid> does *not* corrupt the
database and neither would immediate power loss, for that
matter. And that Marc should consider changing the TIP. Of
course, removing the TIP altogether as Tom later suggested,
would seem to be the best course of action...

Mike Mascari
mascarm@mascari.com