Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 7EC7C2F427D for ; Wed, 21 Mar 2012 12:48:40 -0300 (ADT) Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SANm9-0001Ti-Qw for pgsql-bugs@postgresql.org; Wed, 21 Mar 2012 15:48:39 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id q2LFmOlV001738; Wed, 21 Mar 2012 11:48:24 -0400 (EDT) To: neeraj.punmiya@securetogether.com cc: pgsql-bugs@postgresql.org Subject: Re: BUG #6548: NOWAIT does not work in Select statement if table is locked using "Lock " command In-reply-to: References: Comments: In-reply-to neeraj.punmiya@securetogether.com message dated "Wed, 21 Mar 2012 09:36:44 -0000" Date: Wed, 21 Mar 2012 11:48:24 -0400 Message-ID: <1737.1332344904@sss.pgh.pa.us> From: Tom Lane X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201203/156 X-Sequence-Number: 32717 neeraj.punmiya@securetogether.com writes: > First database session: > --------------------------- > Lock table Test; > Second database session > ----------------------- > Select y from Test where x=1 for update nowait; > select query waits until first session releases table lock. This isn't a bug. FOR UPDATE NOWAIT is only meant to specify not waiting for row-level locks on the rows you're trying to lock for update, as per the explanation in the SELECT reference page: To prevent the operation from waiting for other transactions to commit, use the NOWAIT option. With NOWAIT, the statement reports an error, rather than waiting, if a selected row cannot be locked immediately. Note that NOWAIT applies only to the row-level lock(s) - the required ROW SHARE table-level lock is still taken in the ordinary way If it meant "fail on any lock anywhere" the behavior would be too unpredictable. You might consider doing "lock table Test in row share mode nowait" in the second transaction, if you want it to fail on table-level locks too. Another solution is to just use a short statement_timeout rather than NOWAIT clauses. regards, tom lane