分类: Oracle
2008-05-05 15:55:15
来源:赛迪网 作者:Alice |
查看一下谁在使用那个可以得回滚段,或者查看一下某个可以得用户在使用回滚段,找出领回滚段不断增长的事务,再看看如何处理它,是否可以将它commit,再不行就看能否kill它,查看当前正在使用的回滚段的用户信息和回滚段信息:
set linesize 121
SELECT r.name "ROLLBACK SEGMENT NAME ",l.sid "ORACLE PID",p.spid "SYSTEM PID ",s.username "ORACLE USERNAME"
FROM v$lock l, v$process p, v$rollname r, v$session s
WHERE l.sid = p.pid(+) AND s.sid=l.sid AND TRUNC(l.id1(+)/65536) = r.usn AND l.type(+) = 'TX' AND l.lmode(+) = 6 ORDER BY r.name;
--查看用户的回滚段的信息
select s.username, rn.name from v$session s, v$transaction t, v$rollstat r, v$rollname rn
where s.saddr = t.ses_addr and t.xidusn = r.usn and r.usn = rn.usn
--生成执行计划
explain plan set statement_id='a1' for &1;
--查看执行计划
select lpad(' ',2*(level-1))||operation operation,options,OBJECT_NAME,position from plan_table
start with id=0 and statement_id='a1' connect by prior id=parent_id and statement_id='a1'
--查看内存中存的使用
select decode(greatest(class,10),10,decode(class,1,'Data',2,'Sort',4,'Header',to_char(class)),'Rollback') "Class",
sum(decode(bitand(flag,1),1,0,1)) "Not Dirty",sum(decode(bitand(flag,1),1,1,0)) "Dirty",
sum(dirty_queue) "On Dirty",count(*) "Total"
from x$bh group by decode(greatest(class,10),10,decode(class,1,'Data',2,'Sort',4,'Header',to_char(class)),'Rollback');
--查看表空间状态
select tablespace_name,extent_management,segment_space_management from dba_tablespaces;
select table_name,freelists,freelist_groups from user_tables;
--查看系统请求情况
SELECT DECODE (name, 'summed dirty write queue length', value)/
DECODE (name, 'write requests', value) "Write Request Length"
FROM v$sysstat WHERE name IN ( 'summed dirty queue length', 'write requests') and value>0;
--计算data buffer命中率
select a.value + b.value "logical_reads", c.value "phys_reads",
round(100 * ((a.value+b.value)-c.value) / (a.value+b.value)) "BUFFER HIT RATIO"
from v$sysstat a, v$sysstat b, v$sysstat c
where a.statistic# = 40 and b.statistic# = 41 and c.statistic# = 42;
SELECT name, (1-(physical_reads/(db_block_gets+consistent_gets)))*100 H_RATIO FROM v$buffer_pool_statistics;
--查看内存使用情况
select least(max(b.value)/(1024*1024),sum(a.bytes)/(1024*1024)) shared_pool_used,
max(b.value)/(1024*1024) shared_pool_size,greatest(max(b.value)/(1024*1024),sum(a.bytes)/(1024*1024))-
(sum(a.bytes)/(1024*1024)) shared_pool_avail,((sum(a.bytes)/(1024*1024))/(max(b.value)/(1024*1024)))*100 avail_pool_pct
from v$sgastat a, v$parameter b where (a.pool='shared pool' and a.name not in ('free memory')) and b.name='shared_pool_size';
--查看用户使用内存情况
select username, sum(sharable_mem), sum(persistent_mem), sum(runtime_mem)
from sys.v_$sqlarea a, dba_users b
where a.parsing_user_id = b.user_id group by username;
--查看对象的缓存情况
select OWNER,NAMESPACE,TYPE,NAME,SHARABLE_MEM,LOADS,EXECUTIONS,LOCKS,PINS,KEPT
from v$db_object_cache where type not in ('NOT LOADED','NON-EXISTENT','VIEW','TABLE','SEQUENCE')
and executions>0 and loads>1 and kept='NO' order by owner,namespace,type,executions desc;
select type,count(*) from v$db_object_cache group by type;
--查看库缓存命中率
select namespace,gets, gethitratio*100 gethitratio,pins,pinhitratio*100 pinhitratio,RELOADS,INVALIDATIONS from v$librarycache
--查看某些用户的hash
select a.username, count(b.hash_value) total_hash,count(b.hash_value)-count(unique(b.hash_value)) same_hash,
(count(unique(b.hash_value))/count(b.hash_value))*100 u_hash_ratio
from dba_users a, v$sqlarea b where a.user_id=b.parsing_user_id group by a.username;
--查看字典命中率
select (sum(getmisses)/sum(gets)) ratio from v$rowcache;
--查看undo段的使用情况
SELECT d.segment_name,extents,optsize,shrinks,aveshrink,aveactive,d.status
FROM v$rollname n,v$rollstat s,dba_rollback_segs d
WHERE d.segment_id=n.usn(+) and d.segment_id=s.usn(+);
--无效的对象
select owner,object_type,object_name from dba_objects where status='INVALID';
select constraint_name,table_name from dba_constraints where status='INVALID';
--求出某个进程,并对它进行跟踪
select s.sid,s.serial# from v$session s,v$process p where s.paddr=p.addr and p.spid=&1;
exec dbms_system.SET_SQL_TRACE_IN_SESSION(&1,&2,true);
exec dbms_system.SET_SQL_TRACE_IN_SESSION(&1,&2,false);
--求出锁定的对象
select do.object_name,session_id,process,locked_mode
from v$locked_object lo, dba_objects do where lo.object_id=do.object_id;
--求当前session的跟踪文件
SELECT p1.value || '/' || p2.value || '_ora_' || p.spid || '.ora' filename
FROM v$process p, v$session s, v$parameter p1, v$parameter p2
WHERE p1.name = 'user_dump_dest' AND p2.name = 'instance_name'
AND p.addr = s.paddr AND s.audsid = USERENV('SESSIONID') AND p.background is null AND instr(p.program,'CJQ') = 0;
--求对象所在的文件及块号
select segment_name,header_file,header_block
from dba_segments where segment_name like '&1';
--求对象发生事务时回退段及块号
select a.segment_name,a.header_file,a.header_block
from dba_segments a,dba_rollback_segs b
where a.segment_name=b.segment_name and b.segment_id='&1'
--9i的在线重定义表
/*如果在线重定义的表没有主键需要创建主键*/
exec dbms_redefinition.can_redef_table('cybercafe','announcement');
create table anno2 as select * from announcement
exec dbms_redefinition.start_redef_table('cybercafe','announcement','anno2');
exec dbms_redefinition.sync_interim_table('cybercafe','announcement','anno2');
exec dbms_redefinition.finish_redef_table('cybercafe','announcement','anno2');
drop table anno2
exec dbms_redefinition.abort_redef_table('cybercafe','announcement','anno2');
--常用的logmnr脚本(cybercafe)
exec sys.dbms_logmnr_d.build(dictionary_filename =>'esal',dictionary_location =>'/home/oracle/logmnr');
exec sys.dbms_logmnr.add_logfile(logfilename=>'/home/oracle/oradata/esal/archive/1_24050.dbf', ptions=>sys.dbms_logmnr.new);
exec sys.dbms_logmnr.add_logfile(logfilename=>'/home/oracle/oradata/esal/archive/1_22912.dbf', ptions=>sys.dbms_logmnr.addfile);
exec sys.dbms_logmnr.add_logfile(logfilename=>'/home/oracle/oradata/esal/archive/1_22913.dbf', ptions=>sys.dbms_logmnr.addfile);
exec sys.dbms_logmnr.add_logfile(logfilename=>'/home/oracle/oradata/esal/archive/1_22914.dbf', ptions=>sys.dbms_logmnr.addfile);
exec sys.dbms_logmnr.start_logmnr(dictfilename=>'/home/oracle/logmnr/esal.ora');
create table logmnr2 as select * from v$logmnr_contents;
--与权限相关的字典
ALL_COL_PRIVS表示列上的授权,用户和PUBLIC是被授予者
ALL_COL_PRIVS_MADE表示列上的授权,用户是属主和被授予者
ALL_COL_RECD表示列上的授权,用户和PUBLIC是被授予者
ALL_TAB_PRIVS表示对象上的授权,用户是PUBLIC或被授予者或用户是属主
ALL_TAB_PRIVS_MADE表示对象上的权限,用户是属主或授予者
ALL_TAB_PRIVS_RECD表示对象上的权限,用户是PUBLIC或被授予者
DBA_COL_PRIVS数据库列上的所有授权
DBA_ROLE_PRIVS显示已授予用户或其他角色的角色
DBA_SYS_PRIVS已授予用户或角色的系统权限
DBA_TAB_PRIVS数据库对象上的所有权限
ROLE_ROLE_PRIVS显示已授予用户的角色
ROLE_SYS_PRIVS显示通过角色授予用户的系统权限
ROLE_TAB_PRIVS显示通过角色授予用户的对象权限
SESSION_PRIVS显示用户现在可利用的所有系统权限
USER_COL_PRIVS显示列上的权限,用户是属主、授予者或被授予者
USER_COL_PRIVS_MADE显示列上已授予的权限,用户是属主或授予者
USER_COL_PRIVS_RECD显示列上已授予的权限,用户是属主或被授予者
USER_ROLE_PRIVS显示已授予给用户的所有角色
USER_SYS_PRIVS显示已授予给用户的所有系统权限
USER_TAB_PRIVS显示已授予给用户的所有对象权限
USER_TAB_PRIVS_MADE显示已授予给其他用户的对象权限,用户是属主
USER_TAB_PRIVS_RECD显示已授予给其他用户的对象权限,用户是被授予者
--如何用dbms_stats分析表及模式?
exec dbms_stats.gather_schema_stats(ownname=>'&USER_NAME',estimate_percent=>dbms_stats.auto_sample_size,
method_opt => 'for all columns size auto',degree=> DBMS_STATS.DEFAULT_DEGREE);
exec dbms_stats.gather_schema_stats(ownname=>'&USER_NAME',estimate_percent=>dbms_stats.auto_sample_size,cascade=>true);
/*
FOR ALL [INDEXED | HIDDEN] COLUMNS [size_clause]
FOR COLUMNS [size clause] column|attribute [size_clause] [,column|attribute [size_clause]...],
where size_clause is defined as size_clause := SIZE {integer | REPEAT | AUTO | SKEWONLY}
integer--Number of histogram buckets. Must be in the range [1,254].
REPEAT--Collects histograms only on the columns that already have histograms.
AUTO--Oracle determines the columns to collect histograms based on data distribution and the workload of the columns.
SKEWONLY--Oracle determines the columns to collect histograms based on the data distribution of the columns
*/ |