Skip to content

Instantly share code, notes, and snippets.

@wagnerpinheiro
Created May 16, 2016 14:06
Show Gist options
  • Save wagnerpinheiro/2225b4e626cf5159c6ab185d23936225 to your computer and use it in GitHub Desktop.
Save wagnerpinheiro/2225b4e626cf5159c6ab185d23936225 to your computer and use it in GitHub Desktop.
#!/bin/bash
for ((;;)) do psql kangaroo postgresql -1 -t -c "SELECT now() as at_date, client_addr, substring(regexp_replace(trim(current_query), E'\r|\n', '', 'g'),0,100) as query, count(*) as qtd, case when count(*) > 50 then 'CRITICAL' else '' END as level FROM pg_locks pl LEFT JOIN pg_stat_activity psa ON pl.pid = psa.procpid where client_port > 0 group by client_addr, substring(regexp_replace(trim(current_query), E'\r|\n', '', 'g'),0,100)" >> /tmp/log_lock.log; sleep 1m; done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment