Link to home
Start Free TrialLog in
Avatar of Chakravarthi Ayyala
Chakravarthi AyyalaFlag for United States of America

asked on

What is Oracle's v$session_longops equivalent in Postgres?

Trying to understand if there is an equivalent pg view in Postgres, which is similar to v$session_longops in Oracle.

Avatar of lcohan
lcohan
Flag of Canada image

You can find long running queries in postgres by running a script like belor:


SELECT
  pid,
  user,
  pg_stat_activity.query_start,
  now() - pg_stat_activity.query_start AS query_time,
  query,
  state,
  wait_event_type,
  wait_event
FROM pg_stat_activity
WHERE (now() - pg_stat_activity.query_start) > interval '5 minutes';

Open in new window

where you can change the << '5 >> minutes interval to whatever you wish like << "10  >> for 10seconds etc...


https://www.shanelynn.ie/postgresql-find-slow-long-running-and-blocked-queries/


The query below should give a list with all executing/running queries including their runtime:

SELECT pid, age(clock_timestamp(), query_start), datname, usename, query, state
FROM pg_stat_activity
WHERE state NOT LIKE 'idle%' AND query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;

Open in new window

Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

That query will show you how long a query has been running.

I'm not sure Postgres has the other information contained in v$session_longops.  Definitely have never seen anything like TIME_REMAINING in Postgres.

Some of the other columns might be obtained from other queries.
ASKER CERTIFIED SOLUTION
Avatar of Tomas Helgi Johannsson
Tomas Helgi Johannsson
Flag of Iceland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial