#! /bin/bash
#List processes based on %cpu and memory usage
echo "Start Time" `date`
# By default, it display the list of processes based on the cpu and memory usage #
if [ $# -eq 0 ]
then
echo "List of processes based on the %cpu Usage"
ps -e -o pcpu,cpu,nice,state,cputime,args --sort pcpu # sorted based on %cpu
echo "List of processes based on the memory Usage"
ps -e -orss=,args= | sort -b -k1,1n # sorted bases rss value
# If arguements are given (mem/cpu)
else
case "$1" in
mem)
echo "List of processes based on the memory Usage"
ps -e -orss=,args= | sort -b -k1,1n
;;
cpu)
echo "List of processes based on the %cpu Usage"
ps -e -o pcpu,cpu,nice,state,cputime,args --sort pcpu
;;
*)
echo "Invalid Argument Given \n"
echo "Usage : $0 mem/cpu"
exit 1
esac
fi
echo "End Time" `date`
exit 0
===
$ processes.sh
$ processes.sh mem
$ processes.sh cpu
Search This Blog
Total Pageviews
Friday, 30 July 2010
who is using high CPU percentage
apt-amd-02:/home/anujs/Downloads # cat uniqU.sh
#! /bin/bash
w > /tmp/a
echo "Total number of unique users logged in currently"
cat /tmp/a| sed '1,2d' | awk '{print $1}' | uniq | wc -l
echo ""
echo "List of unique users logged in currently"
cat /tmp/a | sed '1,2d'| awk '{print $1}' | uniq
echo ""
echo "The user who is using high %cpu"
cat /tmp/a | sed '1,2d' | awk '$7 > maxuid { maxuid=$7; maxline=$0 }; END { print maxuid, maxline }'
echo ""
echo "List of users logged in and what they are doing"
cat /tmp/a
#! /bin/bash
w > /tmp/a
echo "Total number of unique users logged in currently"
cat /tmp/a| sed '1,2d' | awk '{print $1}' | uniq | wc -l
echo ""
echo "List of unique users logged in currently"
cat /tmp/a | sed '1,2d'| awk '{print $1}' | uniq
echo ""
echo "The user who is using high %cpu"
cat /tmp/a | sed '1,2d' | awk '$7 > maxuid { maxuid=$7; maxline=$0 }; END { print maxuid, maxline }'
echo ""
echo "List of users logged in and what they are doing"
cat /tmp/a
find out Free memory ( shell script )
$ cat mem.sh
#! /bin/bash
# Total memory space details
echo "Memory Space Details"
free -t -m | grep "Total" | awk '{ print "Total Memory space : "$2 " MB";
print "Used Memory Space : "$3" MB";
print "Free Memory : "$4" MB";
}'
echo "Swap memory Details"
free -t -m | grep "Swap" | awk '{ print "Total Swap space : "$2 " MB";
print "Used Swap Space : "$3" MB";
print "Free Swap : "$4" MB";
}'
#! /bin/bash
# Total memory space details
echo "Memory Space Details"
free -t -m | grep "Total" | awk '{ print "Total Memory space : "$2 " MB";
print "Used Memory Space : "$3" MB";
print "Free Memory : "$4" MB";
}'
echo "Swap memory Details"
free -t -m | grep "Swap" | awk '{ print "Total Swap space : "$2 " MB";
print "Used Swap Space : "$3" MB";
print "Free Swap : "$4" MB";
}'
Thursday, 29 July 2010
Oracle Tablespace free space and fragmentation
Script – Tablespace free space and fragmentation
set linesize 150
column tablespace_name format a20 heading 'Tablespace'
column sumb format 999,999,999
column extents format 9999
column bytes format 999,999,999,999
column largest format 999,999,999,999
column Tot_Size format 999,999 Heading 'Total| Size(Mb)'
column Tot_Free format 999,999,999 heading 'Total Free(MB)'
column Pct_Free format 999.99 heading '% Free'
column Chunks_Free format 9999 heading 'No Of Ext.'
column Max_Free format 999,999,999 heading 'Max Free(Kb)'
set echo off
PROMPT FREE SPACE AVAILABLE IN TABLESPACES
select a.tablespace_name,sum(a.tots/1048576) Tot_Size,
sum(a.sumb/1048576) Tot_Free,
sum(a.sumb)*100/sum(a.tots) Pct_Free,
sum(a.largest/1024) Max_Free,sum(a.chunks) Chunks_Free
from
(
select tablespace_name,0 tots,sum(bytes) sumb,
max(bytes) largest,count(*) chunks
from dba_free_space a
group by tablespace_name
union
select tablespace_name,sum(bytes) tots,0,0,0 from
dba_data_files
group by tablespace_name) a
group by a.tablespace_name
order by pct_free;
set linesize 150
column tablespace_name format a20 heading 'Tablespace'
column sumb format 999,999,999
column extents format 9999
column bytes format 999,999,999,999
column largest format 999,999,999,999
column Tot_Size format 999,999 Heading 'Total| Size(Mb)'
column Tot_Free format 999,999,999 heading 'Total Free(MB)'
column Pct_Free format 999.99 heading '% Free'
column Chunks_Free format 9999 heading 'No Of Ext.'
column Max_Free format 999,999,999 heading 'Max Free(Kb)'
set echo off
PROMPT FREE SPACE AVAILABLE IN TABLESPACES
select a.tablespace_name,sum(a.tots/1048576) Tot_Size,
sum(a.sumb/1048576) Tot_Free,
sum(a.sumb)*100/sum(a.tots) Pct_Free,
sum(a.largest/1024) Max_Free,sum(a.chunks) Chunks_Free
from
(
select tablespace_name,0 tots,sum(bytes) sumb,
max(bytes) largest,count(*) chunks
from dba_free_space a
group by tablespace_name
union
select tablespace_name,sum(bytes) tots,0,0,0 from
dba_data_files
group by tablespace_name) a
group by a.tablespace_name
order by pct_free;
Oracle IO Scripts ... very useful
Check IO Scripts
from Metalink
How To Calculate IOPS of an Oracle Database
V$SYSMETRIC – last 15 and 60 seconds
V$SYSMETRIC_SUMMARY – values last hour (last snapshot) like avg, max, min etc
V$SYSMETRIC_HISTORY – last hour for 1 minute, last 3 mintes for 15 second deltas
DBA_HIST_SYSMETRIC_SUMMARY – hour summaries for last week.
break on day
set pagesize 1000 linesize 5000
col day for a8
col metric_name for 30
select
to_char(begin_time,'DD-Mon') Day,
A.METRIC_NAME,
to_char(sum(decode(substr(to_char(BEGIN_TIME,'HH24'),1,2),'00',maxval,0)),'999999999999999') "00",
to_char(sum(decode(substr(to_char(BEGIN_TIME,'HH24'),1,2),'01',maxval,0)),'999999999999999') "01",
to_char(sum(decode(substr(to_char(BEGIN_TIME,'HH24'),1,2),'02',maxval,0)),'999999999999999') "02",
to_char(sum(decode(substr(to_char(BEGIN_TIME,'HH24'),1,2),'03',maxval,0)),'999999999999999') "03",
to_char(sum(decode(substr(to_char(BEGIN_TIME,'HH24'),1,2),'04',maxval,0)),'999999999999999') "04",
to_char(sum(decode(substr(to_char(BEGIN_TIME,'HH24'),1,2),'05',maxval,0)),'999999999999999') "05",
to_char(sum(decode(substr(to_char(BEGIN_TIME,'HH24'),1,2),'06',maxval,0)),'999999999999999') "06",
to_char(sum(decode(substr(to_char(BEGIN_TIME,'HH24'),1,2),'07',maxval,0)),'999999999999999') "07",
to_char(sum(decode(substr(to_char(BEGIN_TIME,'HH24'),1,2),'08',maxval,0)),'999999999999999') "08",
to_char(sum(decode(substr(to_char(BEGIN_TIME,'HH24'),1,2),'09',maxval,0)),'999999999999999') "09",
to_char(sum(decode(substr(to_char(BEGIN_TIME,'HH24'),1,2),'10',maxval,0)),'999999999999999') "10",
to_char(sum(decode(substr(to_char(BEGIN_TIME,'HH24'),1,2),'11',maxval,0)),'999999999999999') "11",
to_char(sum(decode(substr(to_char(BEGIN_TIME,'HH24'),1,2),'12',maxval,0)),'999999999999999') "12",
to_char(sum(decode(substr(to_char(BEGIN_TIME,'HH24'),1,2),'13',maxval,0)),'999999999999999') "13",
to_char(sum(decode(substr(to_char(BEGIN_TIME,'HH24'),1,2),'14',maxval,0)),'999999999999999') "14",
to_char(sum(decode(substr(to_char(BEGIN_TIME,'HH24'),1,2),'15',maxval,0)),'999999999999999') "15",
to_char(sum(decode(substr(to_char(BEGIN_TIME,'HH24'),1,2),'16',maxval,0)),'999999999999999') "16",
to_char(sum(decode(substr(to_char(BEGIN_TIME,'HH24'),1,2),'17',maxval,0)),'999999999999999') "17",
to_char(sum(decode(substr(to_char(BEGIN_TIME,'HH24'),1,2),'18',maxval,0)),'999999999999999') "18",
to_char(sum(decode(substr(to_char(BEGIN_TIME,'HH24'),1,2),'19',maxval,0)),'999999999999999') "19",
to_char(sum(decode(substr(to_char(BEGIN_TIME,'HH24'),1,2),'20',maxval,0)),'999999999999999') "20",
to_char(sum(decode(substr(to_char(BEGIN_TIME,'HH24'),1,2),'21',maxval,0)),'999999999999999') "21",
to_char(sum(decode(substr(to_char(BEGIN_TIME,'HH24'),1,2),'22',maxval,0)),'999999999999999') "22",
to_char(sum(decode(substr(to_char(BEGIN_TIME,'HH24'),1,2),'23',maxval,0)),'999999999999999') "23"
from dba_hist_sysmetric_summary A
where
A.METRIC_NAME in
('Host CPU Utilization (%)',
'Average Active Sessions',
'Session Count',
'SQL Service Response Time',
'User Transaction Per Sec',
'Temp Space Used',
'Total PGA Allocated'
)
and BEGIN_TIME > trunc(sysdate) - 7
group by A.METRIC_NAME, to_char(begin_time,'DD-Mon')
order by to_char(begin_time,'DD-Mon'),a.metric_name ;
08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23
-------- ---------------------------------------------------------------- ---------------- ---------------- ---------------- ---------------- ---------------- ---------------- ---------------- ---------------- ---------------- ---------------- ---------------- ---------------- ---------------- ---------------- ---------------- ---------------- ---------------- ---------------- ---------------- ---------------- ---------------- ---------------- ---------------- ----------------
19-Jan Average Active Sessions 37 32 32 32 33 32 32 32 32 32 32 32 32 32 32 32 31 32 32 32 32 38 34 32
set linesize 500
col day for a11
select
to_char(begin_time,'DD-MON-YY') Day,
round(max(decode(to_char(begin_time,'HH24'),'00',maxval,NULL)),2) "00",
round(max(decode(to_char(begin_time,'HH24'),'01',maxval,NULL)),2) "01",
round(max(decode(to_char(begin_time,'HH24'),'02',maxval,NULL)),2) "02",
round(max(decode(to_char(begin_time,'HH24'),'03',maxval,NULL)),2) "03",
round(max(decode(to_char(begin_time,'HH24'),'04',maxval,NULL)),2) "04",
round(max(decode(to_char(begin_time,'HH24'),'05',maxval,NULL)),2) "05",
round(max(decode(to_char(begin_time,'HH24'),'06',maxval,NULL)),2) "06",
round(max(decode(to_char(begin_time,'HH24'),'07',maxval,NULL)),2) "07",
round(max(decode(to_char(begin_time,'HH24'),'08',maxval,NULL)),2) "08",
round(max(decode(to_char(begin_time,'HH24'),'09',maxval,NULL)),2) "09",
round(max(decode(to_char(begin_time,'HH24'),'10',maxval,NULL)),2) "10",
round(max(decode(to_char(begin_time,'HH24'),'11',maxval,NULL)),2) "11",
round(max(decode(to_char(begin_time,'HH24'),'12',maxval,NULL)),2) "12",
round(max(decode(to_char(begin_time,'HH24'),'13',maxval,NULL)),2) "13",
round(max(decode(to_char(begin_time,'HH24'),'14',maxval,NULL)),2) "14",
round(max(decode(to_char(begin_time,'HH24'),'15',maxval,NULL)),2) "15",
round(max(decode(to_char(begin_time,'HH24'),'16',maxval,NULL)),2) "16",
round(max(decode(to_char(begin_time,'HH24'),'17',maxval,NULL)),2) "17",
round(max(decode(to_char(begin_time,'HH24'),'18',maxval,NULL)),2) "18",
round(max(decode(to_char(begin_time,'HH24'),'19',maxval,NULL)),2) "19",
round(max(decode(to_char(begin_time,'HH24'),'20',maxval,NULL)),2) "20",
round(max(decode(to_char(begin_time,'HH24'),'21',maxval,NULL)),2) "21",
round(max(decode(to_char(begin_time,'HH24'),'21',maxval,NULL)),2) "22",
round(max(decode(to_char(begin_time,'HH24'),'21',maxval,NULL)),2) "23"
from dba_hist_sysmetric_SUMMARY A where BEGIN_TIME > sysdate - 7
and A.METRIC_NAME in('Average Active Sessions') group by to_char(begin_time,'DD-MON-YY')
/
set lines 500 pages 50000
alter session set nls_date_format='dd-mm-yyyy hh24:mi';
col Phys_Read_Total_Bps for 999999999999
col Phys_Write_Total_Bps for 999999999999
col Redo_Bytes_per_sec for 999999999999
col Phys_Read_IOPS for 999999999999
col Phys_write_IOPS for 999999999999
col Phys_redo_IOPS for 999999999999
col OS_LOad for 999999999999
col DB_CPU_Usage_per_sec for 999999999999
col Host_CPU_util for 999999999999
col Network_bytes_per_sec for 999999999999
col Phys_IO_Tot_MBps for 999999999999
col Phys_IOPS_Tot for 999999999999
spool io_max_checkup.log
select min(begin_time), max(end_time),
sum(case metric_name when 'Physical Read Total Bytes Per Sec' then maxval end) Phys_Read_Tot_Bps,
sum(case metric_name when 'Physical Write Total Bytes Per Sec' then maxval end) Phys_Write_Tot_Bps,
sum(case metric_name when 'Redo Generated Per Sec' then maxval end) Redo_Bytes_per_sec,
sum(case metric_name when 'Physical Read Total IO Requests Per Sec' then maxval end) Phys_Read_IOPS,
sum(case metric_name when 'Physical Write Total IO Requests Per Sec' then maxval end) Phys_write_IOPS,
sum(case metric_name when 'Redo Writes Per Sec' then maxval end) Phys_redo_IOPS,
sum(case metric_name when 'Current OS Load' then maxval end) OS_LOad,
sum(case metric_name when 'CPU Usage Per Sec' then maxval end) DB_CPU_Usage_per_sec,
sum(case metric_name when 'Host CPU Utilization (%)' then maxval end) Host_CPU_util, --NOTE 100% = 1 loaded RAC node
sum(case metric_name when 'Network Traffic Volume Per Sec' then maxval end) Network_bytes_per_sec,
snap_id
from dba_hist_sysmetric_summary
group by snap_id
order by snap_id;
select min(begin_time), max(end_time),
sum(case metric_name when 'Physical Read Total Bytes Per Sec' then maxval end)/1024/1024 +
sum(case metric_name when 'Physical Write Total Bytes Per Sec' then maxval end)/1024/1024 +
sum(case metric_name when 'Redo Generated Per Sec' then maxval end)/1024/1024 Phys_IO_Tot_MBps,
sum(case metric_name when 'Physical Read Total IO Requests Per Sec' then maxval end) +
sum(case metric_name when 'Physical Write Total IO Requests Per Sec' then maxval end) +
sum(case metric_name when 'Redo Writes Per Sec' then maxval end) Phys_IOPS_Tot,
sum(case metric_name when 'Current OS Load' then maxval end) OS_LOad,
sum(case metric_name when 'CPU Usage Per Sec' then maxval end) DB_CPU_Usage_per_sec,
sum(case metric_name when 'Host CPU Utilization (%)' then maxval end) Host_CPU_util, --NOTE 100% = 1 loaded RAC node
sum(case metric_name when 'Network Traffic Volume Per Sec' then maxval end) Network_bytes_per_sec,
snap_id
from dba_hist_sysmetric_summary
group by snap_id
order by snap_id;
spool off
spool io_maxtot_summary.log
Saturday, 24 July 2010
Primary key validation for new rows only ......
Anuj:orcl>create table test ( a number );
Table created.
Anuj:orcl>insert into test ( a ) values ( 1 ) ;
1 row created.
Anuj:orcl>/
1 row created.
Anuj:orcl>/
1 row created.
Anuj:orcl>insert into test ( a ) values (2 ) ;
1 row created.
Anuj:orcl>alter table test add constraint test_pk primary key ( a ) novalidate ;
alter table test add constraint test_pk primary key ( a ) novalidate
*
ERROR at line 1:
ORA-02437: cannot validate (SYS.test_PK) - primary key violated
Anuj:orcl>create index test_i on test ( a );
Index created.
Anuj:orcl>alter table test add constraint test_pk primary key ( a ) novalidate ;
Table altered.
Anuj:orcl>select * from test ;
A
----------
1
1
1
2
Anuj:orcl>insert into test ( a ) values (2 ) ;
insert into test ( a ) values (2 )
*
ERROR at line 1:
ORA-00001: unique constraint (SYS.test_PK) violated
Table created.
Anuj:orcl>insert into test ( a ) values ( 1 ) ;
1 row created.
Anuj:orcl>/
1 row created.
Anuj:orcl>/
1 row created.
Anuj:orcl>insert into test ( a ) values (2 ) ;
1 row created.
Anuj:orcl>alter table test add constraint test_pk primary key ( a ) novalidate ;
alter table test add constraint test_pk primary key ( a ) novalidate
*
ERROR at line 1:
ORA-02437: cannot validate (SYS.test_PK) - primary key violated
Anuj:orcl>create index test_i on test ( a );
Index created.
Anuj:orcl>alter table test add constraint test_pk primary key ( a ) novalidate ;
Table altered.
Anuj:orcl>select * from test ;
A
----------
1
1
1
2
Anuj:orcl>insert into test ( a ) values (2 ) ;
insert into test ( a ) values (2 )
*
ERROR at line 1:
ORA-00001: unique constraint (SYS.test_PK) violated
Friday, 16 July 2010
Oracle 10g when transactions will finish rolling back
select sum(distinct(ktuxesiz)) from x$ktuxe; value should be very less ....
@rollback_active.sql
set serveroutput on
set feedback off
prompt
prompt transactions that are rolling back ...
prompt
declare
cursor tx is
select
s.username,
t.xidusn,
t.xidslot,
t.xidsqn,
x.ktuxesiz
from
sys.x$ktuxe x,
sys.v_$transaction t,
sys.v_$session s
where
x.inst_id = userenv('Instance') and
x.ktuxesta = 'ACTIVE' and
x.ktuxesiz > 1 and
t.xidusn = x.ktuxeusn and
t.xidslot = x.ktuxeslt and
t.xidsqn = x.ktuxesqn and
s.saddr = t.ses_addr;
user_name varchar2(30);
xid_usn number;
xid_slot number;
xid_sqn number;
used_ublk1 number;
used_ublk2 number;
begin
open tx;
loop
fetch tx into user_name, xid_usn, xid_slot, xid_sqn, used_ublk1;
exit when tx%notfound;
if tx%rowcount = 1
then
sys.dbms_lock.sleep(10);
end if;
select
sum(ktuxesiz)
into
used_ublk2
from
sys.x$ktuxe
where
inst_id = userenv('Instance') and
ktuxeusn = xid_usn and
ktuxeslt = xid_slot and
ktuxesqn = xid_sqn and
ktuxesta = 'ACTIVE';
if used_ublk2 < used_ublk1
then
sys.dbms_output.put_line(
user_name ||
'''s transaction ' ||
xid_usn || '.' ||
xid_slot || '.' ||
xid_sqn ||
' will finish rolling back at approximately ' ||
to_char(
sysdate + used_ublk2 / (used_ublk1 - used_ublk2) / 6 / 60 / 24,
'HH24:MI:SS DD-MON-YYYY'
)
);
end if;
end loop;
if user_name is null
then
sys.dbms_output.put_line('No transactions appear to be rolling back.');
end if;
end;
/
@rollback_active.sql
set serveroutput on
set feedback off
prompt
prompt transactions that are rolling back ...
prompt
declare
cursor tx is
select
s.username,
t.xidusn,
t.xidslot,
t.xidsqn,
x.ktuxesiz
from
sys.x$ktuxe x,
sys.v_$transaction t,
sys.v_$session s
where
x.inst_id = userenv('Instance') and
x.ktuxesta = 'ACTIVE' and
x.ktuxesiz > 1 and
t.xidusn = x.ktuxeusn and
t.xidslot = x.ktuxeslt and
t.xidsqn = x.ktuxesqn and
s.saddr = t.ses_addr;
user_name varchar2(30);
xid_usn number;
xid_slot number;
xid_sqn number;
used_ublk1 number;
used_ublk2 number;
begin
open tx;
loop
fetch tx into user_name, xid_usn, xid_slot, xid_sqn, used_ublk1;
exit when tx%notfound;
if tx%rowcount = 1
then
sys.dbms_lock.sleep(10);
end if;
select
sum(ktuxesiz)
into
used_ublk2
from
sys.x$ktuxe
where
inst_id = userenv('Instance') and
ktuxeusn = xid_usn and
ktuxeslt = xid_slot and
ktuxesqn = xid_sqn and
ktuxesta = 'ACTIVE';
if used_ublk2 < used_ublk1
then
sys.dbms_output.put_line(
user_name ||
'''s transaction ' ||
xid_usn || '.' ||
xid_slot || '.' ||
xid_sqn ||
' will finish rolling back at approximately ' ||
to_char(
sysdate + used_ublk2 / (used_ublk1 - used_ublk2) / 6 / 60 / 24,
'HH24:MI:SS DD-MON-YYYY'
)
);
end if;
end loop;
if user_name is null
then
sys.dbms_output.put_line('No transactions appear to be rolling back.');
end if;
end;
/
Subscribe to:
Posts (Atom)
Oracle DBA
anuj blog Archive
- ► 2011 (362)
