Skip to main content
Recent Posts
8
PostgreSQL / Re: MISC Queries
Last post by tino -
Show running queries (9.2)

Code: [Select]
SELECT pid, age(query_start, clock_timestamp()), usename, query 
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;

kill running query
Code: [Select]
SELECT pg_cancel_backend(procpid);

Kill idle query
Code: [Select]
SELECT pg_terminate_backend(procpid);
9
PostgreSQL / MISC Queries
Last post by tino -
Compare two rows

Code: [Select]
SELECT T1.log_dt, T2.log_dt, EXTRACT(EPOCH FROM (T2.log_dt - T1.log_dt))
FROM power_data AS T1
INNER JOIN power_data  AS T2
USING ( node )
WHERE T1.log_dt > '2017-05-05 22:10:00'
AND T2.log_dt > '2017-05-05 22:10:00'
ORDER BY T1.id, T2.id
LIMIT 2