Running Queries and Lock Status

```

SELECT
  S.pid,
  age(clock_timestamp(), query_start),
  usename,
  query,
  L.mode,
  L.locktype,
  L.granted
FROM pg_stat_activity S
inner join pg_locks L on S.pid = L.pid 
order by L.granted, L.pid DESC;

  pid  |       age       |     usename      |                                          query                                           |       mode       |  locktype  | granted
-------+-----------------+------------------+------------------------------------------------------------------------------------------+------------------+------------+---------
 26679 | 00:00:00.000598 | bobsmith         |                                                                                         +| AccessShareLock  | relation   | t
       |                 |                  |             DELETE FROM django_session WHERE session_key = ANY(ARRAY(                   +|                  |            |
       |                 |                  |                 SELECT                                                                  +|                  |            |
       |                 |                  |                     session_key                                                         +|                  |            |
       |                 |                  |                 FROM django_session ds                                                  +|                  |            |
       |                 |                  |                 WHERE expire_date <= '2021-07-12T01:07:52.415734'::timestamp LIMIT 50000+|                  |            |
       |                 |                  |             ))                                                                           |                  |            |


Also of use

SELECT * FROM pg_stat_activity WHERE state = ‘active’ and wait_event_type = ‘Lock’;