BUG #13803: too many clients exception - Mailing list pgsql-bugs

From sebastian.sierra@netbeam.com.co
Subject BUG #13803: too many clients exception
Date
Msg-id 20151207152928.2629.79886@wrigleys.postgresql.org
Whole thread Raw
Responses Re: BUG #13803: too many clients exception  (Kevin Grittner <kgrittn@gmail.com>)
List pgsql-bugs
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<DeviceDTO>
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;
    }

pgsql-bugs by date:

Previous
From: Terje Elde
Date:
Subject: Re: BUG #13805: plpgsql execute using expression evaluate wrong
Next
From: pplachta@gmail.com
Date:
Subject: BUG #13796: ALTER TYPE DROP COLUMN -- unexpected behavior ?