BUG #13803: too many clients exception
BUG #13803: too many clients exception
От:
sebastian.sierra@netbeam.com.co
Дата:
The following bug has been logged on the website:
Bug reference: 13803
Logged by: Sebastian Sierra
Email address: sebastian.sierra@netbeam.com.co
PostgreSQL version: 9.4.0
Operating system: windows
Description:
hello, im using postgresql as my app database, but i find out it isn't
cleaning connections when i use conn.close() in java with jdbc, it clean
them but not instantly after i send this command, i find out using this
query select * from pg_stat_database; there you can see numbackends are not
closing, they stay almost 3 seconds, some times even more can you check if
it's your problem? this is the way im doing my querys List
devices = new ArrayList<>();
Connection con = null;
try {
con = getDatasource().getConnection();
PreparedStatement ps = con.prepareStatement(getDevices);
ps.setInt(1, company);
System.out.println(ps.toString());
ResultSet rs = ps.executeQuery();
while (rs.next()) {
DeviceDTO deviceDTO = new DeviceDTO();
Device device = new Device(rs.getString("device_serial"),
rs.getInt("state"), rs.getInt("device_sleep"),
rs.getString("objecttypedescription"), rs.getString("description"),
new ArrayList<>(),
new ArrayList<>());
/**
PreparedStatement ps2 = con.prepareStatement(getMeasures);
int i = 1;
ps2.setString(i, device.getSerial());
i++;
ps2.setInt(i, company);
i++;
ps2.setString(i, dateSince);
i++;
ps2.setString(i, dateUntil);
ResultSet rs2 = ps2.executeQuery();
while (rs2.next()) {
device.getMeasures()
.add(new MeasureDTO(rs.getInt("measure_id"),
rs.getString("measure_name") + " - " +
rs.getString("measure_unit"),
rs.getDouble("value"), rs.getString("date")));
}
ps2.close();
rs2.close();*/
deviceDTO.copyDevicePOJOtoDeviceDTO(device);
devices.add(deviceDTO);
}
rs.close();
ps.close();
} catch (SQLException e) {
System.out.println("DeviceImpl sql exception on getCompanyDevices: " +
e.getMessage());
}finally {
if (null != con ) {
try {
con.close();
} catch (SQLException e) {
System.out.println(e.getMessage());
}
}
}
return devices;
}Re: BUG #13803: too many clients exception
От:
Kevin Grittner <kgrittn@gmail.com>
Дата:
On Mon, Dec 7, 2015 at 9:29 AM, wrote: > PostgreSQL version: 9.4.0 There are bugs in 9.4.0 which can cause it to run with no apparent problem for a long time, then suddenly lose data and leave a corrupted, and possibly unusable database. It is irresponsible not to apply the latest bug fixes by applying the latest 9.4 minor release. http://www.postgresql.org/support/versioning/ > ps2.close(); > rs2.close();*/ You really haven't given enough information to be sure what your problem is (for example, how you are measuring this delay), but it might be the statement close before the result set close. That results in the JDBC driver canceling the pending query on the connection by making a separate connection and signaling the first to cancel what it is running. To avoid race conditions which might cancel some subsequent statement on the first connection, it has to wait for this all to complete. Always close the ResultSet object before closing the Statement object which generated the ResultSet. -- Kevin Grittner EDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company