pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andrew Biagioni <andrew.biagioni@e-greek.net>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: shobha@phildigital.com
Cc: pgsql-admin@postgresql.org
Subject: Re: deadlock detection
Date: Fri, 18 Apr 2003 14:33:23 -0400
Message-ID: <3EA044F3.2040303@e-greek.net> (raw)
In-Reply-To: <4163.1049861103@sss.pgh.pa.us>
References: <3E92664D.313C3DFE@phil.com.sg>
	<4163.1049861103@sss.pgh.pa.us>



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

view thread (3+ messages)

Message-ID: <3EA044F3.2040303@e-greek.net>
Permalink:  ../3EA044F3.2040303@e-greek.net/
Also on:    postgresql.org/message-id/3EA044F3.2040303@e-greek.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: andrew.biagioni@e-greek.net, tgl@sss.pgh.pa.us, shobha@phildigital.com
  Subject: Re: deadlock detection
  In-Reply-To: <3EA044F3.2040303@e-greek.net>
  References: <3E92664D.313C3DFE@phil.com.sg> <4163.1049861103@sss.pgh.pa.us> <3EA044F3.2040303@e-greek.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox