-- Get active queries with duration greater than 1 sec 
SELECT (now() - query_start) as duracao, pid, query, usename, datname
FROM pg_stat_activity 
WHERE state = 'active'
AND query_start < now() - '1 seconds'::interval
AND pid <> pg_backend_pid() 
ORDER BY query_start ASC