Scripts DBA
Scripts DBA
select o.object_name,l.oracle_username,l.os_user_name,l.session_id
,decode(l.locked_mode,2,'Row-S',3,'Row-X',4,'Share',5,'S/Row-X',6
,'Exclusive','NULL')
from user_objects o , v$locked_object l
where o.object_id = l.object_id;
Description: This script will display the active user and the rollback segment
being used in the database
SELECT r.name rr,
nvl(s.username,'no transaction') us,
s.osuser os,
s.terminal te
FROM
v$lock l,
v$session s,
v$rollname r
WHERE
l.sid = s.sid(+) AND
trunc(l.id1/65536) = r.usn AND
l.type = 'TX' AND
l.lmode = 6
ORDER BY r.name
This script reports how many hours it has been since the rollback segments wrapped
select n.name,
round(24*(sysdate-to_date(i1.value||' '||i2.value,'j SSSSS')) /
(s.writes/s.rssize),1) "Hours"
from v$instance i1,
v$instance i2,
v$rollname n,
v$rollstat s
where
i1.key = 'STARTUP TIME - JULIAN'
and i2.key = 'STARTUP TIME - SECONDS'
and n.usn = s.usn
and s.status = 'ONLINE'
Gives lots of usefull easy to read info on how your RBS are performing. Needs 132
char display
select name,
XACTS,
initial_extent/1048576 InitExt,
next_extent/1048576 NextExt,
min_extents MinExt,
max_extents MaxExt,
optsize/1048576 optsize,
RSSIZE/1048576 rssize,
HWMSIZE/1048576 hwmsize,
wraps,
extends,
shrinks,
aveshrink/1048576 aveshrink,
gets,
waits,
writes/1024 writes,
writes/gets wpg
from v$rollstat,v$rollname,dba_rollback_segs
where v$rollstat.usn=v$rollname.usn
and dba_rollback_segs.segment_id=v$rollname.usn
order by name
Increase Shared pool size to reach a 90% hit ratio on Dictionary Cache. Entries
for dc_table_grants, d_user_grants, and dc_users should be under 5% each in the
MISS RATE % column
select
parameter,
gets,
Getmisses ,
getmisses/(gets+getmisses)*100 "miss ratio",
(1-(sum(getmisses)/ (sum(gets)+sum(getmisses))))*100 "Hit ratio"
from v$rowcache
where gets+getmisses <>0
group by parameter, gets, getmisses ;
Reduce the Reloads and try to increase the hit ratios to above 85%
select
namespace,gets,gethits,gethitratio,pins,pinhits,
pinhitratio, reloads
from v$librarycache
where gets+gethits+pins+pinhits>0
;
This should be near 0.If the Ratio is larger than 1% then increase the
SHARED_POOL_SIZE
select sum(pins) "Total Pins", sum(reloads) "Total Reloads",
sum(reloads)/sum(pins) *100 libcache
from v$librarycache
CASE STUDY:
NCsoft Supports Massive Number of Simultaneous Connections
CASE STUDY:
Learn how Microsoft helped the state of Illinois serve its 12 million constituents
more quickly while saving taxpayer dollars
WHITEPAPER:
Linux vs. Microsoft--Making the Right Choice for Your Client-Server Infrastructure
WHITEPAPER:
Using the .NET Framework to Increase Performance, Availability, & Business Agility
Maximizing the Performance of SUSE Linux Enterprise Real Time for Financial
Services Applications on AMD64 Technology Whitepaper: The technology needs of
financial services companies offer a remarkable challenge for computer hardware
and software vendors. The central requirement is deterministic, real-time
computing for high-priority transactions that must execute accurately and
predictably every time. However, a real-time computing solution must also offer
rock-solid stability and reliability, since there is zero tolerance for missed
transactions, lost records, or system downtime.
Click here.
select Username,
OSUSER,
Consistent_Gets,
Block_Gets,
Physical_Reads,
100*( Consistent_Gets + Block_Gets - Physical_Reads)/
( Consistent_Gets + Block_Gets ) "Hit Ratio %"
from V$SESSION,V$SESS_IO
where V$SESSION.SID = V$SESS_IO.SID
and ( Consistent_Gets + Block_Gets )>0
and username is not null
order by Username,"Hit Ratio %";
Description: If you want to copy the data from one database to another having
many tables and constraints,all you need is this script which will first disable
all the constraints then delete the prior data and then finaly copy the data from
any remote database and finaly it enables all the constraints on the table of that
database.......all you need is to have a table having names of all the tables and
the corresponding constraints
Code:
c2 cconstraints%rowtype;
mytab varchar2(200);
mytab1 varchar2(200);
mytab3 varchar2(200);
mytab4 varchar2(200);
retrycounter number;
counter number;
cstatus varchar2(20);
enableerrorfound boolean:=true;
--MAX_TRY number:=10000;
begin
begin
open cconstraints;
loop
end loop;
close cconstraints;
open cconstraints;
loop
fetch cconstraints into c2;
exit when cconstraints%notfound;
mytab :=c2.table_name;
execute immediate 'delete ' || mytab;
end loop;
close cconstraints;
end;
open cconstraints;
loop
fetch cconstraints into c2;
exit when cconstraints%notfound;
mytab :=c2.table_name;
mytab4 :='DATABASENAME';
execute immediate 'insert into ' || mytab || ' (select * from '|| mytab || '@' ||
mytab4 || ')';
DBMS_OUTPUT.PUT_LINE(mytab);
commit;
DBMS_OUTPUT.PUT_LINE(mytab);
end loop;
close cconstraints;
begin
DBMS_OUTPUT.PUT_LINE('Starting enable script.....');
RETRYCOUNTER := 3;
loop
fetch cconstraints into c2;
exit when cconstraints%notfound;
DBMS_OUTPUT.PUT_LINE('retrycounter==>'||mytab);
mytab := c2.table_name;
mytab1 := c2.constraint_name;
--cstatus:= c2.status;
--if cstatus = 'DISABLED' then
mytab3 :='alter table ' || mytab || ' enable constraint ' || mytab1;
DBMS_OUTPUT.PUT_LINE('Q' || mytab3);
DBMS_OUTPUT.PUT_LINE(retrycounter);
--enableerrorfound:=false;
BEGIN
execute immediate mytab3;
EXCEPTION
WHEN OTHERS THEN
enableerrorfound:=true;
END;
--end if;
end loop;
RETRYCOUNTER := RETRYCOUNTER - 1;
DBMS_OUTPUT.PUT_LINE(retrycounter);
close cconstraints;
end loop;
DBMS_OUTPUT.PUT_LINE(retrycounter);
IF (enableerrorfound) THEN
DBMS_OUTPUT.PUT_LINE('enableerrorfound==> TRUE');
else
DBMS_OUTPUT.PUT_LINE('enableerrorfound==> FALSE');
end if;
end;
end pre_tra;
Description: List the UGA and PGA used by each session on the server
Code:
select se.sid,n.name,
max(se.value) maxmem
from v$sesstat se,
v$statname n
where n.statistic# = se.statistic#
and n.name in ('session pga memory','session pga memory max',
'session uga memory','session uga memory max')
group by n.name,se.sid
order by 3
Description: Try to reduce the contention by reducing all the ratios to be less
than 1
Code: