Re: Locking

Lists: pgsql-jdbc
From: "Sacauskis, Mike" <Mike(dot)Sacauskis(at)gdit(dot)com>
To: <pgsql-jdbc(at)postgresql(dot)org>
Subject: Locking
Date: 2008-04-19 00:09:14
Message-ID: 0F35BAEA672CA340974082D0348491E603954717@HQ-EXVS03.anteon.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc

I'm running into a problem where an "AccessShareLock" is not being
released after a select statement unless a connection is closed. This
is leading me to a deadlock issue with deletes. I'm using JDBC to
interact with the database. I'm using postgresQL 8.0. I was under
the impression that resources (does this include locks) are released
when the prepared statement is closed. The code snippet looks like the
following (though it does more prosessing then in this example. Is
there something that I'm missing to release the locks?

String sql = "select * from testtable";

PreparedStatement prest = con.prepareStatement(sql);

ResultSet rs = prest.executeQuery();

rs.next();

rs.close();

prest.close();

con.close();


From: "Jan de Visser" <jdevisser(at)digitalfairway(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Locking
Date: 2008-04-19 00:34:44
Message-ID: 1159c1e90804181734u61dc442cie41eaf38fcc8a20b@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc

Doh. Forgot to copy list.

On Fri, Apr 18, 2008 at 8:33 PM, Jan de Visser <jdevisser(at)commsolv(dot)com> wrote:
> On Fri, Apr 18, 2008 at 8:09 PM, Sacauskis, Mike
> <Mike(dot)Sacauskis(at)gdit(dot)com> wrote:
> >
> > I'm running into a problem where an "AccessShareLock" is not being released
> > after a select statement unless a connection is closed. This is leading me
> > to a deadlock issue with deletes. I'm using JDBC to interact with the
> > database. I'm using postgresQL 8.0. I was under the impression that
> > resources (does this include locks) are released when the prepared statement
> > is closed. The code snippet looks like the following (though it does more
> > prosessing then in this example. Is there something that I'm missing to
> > release the locks?
>
> Locks get released when the transaction which holds them commits/rolls back.
>
> I assume you are running with autocommit off. If you want your locks
> to be relinquished, you need to call con.commit() at the time you want
> them relinquished.
>
> Or you can just turn autocommit on. In that case you get more or less
> the behaviour you expected, since every statement will run in its own
> transaction which commits on completion of the statement (which is
> even before you start reading from the resultset).
>
> jan
>


From: vinu <vinu(dot)rm(at)gmail(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Locking
Date: 2012-04-05 09:35:49
Message-ID: loom.20120405T112317-834@post.gmane.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc

I am having the same issue. Unless we close the connection or do a
connection.commit(), the AccessShareLock is not getting released.
ResultSet.close() and PreparedStatement.close() is not having any effect on this
behavior. Is this the expected behavior ?


From: "Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov>
To: "vinu" <vinu(dot)rm(at)gmail(dot)com>,<pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: Locking
Date: 2012-04-05 17:57:40
Message-ID: 4F7D96C40200002500046BFF@gw.wicourts.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc

vinu <vinu(dot)rm(at)gmail(dot)com> wrote:

> I am having the same issue.

For the benefit of those who don't remember the post:

http://archives.postgresql.org/pgsql-jdbc/2008-04/msg00094.php

> Unless we close the connection or do a connection.commit(), the
> AccessShareLock is not getting released. ResultSet.close() and
> PreparedStatement.close() is not having any effect on this
> behavior. Is this the expected behavior ?

Yes. Did you look at the existing reply?

http://archives.postgresql.org/pgsql-jdbc/2008-04/msg00095.php

-Kevin