pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Rui DeSousa <rui.desousa@icloud.com>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: Pavan Teja <pavan.postgresdba@gmail.com>
Cc: Ron <ronljohnsonjr@gmail.com>
Cc: pgsql-admin <pgsql-admin@postgresql.org>
Subject: Re: pg_stat_activity
Date: Mon, 11 Jun 2018 15:05:10 -0400
Message-ID: <FC26C5E6-B0C6-46B5-9498-788CC05E7BBC@icloud.com> (raw)
In-Reply-To: <CAKFQuwYx=uBJ+=Vn_WuQ81HX0mFrXMLg36xN9vHFohH+U2uYAQ@mail.gmail.com>
References: <4405957b-2e0f-bfc5-eaf6-5e2864da2796@gmail.com>
	<CAGDYbUM0Lv-fcFp_Mh4jyBtSrW24Z1psvey6FBi5q=LQx=7CMQ@mail.gmail.com>
	<9884a24a-c129-a1a9-1901-2a9c8987331e@gmail.com>
	<BC0EBD96-110B-4CC7-A5B3-3088C40EEDA7@icloud.com>
	<CACh9nsZBYxBrgfFtK-KPB4x-8vZi83Sx=Qzbgf4cpVg+M2SDJA@mail.gmail.com>
	<CAKFQuwYx=uBJ+=Vn_WuQ81HX0mFrXMLg36xN9vHFohH+U2uYAQ@mail.gmail.com>

Ron,

This might get you closer to you goal.  Select will not take out exclusive locks out so we can eliminate sessions that have locks out.  Note that this will also remove long running queries that are part of a larger transaction that had issued some sort of DML/DDL prior to running.

p.s. careful with the smart quotes; autocorrect in email is not great for code.

select pg_stat_activity.pid
  , pg_stat_activity.usename
  , pg_stat_activity.client_addr
  , pg_stat_activity.client_port
  , pg_stat_activity.state
  , pg_stat_activity.backend_xid 
  , pg_stat_activity.backend_xmin
  , age(now(), pg_stat_activity.state_change) as state_time
  , pg_stat_activity.wait_event_type
  , pg_stat_activity.wait_event
  , age(now(), pg_stat_activity.query_start) as query_time
  , pg_stat_activity.query
from pg_stat_activity
where pg_stat_activity.state <> 'idle'::text
  and pg_stat_activity.pid not in (
    select pid 
    from pg_locks 
    where locktype = 'relation'
      and mode in ('RowExclusiveLock', 'ExclusiveLock') 
  )
order by pg_stat_activity.query_start
;

view thread (23+ messages)  latest in thread

Message-ID: <FC26C5E6-B0C6-46B5-9498-788CC05E7BBC@icloud.com>
Permalink:  ../FC26C5E6-B0C6-46B5-9498-788CC05E7BBC@icloud.com/
Also on:    postgresql.org/message-id/FC26C5E6-B0C6-46B5-9498-788CC05E7BBC@icloud.com

 · 

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: rui.desousa@icloud.com, david.g.johnston@gmail.com, pavan.postgresdba@gmail.com, ronljohnsonjr@gmail.com
  Subject: Re: pg_stat_activity
  In-Reply-To: <FC26C5E6-B0C6-46B5-9498-788CC05E7BBC@icloud.com>
  References: <4405957b-2e0f-bfc5-eaf6-5e2864da2796@gmail.com> <CAGDYbUM0Lv-fcFp_Mh4jyBtSrW24Z1psvey6FBi5q=LQx=7CMQ@mail.gmail.com> <9884a24a-c129-a1a9-1901-2a9c8987331e@gmail.com> <BC0EBD96-110B-4CC7-A5B3-3088C40EEDA7@icloud.com> <CACh9nsZBYxBrgfFtK-KPB4x-8vZi83Sx=Qzbgf4cpVg+M2SDJA@mail.gmail.com> <CAKFQuwYx=uBJ+=Vn_WuQ81HX0mFrXMLg36xN9vHFohH+U2uYAQ@mail.gmail.com> <FC26C5E6-B0C6-46B5-9498-788CC05E7BBC@icloud.com>

* 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