Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YTwGB-0003M1-A7 for pgsql-general@arkaria.postgresql.org; Fri, 06 Mar 2015 17:42:03 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YTwGA-0002Vh-2c for pgsql-general@arkaria.postgresql.org; Fri, 06 Mar 2015 17:42:02 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YTwG8-0002Va-Cr for pgsql-general@postgresql.org; Fri, 06 Mar 2015 17:42:00 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by makus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YTwG3-0005iO-UW for pgsql-general@postgresql.org; Fri, 06 Mar 2015 17:41:58 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 6E07E20709 for ; Fri, 6 Mar 2015 12:41:53 -0500 (EST) Received: from frontend2 ([10.202.2.161]) by compute3.internal (MEProxy); Fri, 06 Mar 2015 12:41:54 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=aklaver.com; h= x-sasl-enc:message-id:date:from:mime-version:to:subject :references:in-reply-to:content-type:content-transfer-encoding; s=mesmtp; bh=c/EH1cWOz5RXdS4x6q0mDmJCl14=; b=GUXxYddthJ+e35+/my JwIBVTq7SfQCb+8zQmA2eU/nzduJCNKjaBxr57nZRHW3UrMag3dddgXQezUEjznJ Mdj4YlvHrE1Z6+YBb04GWU/IgvrQ3/zjCsvzsMqSpih9bU18WqUZSURBCt8e14og uEY+1dpiwM3z9710tuha2kcs0= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=x-sasl-enc:message-id:date:from :mime-version:to:subject:references:in-reply-to:content-type :content-transfer-encoding; s=smtpout; bh=c/EH1cWOz5RXdS4x6q0mDm JCl14=; b=lv0V1bZY0wvu1b+rE+RYB54nLnFvrEV61lBoTqu0hdrbANfjP3mfGM EjqWQLcve+L5Kyp2eMFWs9RpgpsfLIeXx2FoJN3B6V7ATjps8b5wCgfUYLaUZpXU Mk8AuiPW/lfRrp095vu0Z+JYv3ULNZC5lO4d/r7obvPgENBRFMGmo= X-Sasl-enc: QaJA5gIdN/HX8LFdxpod/LCCK4lHuJK+NUCGH13a4oY0 1425663714 Received: from killi.site (unknown [74.94.73.222]) by mail.messagingengine.com (Postfix) with ESMTPA id 47F9A680179; Fri, 6 Mar 2015 12:41:54 -0500 (EST) Message-ID: <54F9E6E2.9030106@aklaver.com> Date: Fri, 06 Mar 2015 09:41:54 -0800 From: Adrian Klaver User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: Philippe EMERIAUD , pgsql-general@postgresql.org Subject: Re: Problem JDBC, AutoCommit ON and SELECT FOR UPDATE References: In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.7 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-general Precedence: bulk Sender: pgsql-general-owner@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