Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

PostgreSQL Script for what Query is running more than x minutes with status

This script is useful for what are the query is running more than 'x' minutes(your input values) and that query status,you can list out the query as per your timing and query status
bash-4.1$ cat bash-4.1$
echo "Enter the Timing(minutes) for listing active query";
read time
echo "Enter the Query status Example for idle, idle in transaction, idle in transaction (aborted), disabled";
read status

$PSQL -d $DB -U $USER -p $PORT <<EOF
\pset format wrapped
SELECT pid, now() - query_start as "runtime", usename, datname, waiting, state, query
  FROM  pg_stat_activity
  WHERE now() - query_start > '$time minutes'::interval and state = '$status'
 ORDER BY runtime DESC;
exit 0; 
bash-4.1$ sh active.sh
Enter the Timing(minutes) for listing active query
Enter the Query status Example for idle, idle in transaction, idle in transaction (aborted), disabled
Output format is wrapped.
 pid  |     runtime     |  usename  | datname  | waiting | state  |                                                              query
 5046 | 00:02:35.347025 | emutation | mhrornad | f       | active | SELECT * FROM mhrornad_nad.bulk_data(((E'270100050007440000')::text), ((E'21')::text), ((E'1')::text), ((E'2')::text), ((E'74'):.
      |                 |           |          |         |        |.:text), ((E'ब.')::text), ((E'')::text), ((E'')::text), ((E'')::text), ((E'')::text))
(1 row)


Popular posts from this blog

How to find the server is whether standby (slave) or primary(master) in Postgresql replication ?

7 Steps to configure BDR replication in postgresql

How to Get Table Size, Database Size, Indexes Size, schema Size, Tablespace Size, column Size in PostgreSQL Database

Ora2PG - Oracle/MySQL to Postgres DB migration Version 20.0

PostgreSQL Introduction