Re: Query to detect long-running transactions?

From: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: Query to detect long-running transactions?
Date: 2007-10-22 16:00:29
Message-ID: 20071022160029.GA10204@a-kretschmer.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

am Mon, dem 22.10.2007, um 10:46:58 -0400 mailte Brian Hurt folgendes:
>
> I'm wondering if there is a query I could run to detect long-running
> transactions? Basically, I want to know all transactions (either on a
> given server or just on a given database) that have been running for
> longer than some parameterized amount of time.

You can log all statements with a duration time higher than a limit:

log_min_duration_statement = N

with N in ms.

>
> I've spent some time with the friendly manual (especially Chapter 42 and
> 12), and didn't see anything usefull.
>
> I'm having a problem with stupid humans (including yours truely)
> forgetting they have a transaction outstanding and wandering off for a
> weekend. What I'd like to do is write a quick script that queries the

You can query pg_stat_activity for query_start and compare that with the
current time to find long running transactions (current_query : '<IDLE>
in transaction'). Hope that helps.

Andreas
--
Andreas Kretschmer
Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Brian Hurt 2007-10-22 19:44:38 Big copy slowdown
Previous Message Brian Hurt 2007-10-22 14:46:58 Query to detect long-running transactions?