pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Statement is still active at the back-end even after closing
5+ messages / 3 participants
[nested] [flat]

* Statement is still active at the back-end even after closing
@ 2017-08-31 08:50 Syam Pillai <syam@engravgroup.com>
  2017-08-31 13:09 ` Re: Statement is still active at the back-end even after closing Dave Cramer <pg@fastcrypt.com>
  2017-08-31 16:48 ` Re: Statement is still active at the back-end even after closing David G. Johnston <david.g.johnston@gmail.com>
  0 siblings, 2 replies; 5+ messages in thread

From: Syam Pillai @ 2017-08-31 08:50 UTC (permalink / raw)
  To: pgsql-jdbc

​Not sure if this was reported earlier.

I am using PostgreSQL 9.5.8 and JDBC driver 42.1.4

If I execute the following statements and at Position #1, if I check the
pg_stat_activity from another connection (let's say from the psql
application), I can see that the 'Statement s' is still active:

try {
Class.forName("org.postgresql.Driver");
Connection connection = null;
connection =
DriverManager.getConnection("jdbc:postgresql://localhost:5432/cadup","user",
"password");
Statement s = connection.createStatement();
ResultSet rs =s.executeQuery("SELECT 1 FROM core.Person");
if(rs.next()) {
System.err.println("Yes, we got a row!");
} else {
System.err.println("No rows found");
}
s.close();
Thread.sleep(10000); // Position #1
connection.close();
} catch(Exception e) {
e.printStackTrace();
}


===============
Query executed to check the activity:
SELECT pid, datname, now() - pg_stat_activity.query_start AS duration,
state, query
FROM pg_stat_activity
WHERE now() - pg_stat_activity.query_start > interval '1 second';
Output from psql:
  pid  | datname |    duration     | state |           query
-------+---------+-----------------+-------+---------------------------
 17775 | xxxx   | 00:00:07.481294 | idle  | SELECT 1 FROM core.Person

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Statement is still active at the back-end even after closing
  2017-08-31 08:50 Statement is still active at the back-end even after closing Syam Pillai <syam@engravgroup.com>
@ 2017-08-31 13:09 ` Dave Cramer <pg@fastcrypt.com>
  2017-08-31 16:05   ` Re: Statement is still active at the back-end even after closing Syam Pillai <syam@engravgroup.com>
  1 sibling, 1 reply; 5+ messages in thread

From: Dave Cramer @ 2017-08-31 13:09 UTC (permalink / raw)
  To: Syam Pillai <syam@engravgroup.com>; +Cc: pgsql-jdbc

Seems pretty normal to me ? You have a sleep in there which is keeping it
alive. what happens if you check it after the close ?

Dave Cramer

davec@postgresintl.com
www.postgresintl.com

On 31 August 2017 at 04:50, Syam Pillai <syam@engravgroup.com> wrote:

