In Windows, when I stop tomcat, the application will release the hold on database, since the application will stop with tomcat… But in Ubuntu, even if I stop the tomcat application, it’s not releasing access to database.
I tried with
sudo /etc/init.d/tomcat6 stop
sudo service tomcat6 stop
I can’t use pkill, because if I kill the process, even the connection to database server gets released. I need to start it manually. I only want to release access to the database from application. How can I do it?
Is there anywhere tomcat is holding the application? Or any other process there which is on hold?
What creates the difference between Windows and Ubuntu?
If you stop tomcat by abruptly killing it, rather than stopping it in a way that allows a graceful shutdown, it will not be able to send the network packets to tell PostgreSQL that the connection is closed. If PostgreSQL is listening for the next tomcat request, it will wait for a very long time, never having any clue that tomcat is dead.
TCP has a configurable feature called “keepalives” which causes a listener to send a packet periodically when the connection is idle, to test whether the connection is still good. See the connection configuration settings that start with “tcp_keepalives_”. I suggest you try something like:
This will allow PostgreSQL to detect the broken connection in a little over a minute, without causing very much overhead. This will tell PostgreSQL to wait for 60 seconds on an idle connection before sending extra packets to test whether the connection is still good, and send retries one second apart. (I think it tries nine times.) If none of the packets are answered, PostgreSQL will close the connection and the process will gracefully go away.