X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 958FE9DCC4C for ; Wed, 22 Feb 2006 14:58:32 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 62682-08 for ; Wed, 22 Feb 2006 14:58:32 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 0CCD09DCC44 for ; Wed, 22 Feb 2006 14:58:28 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k1MIwOaO014025; Wed, 22 Feb 2006 13:58:24 -0500 (EST) To: mario.splivalo@mobart.hr cc: pgsql-sql@postgresql.org Subject: Re: 'locking' the SELECTs based on indices... In-reply-to: <1140631350.14229.8.camel@localhost.localdomain> References: <1140631350.14229.8.camel@localhost.localdomain> Comments: In-reply-to Mario Splivalo message dated "Wed, 22 Feb 2006 19:02:30 +0100" Date: Wed, 22 Feb 2006 13:58:24 -0500 Message-ID: <14024.1140634704@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.111 required=5 tests=[AWL=0.111] X-Spam-Score: 0.111 X-Spam-Level: X-Archive-Number: 200602/270 X-Sequence-Number: 24280 Mario Splivalo writes: > Now, when I do this from one connection (psql shell, for instance): > [A]BEGIN TRANSACTION; > [A]SELECT * FROM bla WHERE code_id = 1 FOR UPDATE; > and then, from another psql i do: > [B]SELECT * FROM bla WHERE code_id = 1 FOR UPDATE > the second SELECT will wait untill I rollback or commit first > transaction. That is cool. > But, if I do second SELECT like this: > [C]SELECT * FROM bla WHERE code_id = 2 FOR UPDATE > I will get the rows. Well, of course. Why would you want something different? Why do you think the table's indexes should have anything to do with it? If you want a full-table lock then some form of LOCK TABLE seems like the proper answer. SELECT FOR UPDATE is designed to lock the specified rows, no more. > If I erase the index bla_idx1, then [C] select will wait, same as [B] > select will wait. I don't think so. If it does, it's a bug; please provide a reproducible test case. regards, tom lane