> ​Not sure if this was reported earlier.
>
> I am using PostgreSQL 9.5.8 and JDBC driver 42.1.4
>
> If I execute the following statements and at Position #1, if I check the
> pg_stat_activity from another connection (let's say from the psql
> application), I can see that the 'Statement s' is still active:
>
> try {
> Class.forName("org.postgresql.Driver");
> Connection connection = null;
> connection = DriverManager.getConnection("jdbc:postgresql://localhost:5432/cadup","user",
> "password");
> Statement s = connection.createStatement();
> ResultSet rs =s.executeQuery("SELECT 1 FROM core.Person");
> if(rs.next()) {
> System.err.println("Yes, we got a row!");
> } else {
> System.err.println("No rows found");
> }
> s.close();
> Thread.sleep(10000); // Position #1
> connection.close();
> } catch(Exception e) {
> e.printStackTrace();
> }
>
>
> ===============
> Query executed to check the activity:
> SELECT pid, datname, now() - pg_stat_activity.query_start AS duration,
> state, query
> FROM pg_stat_activity
> WHERE now() - pg_stat_activity.query_start > interval '1 second';
> Output from psql:
>   pid  | datname |    duration     | state |           query
> -------+---------+-----------------+-------+---------------------------
>  17775 | xxxx   | 00:00:07.481294 | idle  | SELECT 1 FROM core.Person
>
>

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Statement is still active at the back-end even after closing
  2017-08-31 08:50 Statement is still active at the back-end even after closing Syam Pillai <syam@engravgroup.com>
  2017-08-31 13:09 ` Re: Statement is still active at the back-end even after closing Dave Cramer <pg@fastcrypt.com>
@ 2017-08-31 16:05   ` Syam Pillai <syam@engravgroup.com>
  2017-08-31 16:40     ` Re: Statement is still active at the back-end even after closing Dave Cramer <pg@fastcrypt.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Syam Pillai @ 2017-08-31 16:05 UTC (permalink / raw)
  To: Dave Cramer <pg@fastcrypt.com>; +Cc: pgsql-jdbc

Just before the sleep, I already closed the Statement. Connection is not
closed because I want to use the connection for executing further
Statements.

On Thu, Aug 31, 2017 at 5:09 PM, Dave Cramer <pg@fastcrypt.com> wrote:

> Seems pretty normal to me ? You have a sleep in there which is keeping it
> alive. what happens if you check it after the close ?
>
> Dave Cramer
>
> davec@postgresintl.com
> www.postgresintl.com
>
> On 31 August 2017 at 04:50, Syam Pillai <syam@engravgroup.com> wrote:
>
>> ​Not sure if this was reported earlier.
>>
>> I am using PostgreSQL 9.5.8 and JDBC driver 42.1.4
>>
>> If I execute the following statements and at Position #1, if I check the
>> pg_stat_activity from another connection (let's say from the psql
>> application), I can see that the 'Statement s' is still active:
>>
>> try {
>> Class.forName("org.postgresql.Driver");
>> Connection connection = null;
>> connection = DriverManager.getConnection("jdbc:postgresql://localhost:5432/cadup","user",
>> "password");
>> Statement s = connection.createStatement();
>> ResultSet rs =s.executeQuery("SELECT 1 FROM core.Person");
>> if(rs.next()) {
>> System.err.println("Yes, we got a row!");
>> } else {
>> System.err.println("No rows found");
>> }
>> s.close();
>> Thread.sleep(10000); // Position #1
>> connection.close();
>> } catch(Exception e) {
>> e.printStackTrace();
>> }
>>
>>
>> ===============
>> Query executed to check the activity:
>> SELECT pid, datname, now() - pg_stat_activity.query_start AS duration,
>> state, query
>> FROM pg_stat_activity
>> WHERE now() - pg_stat_activity.query_start > interval '1 second';
>> Output from psql:
>>   pid  | datname |    duration     | state |           query
>> -------+---------+-----------------+-------+---------------------------
>>  17775 | xxxx   | 00:00:07.481294 | idle  | SELECT 1 FROM core.Person
>>
>>
>


-- 
*Syam S. Pillai, **Director & Chief Technology Officer*
*ENGRAV Aviation Services & Systems Pvt. Ltd.*
*# 15, Level 1, Indradhanush,  Gubbi Cross,*
*Kothannur PO, Bangalore - 560 077, India.*
*Phone: +91 80 2844 3740*
*http://www.engravgroup.com <https://www.engravgroup.com>*

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Statement is still active at the back-end even after closing
  2017-08-31 08:50 Statement is still active at the back-end even after closing Syam Pillai <syam@engravgroup.com>
  2017-08-31 13:09 ` Re: Statement is still active at the back-end even after closing Dave Cramer <pg@fastcrypt.com>
  2017-08-31 16:05   ` Re: Statement is still active at the back-end even after closing Syam Pillai <syam@engravgroup.com>
@ 2017-08-31 16:40     ` Dave Cramer <pg@fastcrypt.com>
  0 siblings, 0 replies; 5+ messages in thread

From: Dave Cramer @ 2017-08-31 16:40 UTC (permalink / raw)
  To: Syam Pillai <syam@engravgroup.com>; +Cc: pgsql-jdbc

So this is perfectly normal. Closing the statement only closes resources on
the driver side there is no interaction with the server.

Dave Cramer

davec@postgresintl.com
www.postgresintl.com

On 31 August 2017 at 12:05, Syam Pillai <syam@engravgroup.com> wrote:

