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

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

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

PostgreSQL Pgbadger Installation On Linux

PostgreSQL Database startup / shutdown /restart