I double checked my code and I have conn.close in the finally block but when I do SELECT * FROM pg_stat_activity; I see many idle connections. How can I fix this?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The most likely cause of this is that your application is using a connection pool. If so, the pool will grab connections and keep a portion of them open so that they can be reused. The connections will show as IDLE until another command is executed or the application is shut down.
If the connection was simply not being closed you would probably see something like IDLE – In Transaction which means that the connection is open and waiting for a commit or rollback to be executed, but not receiving any commands.
Also, I know you say you close the connections so i am not sure if this applies to you, but I just wanted to throw out that I have also experienced problems in the past by not explicitly closing PreparedStatements.