> Just before the sleep, I already closed the Statement. Connection is not
> closed because I want to use the connection for executing further
> Statements.
>
> On Thu, Aug 31, 2017 at 5:09 PM, Dave Cramer <pg@fastcrypt.com> wrote:
>
>> Seems pretty normal to me ? You have a sleep in there which is keeping it
>> alive. what happens if you check it after the close ?
>>
>> Dave Cramer
>>
>> davec@postgresintl.com
>> www.postgresintl.com
>>
>> On 31 August 2017 at 04:50, Syam Pillai <syam@engravgroup.com> wrote:
>>
>>> ​Not sure if this was reported earlier.
>>>
>>> I am using PostgreSQL 9.5.8 and JDBC driver 42.1.4
>>>
>>> If I execute the following statements and at Position #1, if I check the
>>> pg_stat_activity from another connection (let's say from the psql
>>> application), I can see that the 'Statement s' is still active:
>>>
>>> try {
>>> Class.forName("org.postgresql.Driver");
>>> Connection connection = null;
>>> connection = DriverManager.getConnection("j
>>> dbc:postgresql://localhost:5432/cadup","user", "password");
>>> Statement s = connection.createStatement();
>>> ResultSet rs =s.executeQuery("SELECT 1 FROM core.Person");
>>> if(rs.next()) {
>>> System.err.println("Yes, we got a row!");
>>> } else {
>>> System.err.println("No rows found");
>>> }
>>> s.close();
>>> Thread.sleep(10000); // Position #1
>>> connection.close();
>>> } catch(Exception e) {
>>> e.printStackTrace();
>>> }
>>>
>>>
>>> ===============
>>> Query executed to check the activity:
>>> SELECT pid, datname, now() - pg_stat_activity.query_start AS duration,
>>> state, query
>>> FROM pg_stat_activity
>>> WHERE now() - pg_stat_activity.query_start > interval '1 second';
>>> Output from psql:
>>>   pid  | datname |    duration     | state |           query
>>> -------+---------+-----------------+-------+---------------------------
>>>  17775 | xxxx   | 00:00:07.481294 | idle  | SELECT 1 FROM core.Person
>>>
>>>
>>
>
>
> --
> *Syam S. Pillai, **Director & Chief Technology Officer*
> *ENGRAV Aviation Services & Systems Pvt. Ltd.*
> *# 15, Level 1, Indradhanush,  Gubbi Cross,*
> *Kothannur PO, Bangalore - 560 077, India.*
> *Phone: +91 80 2844 3740 <+91%2080%202844%203740>*
> *http://www.engravgroup.com <https://www.engravgroup.com>*
>
>

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Statement is still active at the back-end even after closing
  2017-08-31 08:50 Statement is still active at the back-end even after closing Syam Pillai <syam@engravgroup.com>
@ 2017-08-31 16:48 ` David G. Johnston <david.g.johnston@gmail.com>
  1 sibling, 0 replies; 5+ messages in thread

From: David G. Johnston @ 2017-08-31 16:48 UTC (permalink / raw)
  To: Syam Pillai <syam@engravgroup.com>; +Cc: pgsql-jdbc

On Thu, Aug 31, 2017 at 1:50 AM, Syam Pillai <syam@engravgroup.com> wrote:

> ​
> Query executed to check the activity:
> SELECT pid, datname, now() - pg_stat_activity.query_start AS duration,
> state, query
> FROM pg_stat_activity
> WHERE now() - pg_stat_activity.query_start > interval '1 second';
> Output from psql:
>   pid  | datname |    duration     | state |           query
> -------+---------+-----------------+-------+---------------------------
>  17775 | xxxx   | 00:00:07.481294 | idle  | SELECT 1 FROM core.Person
>
>
​state = "idle" which means that they query column is showing the last
executed query - not something that is presently running.

David J.
​

^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2017-08-31 16:48 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-08-31 08:50 Statement is still active at the back-end even after closing Syam Pillai <syam@engravgroup.com>
2017-08-31 13:09 ` Dave Cramer <pg@fastcrypt.com>
2017-08-31 16:05   ` Syam Pillai <syam@engravgroup.com>
2017-08-31 16:40     ` Dave Cramer <pg@fastcrypt.com>
2017-08-31 16:48 ` David G. Johnston <david.g.johnston@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox