select now()-query_start as cost_time,* from pg_stat_activity where current_query not in ( '<IDLE>','<insufficient privilege>') and waiting='f' order by waiting,cost_time DESC;