When I tried to connect to PostgreSQL as usual, I got this error.
FATAL: sorry, too many clients already
?? You shouldn't be apologized. It seems that the client has exceeded the DB settings ...
I doubt again here. That shouldn't be the case because I'm just using it for testing.
For the time being, check with select * from pg_stat_activity;
.
1234 datname.hoge 0000 postgres 000.000.0.000 2020/1/29 00:00 1234 datname.hoge 0000 postgres 000.000.0.000 2020/1/29 00:00 1234 datname.hoge 0000 postgres 000.000.0.000 2020/1/29 00:00 ... 100 cases below
Yeah ... I'm sorry I used it. This is like sorry.
As a cause. When making continuous DB connections with the Java program on the server side you are using
db.java
try {
Class.forName("org.postgresql.Driver");
conn = DriverManager.getConnection(DBURL, user, password);
Statement stmt = conn.createStatement();
String sql = "First SQL statement";
ResultSet rs = stmt.executeQuery(sql);
rs.close();
stmt.close();
}catch (SQLException e){
}catch (Exception e){
}
try {
Class.forName("org.postgresql.Driver");
conn = DriverManager.getConnection(DBURL, user, password);
Statement stmt = conn.createStatement();
String sql = "Second SQL statement";
ResultSet rs = stmt.executeQuery(sql);
rs.close();
stmt.close();
}catch (SQLException e){
}catch (Exception e){
}finally{
try{
if (conn != null){
conn.close();
}
}catch (SQLException e){
//Exception handling
}
}
I just closed it at the end, but I have to do it every time. It was a matter of course. It's too hot.
Recommended Posts