pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Thomas Kellerer <spam_eater@gmx.net>
To: pgsql-general@postgresql.org
Subject: Re: Problem JDBC,  AutoCommit ON and SELECT FOR UPDATE
Date: Fri, 06 Mar 2015 19:31:36 +0100
Message-ID: <mdcrqe$gij$1@ger.gmane.org> (raw)
In-Reply-To: <OF493CD29D.2988C2D6-ONC1257E00.005A174C-C1257E00.005A7021@ordirope.fr>
References: <OF493CD29D.2988C2D6-ONC1257E00.005A174C-C1257E00.005A7021@ordirope.fr>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-general>

Philippe EMERIAUD wrote on 06.03.2015 17:27:
> Hi all,
>
> We have an application based on DB2 database, We are testing this
> same application on PostgreSQL database. By default we are in
> autocommit on mode.
>
> On DB2 (and Oracle), the query SELECT FOR UPDATE locks the row until
> the resultset is closed. On PostgreSQL database (all versions) this
> same query never locks (because we are in autocommit on mode). But
> this is a bad implementation of JDBC specification : "If a connection
> is in auto-commit mode, then all its SQL statements will be executed
> and committed as individual transactions.[...] The commit occurs when
> the statement completes or the next execute occurs, whichever comes
> first. In the case of statements returning a ResultSet object, the
> statement completes when the last row of the ResultSet object has
> been retrieved or the ResultSet object has been closed."

Maybe it's because the Postgres JDBC driver first reads the whole result into memory, which means
as soon as Statement.executeQuery() is finished, there is no cursor open any longer on the
server side.

Oracle (dont't know about DB2) will keep the cursor open until the last row has been processed.

Unfortunately, you can only switch to cursor-based retrieval when turning off autocommit:

https://jdbc.postgresql.org/documentation/94/query.html#query-with-cursor

> Is it possible to lock row in autocommit on mode on PostgreSQL
> database ?

In my eyes locking and autocommit don't really fit together.
What's the point in locking something if at the end of the statement (=control is returned to the caller)
the lock will be released anyway.

I'm surprised this works in Oracle actually.

Thomas



-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



view thread (5+ messages)  latest in thread

Message-ID: <mdcrqe$gij$1@ger.gmane.org>
Permalink:  ../mdcrqe$gij$1@ger.gmane.org/
Also on:    postgresql.org/message-id/mdcrqe$gij$1@ger.gmane.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: spam_eater@gmx.net, pgsql-general@postgresql.org
  Subject: Re: Problem JDBC,  AutoCommit ON and SELECT FOR UPDATE
  In-Reply-To: <mdcrqe$gij$1@ger.gmane.org>
  References: <OF493CD29D.2988C2D6-ONC1257E00.005A174C-C1257E00.005A7021@ordirope.fr> <mdcrqe$gij$1@ger.gmane.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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