Subject: Wiki editor request

From: Andrew Morris <[email-masked]>
Date: Wed, 6 Dec 2023 13:56:46 +0800

I would like editor access to the wiki, my username is amorris and I would like to modify https://wiki.postgresql.org/wiki/Lock_Monitoring

The existing query:
  SELECT blocked_locks.pid     AS blocked_pid,
         blocked_activity.usename  AS blocked_user,
         blocking_locks.pid     AS blocking_pid,
         blocking_activity.usename AS blocking_user,
         blocked_activity.query    AS blocked_statement,
         blocking_activity.query   AS current_statement_in_blocking_process
   FROM  pg_catalog.pg_locks         blocked_locks
    JOIN pg_catalog.pg_stat_activity blocked_activity  ON blocked_activity.pid = blocked_locks.pid
    JOIN pg_catalog.pg_locks         blocking_locks 
        ON blocking_locks.locktype = blocked_locks.locktype
        AND blocking_locks.database IS NOT DISTINCT FROM blocked_locks.database
        AND blocking_locks.relation IS NOT DISTINCT FROM blocked_locks.relation
        AND blocking_locks.page IS NOT DISTINCT FROM blocked_locks.page
        AND blocking_locks.tuple IS NOT DISTINCT FROM blocked_locks.tuple
        AND blocking_locks.virtualxid IS NOT DISTINCT FROM blocked_locks.virtualxid
        AND blocking_locks.transactionid IS NOT DISTINCT FROM blocked_locks.transactionid
        AND blocking_locks.classid IS NOT DISTINCT FROM blocked_locks.classid
        AND blocking_locks.objid IS NOT DISTINCT FROM blocked_locks.objid
        AND blocking_locks.objsubid IS NOT DISTINCT FROM blocked_locks.objsubid
        AND blocking_locks.pid != blocked_locks.pid
    JOIN pg_catalog.pg_stat_activity blocking_activity ON blocking_activity.pid = blocking_locks.pid
   WHERE NOT blocked_locks.granted;

does not work for cases where there are multiple transactions, it starts reporting additional bloced/blocking pairs that don't exist!

I have the following query that works for simple and complex cases with multiple transactions blocked by the same transaction:

SELECT
    blocker.pid AS blocker_id,
    blocker.datname AS blocker_db,
    blocker.application_name AS blocker_app,
    blocker.xact_start AS blocker_tx_start,
    blocker.query AS blocker_cur_query,
    --
    blocked.pid as blocked_pid,
    blocked.datname as blocked_db,
    blocked.application_name AS blocked_app,
    now() - blocked.query_start AS blocked_duration, 
    blocked.query as blocked_query
FROM pg_stat_activity AS blocked
JOIN pg_stat_activity AS blocker ON blocker.pid = ANY(pg_blocking_pids(blocked.pid))
order by blocked_duration desc;

---

From: Joe Conway <[email-masked]>
Date: Thu, 7 Dec 2023 08:00:05 -0500

On 12/6/23 00:56, Andrew Morris wrote:
> I would like editor access to the wiki

I have expedited your cooling off period. Please log into the wiki once 
and reply-all to this email letting us know that you have done so. At 
that point we can grant editor.

-- 
Joe Conway
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com