How do I close all ports open by postgres?… here is a solution to the problem.
How do I close all ports open by postgres?
I use a PostgreSQL database in my JSP website.
My connection is somewhere not closed in code. So the port opened by PostgreSQL has always been in the ESTABLISHED state, only staying in that state.
After some time, the number of ports exceeded the total limit of PostgreSQL and I had to manually restart PostgreSQL from Linux
service PostgreSQL restart
Is there a way to remove all ports open by PostgreSQL via Java file?
Solution
Look at the pg_cancel_backend() function: http://www.postgresql.org/docs/8.2/static/functions-admin.html
However, you
should consider trying to fix connections that are not closed in your code, as you may experience memory issues and other exceptions.