From: | Rui DeSousa <rui(dot)desousa(at)icloud(dot)com> |
---|---|
To: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> |
Cc: | Pavan Teja <pavan(dot)postgresdba(at)gmail(dot)com>, Ron <ronljohnsonjr(at)gmail(dot)com>, pgsql-admin <pgsql-admin(at)postgresql(dot)org> |
Subject: | Re: pg_stat_activity |
Date: | 2018-06-11 19:05:10 |
Message-ID: | FC26C5E6-B0C6-46B5-9498-788CC05E7BBC@icloud.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-admin |
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
;
From | Date | Subject | |
---|---|---|---|
Next Message | Ahmed, Nawaz | 2018-06-11 21:43:41 | RE: pg_basebackup: could not get write-ahead log end position from server: ERROR |
Previous Message | Pavan Teja | 2018-06-11 18:18:27 | Re: PostgreSQL 'Corruption & Fragmentation' detection and resolution/fix |