6

I am running Postgresql 9.4 as a service on Windows Server 2008 R2. It usually works as a charm, but now there is a situation when the server is apparently running (I can connect to it, Task Manager shows the running processes), but the Windows Service appears stopped.

I tried using pg_ctl, but I get:

$>pg_ctl restart -D c:\psqldata94
pg_ctl: old server process (PID: 1436) seems to be gone
starting server anyway
server starting
2016-02-23 09:59:00 CET  LOG:  could not bind IPv6 socket: No error
2016-02-23 09:59:00 CET  HINT:  Is another postmaster already running on port  5432? If not, wait a few seconds and retry.
2016-02-23 09:59:00 CET  LOG:  could not bind IPv4 socket: No error
2016-02-23 09:59:00 CET  HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2016-02-23 09:59:00 CET  WARNING:  could not create listen socket for "*"
2016-02-23 09:59:00 CET  FATAL:  could not create any TCP/IP sockets

$>pg_ctl stop
pg_ctl: PID file "c:/psqldata94/postmaster.pid" does not exist
Is server running?

I tried looking for help online, but the only thing I could find, was this ominous post at psql-admin mailing list.

It's exactly as the author of the post describes: the server is running, but it does not respond to commands. I suppose I can restart the underlying Windows server, but obviously this could have grave consequences if I just kill the running processes.

Does anybody know how to gracefully stop the server under this circumstances?

2
  • Are you sure you are connecting to the DB you think you are connecting to? Commented Feb 23, 2016 at 10:49
  • If the proccess is lost in the manchine you need to kill the proccess int the task manager. Or boot the manchine
    – Krismorte
    Commented Feb 23, 2016 at 11:39

2 Answers 2

3

For me, the answer lied in more careful reading of the excellent manual. Particularly the following three points:

The general discussion about server shutdown is here.

So what I did was to terminate all the backends that were visible through pg_stat_activity view by pg_terminate_backend and then logging onto the server and running pg_ctl kill TERM <pid> to the remaining running postgres processes.

1
  • Thanks. I tested this. first i tried by kill pid of postmaster and started again server. and check log after restart it was showing in automatic recovery taken. after, i tried killing server pid pg_ctl KILL TERM PID and then restarted server show in logs like db was shutdown only. that mean pg_ctl kill pid is best way to kill server instead of kill pid .
    – Adam Mulla
    Commented Aug 28, 2020 at 14:12
1

I have run into the same issue with Postgres 9.2.

My clean shutdown process is to stop all of the processes that are using Postgres (this includes several Windows services and IIS). Once all of the client applications have terminated, the postgres.exe processes typically go away on their own. Then delete postmaster.pid if it is there, restart the Postgres service, and restart the client processes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.