pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedProblem JDBC, AutoCommit ON and SELECT FOR UPDATE
5+ messages / 4 participants
[nested] [flat]
* Problem JDBC, AutoCommit ON and SELECT FOR UPDATE
@ 2015-03-06 16:27 Philippe EMERIAUD <p.emeriaud@ordirope.fr>
0 siblings, 3 replies; 5+ messages in thread
From: Philippe EMERIAUD @ 2015-03-06 16:27 UTC (permalink / raw)
To: pgsql-general@postgresql.org
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."
Is it possible to lock row in autocommit on mode on PostgreSQL database ?
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Problem JDBC, AutoCommit ON and SELECT FOR UPDATE
@ 2015-03-06 17:41 Adrian Klaver <adrian.klaver@aklaver.com>
parent: Philippe EMERIAUD <p.emeriaud@ordirope.fr>
2 siblings, 0 replies; 5+ messages in thread
From: Adrian Klaver @ 2015-03-06 17:41 UTC (permalink / raw)
To: Philippe EMERIAUD <p.emeriaud@ordirope.fr>; pgsql-general@postgresql.org
On 03/06/2015 08:27 AM, Philippe EMERIAUD wrote:
> 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."
> Is it possible to lock row in autocommit on mode on PostgreSQL database ?
I am not following. So you have:
BEGIN;
SELECT FOR UPDATE ...;
COMMIT;
The SELECT FOR UPDATE will lock the rows while doing the SELECT and then
release when it the COMMIT happens. So barring an error the lock will
hold for the time it takes to do the SELECT and process the COMMIT.
Do you want the lock to hold past the COMMIT?
--
Adrian Klaver
adrian.klaver@aklaver.com
--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Problem JDBC, AutoCommit ON and SELECT FOR UPDATE
@ 2015-03-06 17:51 Dave Cramer <pg@fastcrypt.com>
parent: Philippe EMERIAUD <p.emeriaud@ordirope.fr>
2 siblings, 1 reply; 5+ messages in thread
From: Dave Cramer @ 2015-03-06 17:51 UTC (permalink / raw)
To: Philippe EMERIAUD <p.emeriaud@ordirope.fr>; +Cc: pgsql-general@postgresql.org <pgsql-general@postgresql.org>
Can you point me to the source of that quote ?
The documentation here
http://docs.oracle.com/javase/7/docs/api/java/sql/Connection.html does not
specify anything about ResultSet closing, or completion ?
Short version is that the driver does not hold the lock past the return of
the result set, so unfortunately not.
Dave Cramer
dave.cramer(at)credativ(dot)ca
http://www.credativ.ca
On 6 March 2015 at 11:27, Philippe EMERIAUD <p.emeriaud@ordirope.fr> wrote:
> 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."
> Is it possible to lock row in autocommit on mode on PostgreSQL database ?
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Problem JDBC, AutoCommit ON and SELECT FOR UPDATE
@ 2015-03-06 18:31 Thomas Kellerer <spam_eater@gmx.net>
parent: Philippe EMERIAUD <p.emeriaud@ordirope.fr>
2 siblings, 0 replies; 5+ messages in thread
From: Thomas Kellerer @ 2015-03-06 18:31 UTC (permalink / raw)
To: pgsql-general@postgresql.org
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
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: [GENERAL] Problem JDBC, AutoCommit ON and SELECT FOR UPDATE
@ 2015-03-12 15:16 Dave Cramer <pg@fastcrypt.com>
parent: Dave Cramer <pg@fastcrypt.com>
0 siblings, 0 replies; 5+ messages in thread
From: Dave Cramer @ 2015-03-12 15:16 UTC (permalink / raw)
To: Philippe EMERIAUD <p.emeriaud@ordirope.fr>; pgsql-jdbc
Don't think we support 1.5 any more. This is way past EOL for java
About the only way you can compile this is to get an old build.xml from say
9.2 and use it to compile.
Dave
Dave Cramer
dave.cramer(at)credativ(dot)ca
http://www.credativ.ca
On 12 March 2015 at 11:08, Philippe EMERIAUD <p.emeriaud@ordirope.fr> wrote:
> Hi Dave,
>
> I'am trying to compile the pgjdbc driver with Ant and java 1.5 (for use
> JDBC 3), but the build failed.
> The problem comes from the library JNA.
>
> [javac]
> C:\Users\PEMERI.PACIFIC\Documents\GitHub\pgjdbc\org\postgresql\sspi\NTDSAPI.java:3:
> cannot access com.sun.jna.LastErrorException
> [javac] bad class file:
> C:\Users\PEMERI.PACIFIC\.m2\repository\net\java\dev\jna\jna\4.1.0\jna-4.1.0.jar(com/sun/jna/LastErrorException.class)
> [javac] class file has wrong version 50.0, should be 49.0
> (See my log in the attachment. for more details)
>
> It would seem that the library jna has be compiled with a jdk greater than
> 1.5.
> Can you confirm this and how can i fix it.
>
> Regards
> Philippe Emeriaud.
>
>
>
>
>
>
> De : Dave Cramer <pg@fastcrypt.com>
> A : Philippe EMERIAUD <p.emeriaud@ordirope.fr>
> Date : 09/03/2015 12:26
> Objet : Re: [GENERAL] Problem JDBC, AutoCommit ON and SELECT FOR
> UPDATE
> Envoyé par : davecramer@gmail.com
> ------------------------------
>
>
>
> Philippe,
>
> Well, unfortunately this is not probable (read impossible) to implement in
> postgresql (or any other database besides Oracle).
>
> Candidly any attempt to force this is probably going to end badly; but let
> me know how it goes.
>
> Cheers
>
> Dave Cramer
>
> dave.cramer(at)credativ(dot)ca
> *http://www.credativ.ca* <http://www.credativ.ca/;
>
> On 9 March 2015 at 04:54, Philippe EMERIAUD <*p.emeriaud@ordirope.fr*
> <p.emeriaud@ordirope.fr>> wrote:
> Hi Dave,
> Thanks for your reply. My quote comes from the Java 1.5 specification (i
> know this is an old release !) but in the java 1.7 specification you can
> read the javadoc of setAutoCommit(boolean) method, it says :
>
> * "Sets this connection's auto-commit mode to the given state. If a
> connection is in auto-commit mode, then all its SQL statements will be
> executed and committed as individual transactions. Otherwise, its SQL
> statements are grouped into transactions that are terminated by a call to
> either the method commit or the method rollback. By default, new
> connections are in auto-commit mode.*
>
> *The commit occurs when the statement completes. The time when the
> statement completes depends on the type of SQL Statement:*
>
> - *For DML statements, such as Insert, Update or Delete, and DDL
> statements, the statement is complete as soon as it has finished executing.*
> - *For Select statements, the statement is complete when the
> associated result set is closed.*
> - *For CallableStatement objects or for statements that return
> multiple results, the statement is complete when all of the associated
> result sets have been closed, and all update counts and output parameters
> have been retrieved."*
>
>
> There is no easy solution for our problem, 2 ways :
> - We are testing the application with autocommit turned off.
> - We are testing a modified JDBC driver to force lock in AutoCommit on
> mode.
>
> Thanks again.
> Philippe Emeriaud.
>
>
>
> De : Dave Cramer <*pg@fastcrypt.com* <pg@fastcrypt.com>>
> A : Philippe EMERIAUD <*p.emeriaud@ordirope.fr*
> <p.emeriaud@ordirope.fr>>
> Cc : "*pgsql-general@postgresql.org* <pgsql-general@postgresql.org>"
> <*pgsql-general@postgresql.org* <pgsql-general@postgresql.org>>
> Date : 06/03/2015 18:54
> Objet : Re: [GENERAL] Problem JDBC, AutoCommit ON and SELECT FOR
> UPDATE
> Envoyé par : *pgsql-general-owner@postgresql.org*
> <pgsql-general-owner@postgresql.org>
> ------------------------------
>
>
>
>
> Can you point me to the source of that quote ?
>
> The documentation here
> *http://docs.oracle.com/javase/7/docs/api/java/sql/Connection.html*
> <http://docs.oracle.com/javase/7/docs/api/java/sql/Connection.html; does
> not specify anything about ResultSet closing, or completion ?
>
> Short version is that the driver does not hold the lock past the return of
> the result set, so unfortunately not.
>
> Dave Cramer
>
> dave.cramer(at)credativ(dot)ca
> *http://www.credativ.ca* <http://www.credativ.ca/;
>
> On 6 March 2015 at 11:27, Philippe EMERIAUD <*p.emeriaud@ordirope.fr*
> <p.emeriaud@ordirope.fr>> wrote:
> 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."
> Is it possible to lock row in autocommit on mode on PostgreSQL database ?
>
>
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2015-03-12 15:16 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2015-03-06 16:27 Problem JDBC, AutoCommit ON and SELECT FOR UPDATE Philippe EMERIAUD <p.emeriaud@ordirope.fr>
2015-03-06 17:41 ` Adrian Klaver <adrian.klaver@aklaver.com>
2015-03-06 17:51 ` Re: Problem JDBC, AutoCommit ON and SELECT FOR UPDATE Dave Cramer <pg@fastcrypt.com>
2015-03-12 15:16 ` Re: [GENERAL] Problem JDBC, AutoCommit ON and SELECT FOR UPDATE Dave Cramer <pg@fastcrypt.com>
2015-03-06 18:31 ` Thomas Kellerer <spam_eater@gmx.net>
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