user3927415
user3927415

Reputation: 435

Too many connection to Postgresql in java

I use postgresql for DB and have a connection problem. The project is very big, with a lot of inner flows, and very complex... Sometimes, the app creates a lot of connections, and there are no connections left in the db, and the app freezes. The problem is not in the db, it is in the app.

When I look into pg_stat_activity, i see all the connections, and their query is select 1 (the first query that occures when connection is open, to validate the connection). So it seems that the app opens a connection, and does not use it. And when there are to many of those... you know...

I dont know where from, in the code, the connection open.

Is there a technic/tool for java/postgres to know where they come from?

From just looking at the code it will take forever.

Upvotes: 0

Views: 649

Answers (1)

pifor
pifor

Reputation: 7882

There is no feature in PostgreSQL to find something in the application source directly.

You could only try enable to more detailed logging on PostgreSQL side with the right log_line_prefix and log_statement parameter: this could only help if the statements are submitted from a specific executable or host (because related logged data could help finding the right code section).

If application starts a transaction that stays idle too long, you can set idle_in_transaction_session_timeout.

Unfortunately PostgreSQL has no timeout for idle sessions that are not running a transaction.

Upvotes: 1

Related Questions