Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to close the all ports opened by postgres?

I am using PostgreSQL database in the JSP website.

Somewhere my connection is not closed in code. So port was opened by the PostgreSQL was remained in ESTABLISHED situation and remained in that state only.

After sometime number of ports exceeds the limit of PostgreSQL total limit and than I have to manually restart the PostgreSQL from Linux by,

service PostgreSQL restart

Is there any way to delete all the ports opened by PostgreSQL through JAVA file?

like image 660
Dinesh Dabhi Avatar asked Dec 06 '25 14:12

Dinesh Dabhi


2 Answers

Take a 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 the unclosed connections in your code as you are likely to run into memory issues and other strangeness.

like image 86
jcern Avatar answered Dec 08 '25 02:12

jcern


I strongly recommend fixing the connection leak in your code.

like image 30
Tim Lamballais Avatar answered Dec 08 '25 04:12

Tim Lamballais



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!