Para las versiones de Postgres 9.2 o superiores podéis crear una vista que facilitará la consulta de los procesos que actualmente tiene bloqueos en vuestro sistema:
CREATE OR REPLACE VIEW public.procesos_bloqueantes(
blocking_pid,
blocking_user,
blocking_query,
blocked_pid,
blocked_user,
blocked_query,
age)
AS
SELECT kl.pid AS blocking_pid,
ka.usename AS blocking_user,
ka.query AS blocking_query,
bl.pid AS blocked_pid,
a.usename AS blocked_user,
a.query AS blocked_query,
to_char(age(now(), a.query_start), 'HH24h:MIm:SSs' ::text) AS age
FROM pg_locks bl
JOIN pg_stat_activity a ON bl.pid = a.pid
JOIN pg_locks kl ON bl.locktype = kl.locktype AND NOT bl.database IS
DISTINCT
FROM kl.database AND NOT bl.relation IS DISTINCT
FROM kl.relation AND NOT bl.page IS DISTINCT
FROM kl.page AND NOT bl.tuple IS DISTINCT
FROM kl.tuple AND NOT bl.virtualxid IS DISTINCT
FROM kl.virtualxid AND NOT bl.transactionid IS DISTINCT
FROM kl.transactionid AND NOT bl.classid IS DISTINCT
FROM kl.classid AND NOT bl.objid IS DISTINCT
FROM kl.objid AND NOT bl.objsubid IS DISTINCT
FROM kl.objsubid AND bl.pid <> kl.pid
JOIN pg_stat_activity ka ON kl.pid = ka.pid
WHERE kl.granted AND
NOT bl.granted
ORDER BY a.query_start;
Una vez localizados los procesos que están produciendo el bloqueo y que sentencia están ejecutando, podemos tomar la decisión de eliminarlos si llevan demasiado tiempo en ejecución y no nos importa perder él resultado de la acción que estaban ejecutando. El identificador de proceso a matar es el "blocking_id" de la vista:
select pg_cancel_backend ( blocking_pid );
No hay comentarios:
Publicar un comentario