- SELECT INTO v_blk_xact extract(EPOCH FROM current_timestamp-ba.xact_start) AS blk_runtime,
- b.pid AS blk_pid,
- ba.usename AS blk_usename,
- COALESCE(ba.application_name,'[unknown]') as blk_app,
- COALESCE(ba.client_addr || ':' || ba.client_port, '[local]') AS blk_client,
- ba.current_query AS blk_query,
- COALESCE(t.schemaname || '.' || t.relname || ' (' || b.mode || ')', bt.locks, '[unknown]') AS blk_relation,
- CASE b.locktype WHEN 'transactionid' THEN 'transaction id ' || b.transactionid ELSE b.locktype END AS blk_type
- FROM pg_catalog.pg_locks l
- LEFT JOIN pg_catalog.pg_locks b ON b.granted
- AND ((b.locktype = 'transactionid' AND b.transactionid = l.transactionid) OR (b.locktype = 'relation' AND b.relation = l.relation))
- AND b.pid != l.pid
- LEFT JOIN pg_catalog.pg_stat_activity ba ON ba.procpid = b.pid
- LEFT JOIN pg_catalog.pg_stat_user_tables t ON l.relation = t.relid
- LEFT JOIN (SELECT pid, 'any (' || string_agg(schemaname || '.' || relname || ' (' || mode || ')',', ') || ')' AS locks
- FROM pg_locks JOIN pg_stat_user_tables ON relation = relid
- WHERE mode ~ 'ExclusiveLock'
- GROUP BY pid) bt ON bt.pid = b.pid
- WHERE l.pid = v_xact.pid AND NOT l.granted LIMIT 1;
+ IF (v_srv_version < 9.2) THEN
+ SELECT INTO v_blk_xact extract(EPOCH FROM current_timestamp-ba.xact_start) AS blk_runtime,
+ b.pid AS blk_pid,
+ ba.usename AS blk_usename,
+ COALESCE(ba.application_name,'[unknown]') as blk_app,
+ COALESCE(ba.client_addr || ':' || ba.client_port, '[local]') AS blk_client,
+ ba.current_query AS blk_query,
+ '[not supported]' AS blk_state,
+ COALESCE(t.schemaname || '.' || t.relname || ' (' || b.mode || ')', bt.locks, '[unknown]') AS blk_relation,
+ CASE b.locktype WHEN 'transactionid' THEN 'transaction id ' || b.transactionid ELSE b.locktype END AS blk_type
+ FROM pg_catalog.pg_locks l
+ LEFT JOIN pg_catalog.pg_locks b ON b.granted
+ AND ((b.locktype = 'transactionid' AND b.transactionid = l.transactionid) OR (b.locktype = 'relation' AND b.relation = l.relation))
+ AND b.pid != l.pid
+ LEFT JOIN pg_catalog.pg_stat_activity ba ON ba.procpid = b.pid
+ LEFT JOIN pg_catalog.pg_stat_user_tables t ON l.relation = t.relid
+ LEFT JOIN (SELECT pid, 'any (' || string_agg(schemaname || '.' || relname || ' (' || mode || ')',', ') || ')' AS locks
+ FROM pg_locks JOIN pg_stat_user_tables ON relation = relid
+ WHERE mode ~ 'ExclusiveLock'
+ GROUP BY pid) bt ON bt.pid = b.pid
+ WHERE l.pid = v_xact.pid AND NOT l.granted LIMIT 1;
+ ELSE
+ SELECT INTO v_blk_xact extract(EPOCH FROM current_timestamp-ba.xact_start) AS blk_runtime,
+ b.pid AS blk_pid,
+ ba.usename AS blk_usename,
+ COALESCE(ba.application_name,'[unknown]') as blk_app,
+ COALESCE(ba.client_addr || ':' || ba.client_port, '[local]') AS blk_client,
+ ba.query AS blk_query,
+ ba.state AS blk_state,
+ COALESCE(t.schemaname || '.' || t.relname || ' (' || b.mode || ')', bt.locks, '[unknown]') AS blk_relation,
+ CASE b.locktype WHEN 'transactionid' THEN 'transaction id ' || b.transactionid ELSE b.locktype END AS blk_type
+ FROM pg_catalog.pg_locks l
+ LEFT JOIN pg_catalog.pg_locks b ON b.granted
+ AND ((b.locktype = 'transactionid' AND b.transactionid = l.transactionid) OR (b.locktype = 'relation' AND b.relation = l.relation))
+ AND b.pid != l.pid
+ LEFT JOIN pg_catalog.pg_stat_activity ba ON ba.pid = b.pid
+ LEFT JOIN pg_catalog.pg_stat_user_tables t ON l.relation = t.relid
+ LEFT JOIN (SELECT pid, 'any (' || string_agg(schemaname || '.' || relname || ' (' || mode || ')',', ') || ')' AS locks
+ FROM pg_locks JOIN pg_stat_user_tables ON relation = relid
+ WHERE mode ~ 'ExclusiveLock'
+ GROUP BY pid) bt ON bt.pid = b.pid
+ WHERE l.pid = v_xact.pid AND NOT l.granted LIMIT 1;
+ END IF;