From: Tom Lane <tgl@sss.pgh.pa.us>
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
Date: Wed, 21 Mar 2012 11:48:24 -0400
Message-ID: <1737.1332344904@sss.pgh.pa.us> (raw)
In-Reply-To: <E1SAHyG-0002nj-Hq@wrigleys.postgresql.org>
References: <E1SAHyG-0002nj-Hq@wrigleys.postgresql.org>
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
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-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, neeraj.punmiya@securetogether.com
Subject: Re: BUG #6548: NOWAIT does not work in Select statement if table is locked using "Lock " command
In-Reply-To: <1737.1332344904@sss.pgh.pa.us>
References: <E1SAHyG-0002nj-Hq@wrigleys.postgresql.org> <1737.1332344904@sss.pgh.pa.us>
* 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