How it works…

The query is relatively simple: we just introduced the pg_blocking_pids() function, which returns an array composed by the PIDs of all the sessions that are blocking the session with the given PID.