I am having a scenario where we close the postgres connection unexpectedly that is the jetty server which is using the connection pool. So in our scenario we are killing the jetty server issuing Kill -9 so connection pool is not closed properly , so my question is that will it going to affect the postgres database, can it cause the postgres corruption. Or all the Connections will be closed automatically and the running transactions will be rolled back without affecting the database.
1 Answer
Any transaction that is not committed, will cause an implicit rollback when you disconnect. This will never result in a corrupt database, a rollback never results in a corrupt database.
Using kill -9 is asking for problems, but it won't corrupt your database when you just kill the connection.
4 Comments
Abhishek Parikh
But what will happen to connection at the Postgres side when my application is getting killed, will they remain open at the postgres side ?
Frank Heikens
No, the process will be stopped. Just do a test and see it happen.
Abhishek Parikh
Frank how can i Check it on the postgres side whether the Connection is still open ?
Frank Heikens
Check pg_stat_activity: SELECT * FROM pg_stat_activity;
kill -KILL?