Re: Concurrency problem

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Dag Gullberg <dag(dot)gullberg(at)telia(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Concurrency problem
Date: 2004-10-03 17:15:50
Message-ID: 3318.1096823750@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Dag Gullberg <dag(dot)gullberg(at)telia(dot)com> writes:
> Warning: pg_query(): Query failed: ERROR: tuple concurrently updated
> CONTEXT: PL/pgSQL function "get_rights" line 5 at SQL statement in
> /home/site/PHP/db_func.php on line 301

> Code of get_rights:
> GRANT SELECT ON c.users TO
> adm,w3;
> SELECT rights INTO result
> FROM c.users
> WHERE usr_id=uid;

> REVOKE ALL ON c.users FROM w3,adm;
> RETURN result;

Do you have a bunch of clients doing this in parallel? If so, the
problem is probably coming from two instances of the function trying to
update the catalog entry for c.users at the same time. The approach
is fundamentally broken anyhow, because there is nothing stopping
client 2 from revoking the rights in between client 1 doing his GRANT
and his SELECT.

The right way to do what you seem to want (allow only this function to
access the table) is not to flap the rights settings back and forth
like that. Grant SELECT rights to a specific userid and make the
function be owned by that userid and be labeled SECURITY DEFINER.

regards, tom lane

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Jens Arnfelt 2004-10-03 20:50:13 How to convert 3 colums to timestamp with timezone
Previous Message John DeSoi 2004-10-03 15:50:38 Re: Postgres Doubt