Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Script For Finding slow Running Query and Most CPU Utilization Query Using Top command PID

This script is very useful after Issue top command you will get PID which one Process taken More CPU Utilization  example for  32696 is the most CPU utilization process means take the PID then run the following script it will prompt "Enter the value Of PID" then give PID as 32696 you will get query then take the explain plan for that particular query then do Performance Tuning.
bash-4.1$ cat givepid.sh
echo "Enter the value of PID";
read pid
$PSQL -d $DB -U $USER -p $PORT <<EOF
\pset format wrapped
SELECT now() - query_start as "runtime",state,query from pg_stat_activity WHERE pid= $pid;
exit 0;
Enter the value of PID
Output format is wrapped.
    runtime     | state  |                                                                       query
 00:00:01.93486 | active | select   timestatus::date from mhrornad_akl.edit_mut_new_audit WHERE ccode='270100010000760000' and report_status='Generated' and edit_mut_no=214
(1 row)


Popular posts from this blog

PostgreSQL pgBadger

PostgreSQL Pgbadger Installation On Linux

Script to kill ALL IDLE Connection In postgreSQL

How to configure Replication Manager (repmgr) ?

How To Schedule PostgreSQL Jobs using pgAgent on Linux plateform