From: Ang Chin Han <angch@bytecraft.com.my>
To: Oliver Elphick <olly@lfix.co.uk>
Cc: Szabó Péter <matyee@westel900.net>
Cc: pgsql-admin@postgresql.org
Subject: Re: Lock!
Date: Wed, 15 Oct 2003 12:26:39 +0800
Message-ID: <3F8CCC7F.6@bytecraft.com.my> (raw)
In-Reply-To: <1066148873.5581.67.camel@linda.lfix.co.uk>
References: <004c01c39175$0f0b3620$2702a8c0@WorkGroup>
<1066148873.5581.67.camel@linda.lfix.co.uk>
Oliver Elphick wrote:
> You can't.
>
> Quote from the manual:
> So long as no deadlock situation is detected, a transaction
> seeking either a table-level or row-level lock will wait
> indefinitely for conflicting locks to be released. This means it
> is a bad idea for applications to hold transactions open for
> long periods of time (e.g., while waiting for user input).
Unless you set STATEMENT_TIMEOUT:
http://www.postgresql.org/docs/7.3/static/runtime-config.html#RUNTIME-CONFIG-GENERAL
In other words, try:
SET STATEMENT_TIMEOUT=50;
SELECT * FROM foo WHERE foo_id = 1 FOR UPDATE;
That means if another process is locking foo_id = 1 row for more than 50
millisecond after you try to SELECT it FOR UPDATE, you'll get an
error/rollback, and you can then assume it's being used.
Just remember to reset STATEMENT_TIMEOUT to zero or your default before
any slow queries in that transaction.
There was some discussion about emulating (IIRC) Oracle's SELECT .. FOR
UPDATE NOWAIT somewhere in the Postgresql archives. Look them up for
more details.
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 using the --to and --cc options:
reply via email
To: pgsql-admin@postgresql.org
Cc: angch@bytecraft.com.my, olly@lfix.co.uk, matyee@westel900.net
Subject: Re: Lock!
In-Reply-To: <3F8CCC7F.6@bytecraft.com.my>
* 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