Reputation: 8965
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?
Upvotes: 1
Views: 4364
Reputation: 7848
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.
Upvotes: 4