php-psql lock problem. Thanks!

From: Maurizio Ortolan <crix98(at)tin(dot)it>
To: pgsql-hackers(at)postgresql(dot)org
Subject: php-psql lock problem. Thanks!
Date: 2001-10-14 19:24:47
Message-ID: 5.1.0.14.2.20011014122416.037cd170@mail.tin.it
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello to everybody!

I've a little problem with LOCK-ing a
certain row in a table using PHP and
PostgreSQL on LINUX.

>> In a few words, I'd like to undertand
>> how find out if a certain row is locked,
>> in order to prevent a kind of deadlock.

Which is the (system) table where all
locked row or tables are 'saved' ?
Is there any flag?

// ############################
Example 1:

User A:

BEGIN WORK;
select login from people where userid='1' for update;
[ ... ]
COMMIT WORK;

User B:
BEGIN WORK;
(***)
select login from people where userid='1' for update;

[ WAIT UNTIL 'COMMIT WORK' of user A ! :( ]

COMMIT WORK;

Solution:
I'd like to put in (***) a quick check in order to
know if the row with userid='1' is already locked or not.

In this way, if it's already locked, I'll use
select login from people where userid='1';
[ ONLY READ ]
instead of
select login from people where userid='1' for update;
[READ & WRITE]

// ############################
Example 2:

BEGIN WORK;
LOCK TABLE utenti IN SHARE ROW EXCLUSIVE MODE;
select login from people where userid='1';
COMMIT WORK;

// ############################

Many thanks to everybody!
Ciao!
MaURIZIO

crix98(at)____tin(dot)it

It's sure that
a small example in PHP will very very appreciated!! :))

PS: it's possible to setup a timeout for a locked table,
in order to exec an aoutomatic ROLLBACK ??
(for examples if the user goes away?

*******************************************
** Happy surfing on THE NET !! **
** Ciao by **
** C R I X 98 **
*******************************************
AntiSpam: rimuovere il trattino basso
dall'indirizzo per scrivermi...
(delete the underscore from the e-mail address to reply)

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2001-10-14 20:50:57 Re: Package support for Postgres
Previous Message Bill Studenmund 2001-10-14 18:19:38 Re: schema support, was Package support for Postgres