Re: Long running queries

From: Benjamin Leis <benleis1(at)gmail(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Scott Ribe <scott_ribe(at)elevated-dev(dot)com>, Clive Swan <cliveswan(at)gmail(dot)com>, pgsql-admin(at)lists(dot)postgresql(dot)org
Subject: Re: Long running queries
Date: 2023-01-26 00:18:01
Message-ID: CADP9qHuvWMAXA9y3miYLAFwWQ51hJJasN1UkuYo_4spJqHHuVA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

We do a variety of variants on the following to find long running things.
The one below is looking for 'idle in txn' txns longer than 20 minutes.

SELECT NOW() - coalesce(xact_start, state_change) AS duration, * FROM
pg_stat_activity WHERE NOW() - coalesce(xact_st
art, state_change) > interval '20 minutes' AND state = 'idle in
transaction' ORDER BY xact_start

On Wed, Jan 25, 2023, 4:14 PM Bruce Momjian <bruce(at)momjian(dot)us> wrote:

> On Wed, Jan 25, 2023 at 10:57:58AM -0700, Scott Ribe wrote:
> > > On Jan 25, 2023, at 10:55 AM, Clive Swan <cliveswan(at)gmail(dot)com> wrote:
> > >
> > > SQL Server has a handy SQL "tool" to spot expensive and/or long
> running queries.
> > >
> > > Is there a similar query/tool for Postgresql??
> >
> > - pg_stat_statements extension
> > - log_min_duration config parameter
>
> FYI, log_min_duration_statement will not print the duration until the
> query completes, so it is good for analysis later.
>
> --
> Bruce Momjian <bruce(at)momjian(dot)us> https://momjian.us
> EDB https://enterprisedb.com
>
> Embrace your flaws. They make you human, rather than perfect,
> which you will never be.
>
>
>

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Massimo Ortensi 2023-01-26 10:11:09 Problems with unique constraints
Previous Message Bruce Momjian 2023-01-26 00:13:49 Re: Long running queries