X-Original-To: pgsql-admin-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 2EB519FB1F0; Wed, 23 Aug 2006 17:40:38 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 30853-01-3; Wed, 23 Aug 2006 17:40:24 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- X-Greylist: from auto-whitelisted by SQLgrey- Received: from exchange.g2switchworks.com (mail.g2switchworks.com [63.87.162.25]) by postgresql.org (Postfix) with ESMTP id 3DAF89FB3D5; Wed, 23 Aug 2006 17:40:23 -0300 (ADT) Received: from 10.10.1.37 ([10.10.1.37]) by exchange.g2switchworks.com ([10.10.1.2]) with Microsoft Exchange Server HTTP-DAV ; Wed, 23 Aug 2006 20:40:22 +0000 Received: from state.g2switchworks.com by mail.g2switchworks.com; 23 Aug 2006 15:40:22 -0500 Subject: Re: [GENERAL] How to detect Postgres deadlocks? From: Scott Marlowe To: andre Cc: pgsql-admin@postgresql.org, pgsql general In-Reply-To: <6c3954020608231245l3035ffbby41cfdbfac2d37326@mail.google.com> References: <6c3954020608231245l3035ffbby41cfdbfac2d37326@mail.google.com> Content-Type: text/plain Content-Transfer-Encoding: 7bit Message-Id: <1156365622.7223.62.camel@state.g2switchworks.com> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) Date: Wed, 23 Aug 2006 15:40:22 -0500 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.083 tagged_above=0 required=5 tests=AWL, SPF_PASS, UNPARSEABLE_RELAY X-Spam-Level: X-Archive-Number: 200608/249 X-Sequence-Number: 22792 On Wed, 2006-08-23 at 14:45, andre wrote: > Hi, > > We are using Postgres 7.4.5, and I'm trying to find a way to detect > and gather deadlock information. > > 1) Which sql queries should I use to detect deadlocks while they are > happening? I see the deadlock info on the log file, but I'd like to > query the database to see them as they happen... > > 2) Which fields on which pg catalogs indicate a deadlock condition? > > 3) How can I get more info about the processes involved on deadlocks? > > 4) How can I get the sql statements associated with the processes > involved on deadlocks? > > On the logs I see the procpids of the processes involved on past > deadlocks, but I 'd like to know how to get those procpids, and how to > get the "current_query" associated with them... I'm not sure what you're really looking for. When PostgreSQL detects a deadlock, it aborts one of the queries to stop the deadlock right away. test=> update l set b=22 where i=2; ERROR: deadlock detected DETAIL: Process 25854 waits for ShareLock on transaction 11654043; blocked by process 24918. Process 24918 waits for ShareLock on transaction 11654047; blocked by process 25854. test=> That deadlock detection took about 1 second and rolled back my transaction immediately. I'm not sure you can detect them in real time any better than pgsql can. Or are you experiencing some kind of deadly embrace problem??? Tell us what problem you're having and maybe we can come up with some better advice.