X-Original-To: pgsql-admin@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 9524B475E91 for ; Fri, 18 Apr 2003 14:33:25 -0400 (EDT) Received: from proteus.affordablehost.com (unknown [216.46.203.177]) by postgresql.org (Postfix) with SMTP id 6C9AB475458 for ; Fri, 18 Apr 2003 14:33:21 -0400 (EDT) Received: (qmail 8005 invoked from network); 18 Apr 2003 18:33:20 -0000 Received: from unknown (HELO e-greek.net) (66.92.74.181) by 216.46.203.177 with SMTP; 18 Apr 2003 18:33:20 -0000 Message-ID: <3EA044F3.2040303@e-greek.net> Date: Fri, 18 Apr 2003 14:33:23 -0400 From: Andrew Biagioni User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.3) Gecko/20030312 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Tom Lane Cc: shobha@phildigital.com, pgsql-admin@postgresql.org Subject: Re: deadlock detection References: <3E92664D.313C3DFE@phil.com.sg> <4163.1049861103@sss.pgh.pa.us> In-Reply-To: <4163.1049861103@sss.pgh.pa.us> Content-Type: multipart/alternative; boundary="------------000006060108040300020505" X-Spam-Status: No, hits=-37.0 required=5.0 tests=BAYES_10,EMAIL_ATTRIBUTION,HTML_10_20,IN_REP_TO, QUOTED_EMAIL_TEXT,REFERENCES,REPLY_WITH_QUOTES, USER_AGENT_MOZILLA_UA autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200304/258 X-Sequence-Number: 8413 This is a multi-part message in MIME format. --------------000006060108040300020505 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Tom Lane wrote: >SHOBHA HALDONKAR writes: > > >> Suppose if a record is locked with update command and another >>concurrent user tries to lock the same record and the first transaction >>for some reason , eg. m/c hangings is not committed both the >>transactions remains locked for indefinite period . I have checked the >>setting in postgresql.config for deadlock_timeout which is set to 1000 >>. Than why doesn't the transaction deatect deadlock after 1000 >>millisecond . >> >> > >Waiting for a client that chooses not to commit is not a deadlock. > > regards, tom lane > I used to be unclear on some of this, so I think I understand your confusion. This is how it works: The database assumes that you know what you are doing; if a transaction is not committed or rolled back, the lock remains (in 7.3 you can have transactions time out as well). If a connection drops, and you CANNOT terminate the transaction, the DB terminates it for you (ROLLBACK). Anywhere you have to wait for user interaction to complete an operation, AND you did a write before you started waiting for the user, you need ot find a way to break up the operation into two transactions, otherwise you WILL lock the DB (if the user goes to the restroom, or to lunch, or their keyboard breaks, ...). My approach is usually to store in the front end or middle layer anything I need to write, and actually write to the DB after the user interaction is complete (with no delays between start and end of transaction). Another approach is to set up the DB so that you can do your writes in multiple transactions without compromising data validity, although some times you need to run a clean-up every now and then to purge those operations that never completed. Beyond that... Get creative ! :-) Andrew --------------000006060108040300020505 Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit

Tom Lane wrote:
SHOBHA HALDONKAR <shobha@phildigital.com> writes:
  
       Suppose if a record is locked with update  command   and another
concurrent user  tries to lock the same record and the first transaction
for some reason , eg. m/c hangings   is not committed  both the
transactions remains locked for indefinite period . I have checked the
setting in postgresql.config  for deadlock_timeout  which is set to 1000
. Than why doesn't  the transaction deatect deadlock after 1000
millisecond  .
    

Waiting for a client that chooses not to commit is not a deadlock.

			regards, tom lane

I used to be unclear on some of this, so I think I understand your confusion.  This is how it works:

The database assumes that you know what you are doing;  if a transaction is not committed or rolled back, the lock remains (in 7.3 you can have transactions time out as well).

If a connection drops, and you CANNOT terminate the transaction, the DB terminates it for you (ROLLBACK).

Anywhere you have to wait for user interaction to complete an operation, AND you did a write before you started waiting for the user, you need ot find a way to break up the operation into two transactions, otherwise you WILL lock the DB (if the user goes to the restroom, or to lunch, or their keyboard breaks, ...).

My approach is usually to store in the front end or middle layer anything I need to write, and actually write to the DB after the user interaction is complete (with no delays between start and end of transaction). 

Another approach is to set up the DB so that you can do your writes in multiple transactions without compromising data validity, although some times you need to run a clean-up every now and then to purge those operations that never completed.

Beyond that...  Get creative !  :-)

    Andrew

--------------000006060108040300020505--