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

PostgreSQL Database startup / shutdown /restart

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

2017 Shortern URL - Other Website Like ADFOC.US

ORA-01261: Parameter db_recovery_file_dest destination string cannot be translated ORA-01262: Stat failed on a file destination directory Linux-x86_64 Error: 2: No such file or directory

PostgreSQL Pgbadger Installation On Linux