X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 71E3E32ACDB for ; Mon, 4 Oct 2004 12:33:47 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 71039-04 for ; Mon, 4 Oct 2004 11:33:35 +0000 (GMT) Received: from av9-1-sn4.m-sp.skanova.net (av9-1-sn4.m-sp.skanova.net [81.228.10.108]) by svr1.postgresql.org (Postfix) with ESMTP id C593832ACD9 for ; Mon, 4 Oct 2004 12:33:36 +0100 (BST) Received: by av9-1-sn4.m-sp.skanova.net (Postfix, from userid 502) id 55DFB37F0E; Mon, 4 Oct 2004 13:33:35 +0200 (CEST) Received: from smtp2-1-sn4.m-sp.skanova.net (smtp2-1-sn4.m-sp.skanova.net [81.228.10.183]) by av9-1-sn4.m-sp.skanova.net (Postfix) with ESMTP id 4253537E6F for ; Mon, 4 Oct 2004 13:33:35 +0200 (CEST) Received: from [192.168.100.2] (h153n2fls31o806.telia.com [217.210.1.153]) by smtp2-1-sn4.m-sp.skanova.net (Postfix) with ESMTP id 2DAE137E49 for ; Mon, 4 Oct 2004 13:33:34 +0200 (CEST) Subject: Re: Concurrency problem From: Dag Gullberg To: pgsql-sql@postgresql.org In-Reply-To: <3318.1096823750@sss.pgh.pa.us> References: <1096801131.5238.32.camel@hemma> <3318.1096823750@sss.pgh.pa.us> Content-Type: text/plain; charset=ISO-8859-1 Organization: Message-Id: <1096889735.4305.239.camel@hemma> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.2 (1.2.2-5) Date: 04 Oct 2004 13:35:35 +0200 Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=2.2 tagged_above=0.0 required=5.0 tests=RCVD_IN_BL_SPAMCOP_NET X-Spam-Level: ** X-Archive-Number: 200410/19 X-Sequence-Number: 19122 Hi Tom, Yes, I have several clients connecting to the db, using the same username, doing the same things, pretty much. Please educate me: When a table is accessed, is there an entry that is updated in pg_catalog.pg_tables (or somewhere else) in such a fashion that the MVCC cannot handle it and that consecutive selects from other clients will cause concurrency errors? Are these entries not "locked" while accessed? What's more in your response is very clear and it is amazing how easy it is to slip into singel user reasoning, if not careful, when writing code for a multi user environment. Its a blunder, pure and simple. I stand corrected (and wiser). Thanks! /Dag (apologies for sending this to you private address first) sön 2004-10-03 klockan 19.15 skrev Tom Lane: > Dag Gullberg 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.