title: postgresql "idle in transaction" with all locks granted
body: <p>A very simple delete (by key) on a small table (700 rows) every now and then stays "idle in transaction" for minutes (takes milliseconds usually) even though all the locks are marked as "granted".</p>
  
  <p>What can I do to pinpoint what causes it?
  I'm using this select:</p>
  
  <pre><code>  SELECT a.datname,
       c.relname,
       l.transactionid,
       l.mode,
       l.GRANTED,
       a.usename,
       a.waiting,
       a.query, 
       a.query_start,
       age(now(), a.query_start) AS "age", 
       a.pid 
  FROM  pg_stat_activity a
   JOIN pg_locks         l ON l.pid = a.pid
   JOIN pg_class         c ON c.oid = l.relation
  ORDER BY a.query_start;
  </code></pre>
  
  <p>which shows a lot of "RowExclusiveLock"s but all are granted... so I don't see what is causing this spikes of delays.</p>