Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fSS7z-0002vY-2c for pgsql-admin@arkaria.postgresql.org; Mon, 11 Jun 2018 19:05:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fSS7x-0004oe-PF for pgsql-admin@arkaria.postgresql.org; Mon, 11 Jun 2018 19:05:17 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fSS7x-0004oJ-C1 for pgsql-admin@lists.postgresql.org; Mon, 11 Jun 2018 19:05:17 +0000 Received: from mr28p48im-tydg10101201.me.com ([17.110.88.44]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fSS7u-0001Cn-OA for pgsql-admin@postgresql.org; Mon, 11 Jun 2018 19:05:15 +0000 Received: from process-dkim-sign-daemon.mr28p48im-tydg10101201.me.com by mr28p48im-tydg10101201.me.com (Oracle Communications Messaging Server 8.0.1.2.20170607 64bit (built Jun 7 2017)) id <0PA600B00A7U0200@mr28p48im-tydg10101201.me.com> for pgsql-admin@postgresql.org; Mon, 11 Jun 2018 19:05:13 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=04042017; t=1528743913; bh=fYN9VS8zkQ9Ps9FHKxnb24i60UO1I/lk9NdQogUtZDw=; h=From:Message-id:Content-type:MIME-version:Subject:Date:To; b=qhtxvguD+jV0cOwUCgoCGLmViMTH7a/qiOXqsNcLUDwQe1MaaJstvDok/VqwTekd+ mJS7YDamg3YsPaKPF8YvukQQz3Sp8CrFRfNkxub7EOmEb0r0J6gT37K/eHUfZ1TbQC KOvEYMbCPCCDfNZrZP6jsSSxMmo0xRaw2RLWU69h83XqLW5lbJcDwh7TV244XMV8m/ JvTNOLn4NvVwzYFsCVkxSdMN/B4Sj35o3h7hTQ3nT5INqNnJUCIrjaVYLPIN6yl8ZH 2CXIzhxXk5blosmmFuDJtZIX+KrtSeYPFgvtJ3lbnLu69vwXnqt5llYVB/WPGePKbj VnTFI1MfV4QCw== Received: from icloud.com ([127.0.0.1]) by mr28p48im-tydg10101201.me.com (Oracle Communications Messaging Server 8.0.1.2.20170607 64bit (built Jun 7 2017)) with ESMTPSA id <0PA600MIDACNOC30@mr28p48im-tydg10101201.me.com>; Mon, 11 Jun 2018 19:05:13 +0000 (GMT) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-06-11_09:,, signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 clxscore=1011 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1806110214 From: Rui DeSousa Message-id: Content-type: multipart/alternative; boundary="Apple-Mail=_DD4FE4FE-91D1-48F0-9A77-569DAB168041" MIME-version: 1.0 (Mac OS X Mail 11.4 \(3445.8.2\)) Subject: Re: pg_stat_activity Date: Mon, 11 Jun 2018 15:05:10 -0400 In-reply-to: Cc: Pavan Teja , Ron , pgsql-admin To: "David G. Johnston" References: <4405957b-2e0f-bfc5-eaf6-5e2864da2796@gmail.com> <9884a24a-c129-a1a9-1901-2a9c8987331e@gmail.com> X-Mailer: Apple Mail (2.3445.8.2) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --Apple-Mail=_DD4FE4FE-91D1-48F0-9A77-569DAB168041 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii 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=20 , 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=20 from pg_locks=20 where locktype =3D 'relation' and mode in ('RowExclusiveLock', 'ExclusiveLock')=20 ) order by pg_stat_activity.query_start ; --Apple-Mail=_DD4FE4FE-91D1-48F0-9A77-569DAB168041 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii
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 =3D = 'relation'
      and mode in = ('RowExclusiveLock', 'ExclusiveLock') 
  )
order by = pg_stat_activity.query_start
;


= --Apple-Mail=_DD4FE4FE-91D1-48F0-9A77-569DAB168041--