New Feature: Show locks for a single query analyzed with EXPLAIN
What to do:
add to joe report of the locks obtained by the analysed query
How to implement:
start transaction, execute given query, query pg_locks (not closing transaction), close transaction:
BEGIN
-- Run the analysed query
-- Check which locks are taken
COMMIT
query to get locks data
SELECT l.relation::regclass,
c.relkind,
l.locktype,
l.mode,
l.granted,
l.fastpath
FROM pg_locks l
JOIN pg_class c ON c.oid=l.relation
JOIN pg_stat_activity a on l.pid = a.pid
AND a.query NOT ILIKE '%pg_stat_activity%'
ORDER BY l.relation ASC;
expected result - something like this
+---------------------------------------+---------+----------+-----------------+---------+----------+
| relation | relkind | locktype | mode | granted | fastpath |
----------------------------------------+---------+----------+-----------------+---------+----------+
| pg_authid | r | relation | AccessShareLock | t | f |
| pg_database | r | relation | AccessShareLock | t | f |
+---------------------------------------+---------+----------+-----------------+---------+----------+
UPDATE 2023-07-19: we decided to change the algorithm to avoid observer effects:
begin;
-- Anayze query – with or without execution
-- Get the info about locks form pg_locks, using a different connection (!) to avoid additional locks
commi;
Edited by Nikolay Samokhvalov