FAQ
Is it possible to do a nonblocking lock? That is,
I want several clients to execute,

begin
if table A is locked
then
go around doing stuff on other tables
else
lock A and do stuff on A
endif

the problem is, if I use normal lock, then
after one client has locked and is doing stuff on A
the other one will block and thus it won't be able
to go around doing stuff on other tables. Is it
possible to do a nonblocking lock that will just
fail if the table is locked already?


NOTE: I tried using PQrequestCancel but it won't
cancel the request. It still blocks for as long
as the lock lasts. The only way around I've found so
far is to use PQreset. That's crude but works. But
it leaves a dangling postmaster process that lives
until the orignal lock is freed. Any other ideas?

Thanks a lot

Pablo Funes
Brandeis University
pablo@cs.brandeis.edu

Search Discussions

  • Massimo Dal Zotto at Jun 2, 1999 at 1:26 pm

    Is it possible to do a nonblocking lock? That is,
    I want several clients to execute,

    begin
    if table A is locked
    then
    go around doing stuff on other tables
    else
    lock A and do stuff on A
    endif

    the problem is, if I use normal lock, then
    after one client has locked and is doing stuff on A
    the other one will block and thus it won't be able
    to go around doing stuff on other tables. Is it
    possible to do a nonblocking lock that will just
    fail if the table is locked already?
    Try with user locks. You can find the code in contrib/userlocks.

    --
    Massimo Dal Zotto

    +----------------------------------------------------------------------+
    Massimo Dal Zotto email: dz@cs.unitn.it |
    Via Marconi, 141 phone: ++39-0461534251 |
    38057 Pergine Valsugana (TN) www: http://www.cs.unitn.it/~dz/ |
    Italy pgp: finger dz@tango.cs.unitn.it |
    +----------------------------------------------------------------------+
  • Bruce Momjian at Jun 2, 1999 at 3:33 pm

    Is it possible to do a nonblocking lock? That is,
    I want several clients to execute,

    begin
    if table A is locked
    then
    go around doing stuff on other tables
    else
    lock A and do stuff on A
    endif

    the problem is, if I use normal lock, then
    after one client has locked and is doing stuff on A
    the other one will block and thus it won't be able
    to go around doing stuff on other tables. Is it
    possible to do a nonblocking lock that will just
    fail if the table is locked already?
    Try with user locks. You can find the code in contrib/userlocks.
    Yes, this is the proper PostgreSQL solution.

    --
    Bruce Momjian | http://www.op.net/~candle
    maillist@candle.pha.pa.us | (610) 853-3000
    + If your life is a hard drive, | 830 Blythe Avenue
    + Christ can be your backup. | Drexel Hill, Pennsylvania 19026

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppgsql-hackers @
categoriespostgresql
postedMay 27, '99 at 10:42p
activeJun 2, '99 at 3:33p
posts3
users3
websitepostgresql.org...
irc#postgresql

People

Translate

site design / logo © 2021 Grokbase