pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #6548: NOWAIT does not work in Select statement if table is locked using "Lock " command
3+ messages / 3 participants
[nested] [flat]

* BUG #6548: NOWAIT does not work in Select statement if table is locked using "Lock " command
@ 2012-03-21 09:36  neeraj.punmiya@securetogether.com
  0 siblings, 2 replies; 3+ messages in thread

From: neeraj.punmiya@securetogether.com @ 2012-03-21 09:36 UTC (permalink / raw)
  To: pgsql-bugs

The following bug has been logged on the website:

Bug reference:      6548
Logged by:          Neeraj Punmiya
Email address:      neeraj.punmiya@securetogether.com
PostgreSQL version: 9.1.3
Operating system:   CentOS 6.2 , Windows 7
Description:        

Steps to simulate problem
============================

Create Table Test (x integer,y integer);

Insert Into Test Values(1,100);
Insert Into Test Values(2,200);

First database session:
---------------------------
start transaction;
Lock table Test;

Second database session
-----------------------
start transaction;

Select y from Test where x=1 for update nowait;

select query waits until first session releases table lock. 
Nowait does not have any effect in select statement. 




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #6548: NOWAIT does not work in Select statement if table is locked using "Lock " command
@ 2012-03-21 14:54  Kevin Grittner <Kevin.Grittner@wicourts.gov>
  parent: neeraj.punmiya@securetogether.com
  1 sibling, 0 replies; 3+ messages in thread

From: Kevin Grittner @ 2012-03-21 14:54 UTC (permalink / raw)
  To: neeraj.punmiya@securetogether.com; +Cc: pgsql-bugs

<neeraj.punmiya@securetogether.com> wrote:
 
> Create Table Test (x integer,y integer);
> 
> Insert Into Test Values(1,100);
> Insert Into Test Values(2,200);
> 
> First database session:
> ---------------------------
> start transaction;
> Lock table Test;
> 
> Second database session
> -----------------------
> start transaction;
> 
> Select y from Test where x=1 for update nowait;
> 
> select query waits until first session releases table lock. 
> Nowait does not have any effect in select statement. 
 
That is all functioning as designed and documented.  From the docs
at:
 
http://www.postgresql.org/docs/9.1/interactive/sql-select.html#SQL-FOR-UPDATE-SHARE
 
| 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 (see Chapter 13). You can use LOCK with the NOWAIT option
| first, if you need to acquire the table-level lock without waiting.
 
This is not a bug.
 
-Kevin



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #6548: NOWAIT does not work in Select statement if table is locked using "Lock " command
@ 2012-03-21 15:48  Tom Lane <tgl@sss.pgh.pa.us>
  parent: neeraj.punmiya@securetogether.com
  1 sibling, 0 replies; 3+ messages in thread

From: Tom Lane @ 2012-03-21 15:48 UTC (permalink / raw)
  To: neeraj.punmiya@securetogether.com; +Cc: pgsql-bugs

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



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2012-03-21 15:48 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2012-03-21 09:36 BUG #6548: NOWAIT does not work in Select statement if table is locked using "Lock " command neeraj.punmiya@securetogether.com
2012-03-21 14:54 ` Kevin Grittner <Kevin.Grittner@wicourts.gov>
2012-03-21 15:48 ` Tom Lane <tgl@sss.pgh.pa.us>

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