X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 802FA52862 for ; Mon, 6 Jun 2005 11:05:49 -0300 (ADT) 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 83180-09 for ; Mon, 6 Jun 2005 14:05:45 +0000 (GMT) Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by svr1.postgresql.org (Postfix) with ESMTP id D8B42528C5 for ; Mon, 6 Jun 2005 11:05:43 -0300 (ADT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id j56E5aYx054714 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 6 Jun 2005 08:05:38 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.3/8.13.3) with ESMTP id j56E5Z0X038120; Mon, 6 Jun 2005 08:05:35 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.3/8.13.3/Submit) id j56E5Y2P038119; Mon, 6 Jun 2005 08:05:35 -0600 (MDT) (envelope-from mfuhr) Date: Mon, 6 Jun 2005 08:05:34 -0600 From: Michael Fuhr To: Douglas McNaught Cc: Surabhi Ahuja , pgsql-general@postgresql.org Subject: Re: transactions Message-ID: <20050606140534.GA38033@winnie.fuhr.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.005 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200506/247 X-Sequence-Number: 78955 On Mon, Jun 06, 2005 at 09:21:15AM -0400, Douglas McNaught wrote: > "Surabhi Ahuja " writes: > > > say i have two transactions going on simultaneoulsy. > > in one transaction i do an insertion > > and the other transaction i do a delete. > > what will happen if in both the transactions, the insert(in one) and > > delete(in the other) are issued at exactly the same time? will bothe get > > blocked and enter into a deadlock, if yes then do both the transactions > > get aborted after some time of waiting. > > The transactions will be executed completely independently, unless you > do explicit locking (via SELECT FOR UPDATE or LOCK TABLE). Deadlock can still happen if Transaction A's INSERT blocks because of something Transaction B did previously, and Transaction B's DELETE blocks because of something Transaction A did previously. Foreign key relationships are a typical cause, but even UPDATEs on simple tables can cause later operations to deadlock if the application isn't careful with its order of operations. -- Michael Fuhr http://www.fuhr.org/~mfuhr/