How to get list long running processes in PostgreSQL

Why processes(sql queries) takes long time?

1. Table(object) not designed properly
2. Memory issues
3. Table Scan
4. Others

How to get list long running processes in PostgreSQL

We can get this information from pg_stat_activity object.

Following query gives logn running process, on which database it is running, start time of pid(process id) and sql text(query) the pid.

postgres=# SELECT datname,pid, xact_start, state,query FROM pg_stat_activity; datname | pid | xact_start | state | query ----------+------+----------------------------------+--------+-------------------------------------------------------------------- postgres | 9016 | 2017-10-17 05:19:27.885612+05:30 | active | SELECT datname,pid, xact_start, state,query FROM pg_stat_activity;

Following query gives the pid(process id) on which database it is running and What is running.

postgres=# SELECT datname,pid,state,query FROM pg_stat_activity; datname | pid | state | query ----------+------+--------+------------------------------------------------------- postgres | 9016 | active | SELECT datname,pid,state,query FROM pg_stat_activity;

(1 row)

Following query returns the start time of pids.

postgres=# SELECT pid, xact_start FROM pg_stat_activity ORDER BY xact_start ASC; pid | xact_start ------+---------------------------------- 9016 | 2017-10-17 05:06:09.012831+05:30

CheapSexCams
Responses are currently closed, but you can trackback from your own site.

Comments are closed.

Powered by k2schools
%d bloggers like this: