You might see the following when issuing the normal stop command to postgres via pg_ctl.

-bash-3.1$ pg_ctl stop
waiting for server to shut down……………………………………………………… failed
pg_ctl: server does not shut down

Sometimes postgres does not want to shutdown by just issuing a pg_ctl stop as the postgres user. User might feel the need to “kill -9″ the postgres processes however this could be dangerous for PostgreSQL. Instead of trying to kill the PID follow the directions below in an attempt to stop postgres in an organized fashion.

  1. Attempt Normal Stop: bash-3.1$pg_ctl stop
  2. Attempt Smart Stop: bash-3.1$pg_ctl stop -m s
  3. Attempt Fast Stop: bash-3.1$pg_ctl stop -m f
  4. Attempt Immediate Stop: bash-3.1$pg_ctl stop -m i

The immediate stop almost always ends up stopping postgres if you are having trouble in stopping the processes. If the immediate stop does not work the issue should be investigated before attempting to kill -9 the PID.

SQL in a Nutshell (In a Nutshell (O'Reilly)) (Paperback)

By (author): Kevin Kline, Brand Hunt, Daniel Kline

List Price: $44.99 USD
New From: $24.99 USD In Stock
Used from: $16.91 USD In Stock

SQL Cookbook (Cookbooks (O'Reilly)) (Paperback)

By (author): Anthony Molinaro

List Price: $39.95 USD
New From: $21.26 USD In Stock
Used from: $14.99 USD In Stock

Tags: , , , , ,
6 Responses to “pg_ctl: Server Does Not Shut Down – Force Postgres to Shutdown”
  1. Joe User says:

    This is quite a good info. I’ll share it on Delicious.


    alex Reply:

    Thanks for the feedback.


  2. Ahmed says:

    I’ve been looking for this for a while. Thanks!
    Any ideas why postgres refuses to stop when it has no connections in transaction?!


  3. John Dunlap says:

    >> Attempt Immediate Stop: bash-3.1$pg_ctl -m i
    Should be,

    Attempt Immediate Stop: bash-3.1$pg_ctl stop -m i


    alex Reply:

    Oops!… Thanks John. I have corrected above as well..


Leave a Reply

*Type the letter/number combination in the abvoe field before clicking submit.