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

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

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

7 Steps to configure BDR replication in postgresql

Postgres Streaming Replication Configuration

vacuumlo - removing large objects orphans from a database PostgreSQL