- 浏览: 342310 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
yin_bp:
不建议使用session复制机制,推荐bboss会话共享框架, ...
JBOSS7 集群和Session复制配置笔记 -
heipacker:
建议:java(多线程)实现高性能数据同步==>java ...
java(多线程)实现高性能数据同步 -
yang_min:
582399232 写道你的脚本貌似不能用呀?service ...
JBOSS7学习笔记 -
yang_min:
582399232 写道感觉这个脚本不好#shutdown=' ...
JBOSS7学习笔记 -
yang_min:
582399232 写道博主能问几个问题吗?1.按照你的步骤执 ...
JBOSS7 集群和Session复制配置笔记
1、查看表空间的名称及大小 select t.tablespace_name, round(sum(bytes/(1024*1024)),0) ts_size from dba_tablespaces t, dba_data_files d where t.tablespace_name = d.tablespace_name group by t.tablespace_name; 2、查看表空间物理文件的名称及大小 select tablespace_name, file_id, file_name, round(bytes/(1024*1024),0) total_space from dba_data_files order by tablespace_name; 3、查看回滚段名称及大小 select segment_name, tablespace_name, r.status, (initial_extent/1024) InitialExtent,(next_extent/1024) NextExtent, max_extents, v.curext CurExtent From dba_rollback_segs r, v$rollstat v Where r.segment_id = v.usn(+) order by segment_name ; 4、查看控制文件 select name from v$controlfile; 5、查看日志文件 select member from v$logfile; 6、查看表空间的使用情况 select sum(bytes)/(1024*1024) as free_space,tablespace_name from dba_free_space group by tablespace_name; SELECT A.TABLESPACE_NAME,A.BYTES TOTAL,B.BYTES USED, C.BYTES FREE, (B.BYTES*100)/A.BYTES "% USED",(C.BYTES*100)/A.BYTES "% FREE" FROM SYS.SM$TS_AVAIL A,SYS.SM$TS_USED B,SYS.SM$TS_FREE C WHERE A.TABLESPACE_NAME=B.TABLESPACE_NAME AND A.TABLESPACE_NAME=C.TABLESPACE_NAME; 7、查看数据库库对象 select owner, object_type, status, count(*) count# from all_objects group by owner, object_type, status; 8、查看数据库的版本 Select version FROM Product_component_version Where SUBSTR(PRODUCT,1,6)='Oracle'; 9、查看数据库的创建日期和归档方式 Select Created, Log_Mode, Log_Mode From V$Database; 10、捕捉运行很久的SQL column username format a12 column opname format a16 column progress format a8 select username,sid,opname, round(sofar*100 / totalwork,0) || '%' as progress, time_remaining,sql_text from v$session_longops , v$sql where time_remaining <> 0 and sql_address = address and sql_hash_value = hash_value / 11、查看数据表的参数信息 SELECT partition_name, high_value, high_value_length, tablespace_name, pct_free, pct_used, ini_trans, max_trans, initial_extent, next_extent, min_extent, max_extent, pct_increase, FREELISTS, freelist_groups, LOGGING, BUFFER_POOL, num_rows, blocks, empty_blocks, avg_space, chain_cnt, avg_row_len, sample_size, last_analyzed FROM dba_tab_partitions --WHERE table_name = :tname AND table_owner = :towner ORDER BY partition_position 12.查看还没提交的事务 select * from v$locked_object; select * from v$transaction; 13。查找object为哪些进程所用 select p.spid, s.sid, s.serial# serial_num, s.username user_name, a.type object_type, s.osuser os_user_name, a.owner, a.object object_name, decode(sign(48 - command), 1, to_char(command), 'Action Code #' || to_char(command) ) action, p.program oracle_process, s.terminal terminal, s.program program, s.status session_status from v$session s, v$access a, v$process p where s.paddr = p.addr and s.type = 'USER' and a.sid = s.sid and a.object='SUBSCRIBER_ATTR' order by s.username, s.osuser 14。回滚段查看 select rownum, sys.dba_rollback_segs.segment_name Name, v$rollstat.extents Extents, v$rollstat.rssize Size_in_Bytes, v$rollstat.xacts XActs, v$rollstat.gets Gets, v$rollstat.waits Waits, v$rollstat.writes Writes, sys.dba_rollback_segs.status status from v$rollstat, sys.dba_rollback_segs, v$rollname where v$rollname.name(+) = sys.dba_rollback_segs.segment_name and v$rollstat.usn (+) = v$rollname.usn order by rownum 15。耗资源的进程(top session) select s.schemaname schema_name, decode(sign(48 - command), 1, to_char(command), 'Action Code #' || to_char(command) ) action, status session_status, s.osuser os_user_name, s.sid, p.spid , s.serial# serial_num, nvl(s.username, '[Oracle process]') user_name, s.terminal terminal, s.program program, st.value criteria_value from v$sesstat st, v$session s , v$process p where st.sid = s.sid and st.statistic# = to_number('38') and ('ALL' = 'ALL' or s.status = 'ALL') and p.addr = s.paddr order by st.value desc, p.spid asc, s.username asc, s.osuser asc 16。查看锁(lock)情况 select /*+ RULE */ ls.osuser os_user_name, ls.username user_name, decode(ls.type, 'RW', 'Row wait enqueue lock', 'TM', 'DML enqueue lock', 'TX', 'Transaction enqueue lock', 'UL', 'User supplied lock') lock_type, o.object_name object, decode(ls.lmode, 1, null, 2, 'Row Share', 3, 'Row Exclusive', 4, 'Share', 5, 'Share Row Exclusive', 6, 'Exclusive', null) lock_mode, o.owner, ls.sid, ls.serial# serial_num, ls.id1, ls.id2 from sys.dba_objects o, ( select s.osuser, s.username, l.type, l.lmode, s.sid, s.serial#, l.id1, l.id2 from v$session s, v$lock l where s.sid = l.sid ) ls where o.object_id = ls.id1 and o.owner <> 'SYS' order by o.owner, o.object_name 17。查看等待(wait)情况 SELECT v$waitstat.class, v$waitstat.count count, SUM(v$sysstat.value) sum_value FROM v$waitstat, v$sysstat WHERE v$sysstat.name IN ('db block gets', 'consistent gets') group by v$waitstat.class, v$waitstat.count 18。查看sga情况 SELECT NAME, BYTES FROM SYS.V_$SGASTAT ORDER BY NAME ASC
19。查看catched object SELECT owner, name, db_link, namespace, type, sharable_mem, loads, executions, locks, pins, kept FROM v$db_object_cache 20。查看V$SQLAREA SELECT SQL_TEXT, SHARABLE_MEM, PERSISTENT_MEM, RUNTIME_MEM, SORTS, VERSION_COUNT, LOADED_VERSIONS, OPEN_VERSIONS, USERS_OPENING, EXECUTIONS, USERS_EXECUTING, LOADS, FIRST_LOAD_TIME, INVALIDATIONS, PARSE_CALLS, DISK_READS, BUFFER_GETS, ROWS_PROCESSED FROM V$SQLAREA 21。查看object分类数量 select decode (o.type#,1,'INDEX' , 2,'TABLE' , 3 , 'CLUSTER' , 4, 'VIEW' , 5 , 'SYNONYM' , 6 , 'SEQUENCE' , 'OTHER' ) object_type , count(*) quantity from sys.obj$ o where o.type# > 1 group by decode (o.type#,1,'INDEX' , 2,'TABLE' , 3 , 'CLUSTER' , 4, 'VIEW' , 5 , 'SYNONYM' , 6 , 'SEQUENCE' , 'OTHER' ) union select 'COLUMN' , count(*) from sys.col$ union select 'DB LINK' , count(*) from 22。按用户查看object种类 select u.name schema, sum(decode(o.type#, 1, 1, NULL)) indexes, sum(decode(o.type#, 2, 1, NULL)) tables, sum(decode(o.type#, 3, 1, NULL)) clusters, sum(decode(o.type#, 4, 1, NULL)) views, sum(decode(o.type#, 5, 1, NULL)) synonyms, sum(decode(o.type#, 6, 1, NULL)) sequences, sum(decode(o.type#, 1, NULL, 2, NULL, 3, NULL, 4, NULL, 5, NULL, 6, NULL, 1)) others from sys.obj$ o, sys.user$ u where o.type# >= 1 and u.user# = o.owner# and u.name <> 'PUBLIC' group by u.name order by sys.link$ union select 'CONSTRAINT' , count(*) from sys.con$ 23。有关connection的相关信息 1)查看有哪些用户连接 select s.osuser os_user_name, decode(sign(48 - command), 1, to_char(command), 'Action Code #' || to_char(command) ) action, p.program oracle_process, status session_status, s.terminal terminal, s.program program, s.username user_name, s.fixed_table_sequence activity_meter, '' query, 0 memory, 0 max_memory, 0 cpu_usage, s.sid, s.serial# serial_num from v$session s, v$process p where s.paddr=p.addr and s.type = 'USER' order by s.username, s.osuser 2)根据v.sid查看对应连接的资源占用等情况 select n.name, v.value, n.class, n.statistic# from v$statname n, v$sesstat v where v.sid = 71 and v.statistic# = n.statistic# order by n.class, n.statistic# 3)根据sid查看对应连接正在运行的sql select /*+ PUSH_SUBQ */ command_type, sql_text, sharable_mem, persistent_mem, runtime_mem, sorts, version_count, loaded_versions, open_versions, users_opening, executions, users_executing, loads, first_load_time, invalidations, parse_calls, disk_reads, buffer_gets, rows_processed, sysdate start_time, sysdate finish_time, '>' || address sql_address, 'N' status from v$sqlarea where address = (select sql_address from v$session where sid = 71) 24.查询表空间使用情况select a.tablespace_name "表空间名称", 100-round((nvl(b.bytes_free,0)/a.bytes_alloc)*100,2) "占用率(%)", round(a.bytes_alloc/1024/1024,2) "容量(M)", round(nvl(b.bytes_free,0)/1024/1024,2) "空闲(M)", round((a.bytes_alloc-nvl(b.bytes_free,0))/1024/1024,2) "使用(M)", Largest "最大扩展段(M)", to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') "采样时间" from (select f.tablespace_name, sum(f.bytes) bytes_alloc, sum(decode(f.autoextensible,'YES',f.maxbytes,'NO',f.bytes)) maxbytes from dba_data_files f group by tablespace_name) a, (select f.tablespace_name, sum(f.bytes) bytes_free from dba_free_space f group by tablespace_name) b, (select round(max(ff.length)*16/1024,2) Largest, ts.name tablespace_name from sys.fet$ ff, sys.file$ tf,sys.ts$ ts where ts.ts#=ff.ts# and ff.file#=tf.relfile# and ts.ts#=tf.ts# group by ts.name, tf.blocks) c where a.tablespace_name = b.tablespace_name and a.tablespace_name = c.tablespace_name 25. 查询表空间的碎片程度 select tablespace_name,count(tablespace_name) from dba_free_space group by tablespace_name having count(tablespace_name)>10; alter tablespace name coalesce; alter table name deallocate unused; create or replace view ts_blocks_v as select tablespace_name,block_id,bytes,blocks,'free space' segment_name from dba_free_space union all select tablespace_name,block_id,bytes,blocks,segment_name from dba_extents; select * from ts_blocks_v; select tablespace_name,sum(bytes),max(bytes),count(block_id) from dba_free_space group by tablespace_name;
26.监控索引是否使用alter index &index_name monitoring usage;alter index &index_name nomonitoring usage;select * from v$object_usage where index_name = &index_name;
27.求数据文件的I/O分布select df.name,phyrds,phywrts,phyblkrd,phyblkwrt,singleblkrds,readtim,writetim ?from v$filestat fs,v$dbfile df where fs.file#=df.file# order by df.name;
28.求某个隐藏参数的值?col ksppinm format a54?col ksppstvl format a54?select ksppinm, ksppstvl ? from x$ksppi pi, x$ksppcv cv ?where cv.indx=pi.indx and pi.ksppinm like '\_%' escape '\' and pi.ksppinm like '%¶meer%';
29.求系统中较大的latchselect name,sum(gets),sum(misses),sum(sleeps),sum(wait_time) ?from v$latch_children group by name having sum(gets) > 50 order by 2;
30.求归档日志的切换频率(生产系统可能时间会很长)select start_recid,start_time,end_recid,end_time,minutes from (select test.*, rownum as rn ?from (select b.recid start_recid,to_char(b.first_time,'yyyy-mm-dd hh24:mi:ss') start_time,? a.recid end_recid,to_char(a.first_time,'yyyy-mm-dd hh24:mi:ss') end_time,round(((a.first_time-b.first_time)*24)*60,2) minutes ?from v$log_history a,v$log_history b where a.recid=b.recid+1 and b.first_time > sysdate - 1 ? order by a.first_time desc) test) y where y.rn < 30
31.求回滚段正在处理的事务select a.name,b.xacts,c.sid,c.serial#,d.sql_text?from v$rollname a,v$rollstat b,v$session c,v$sqltext d,v$transaction ewhere a.usn=b.usn and b.usn=e.xidusn and c.taddr=e.addr ?and c.sql_address=d.address and c.sql_hash_value=d.hash_value order by a.name,c.sid,d.piece;
32.求出无效的对象select 'alter procedure '||object_name||' compile;' ?from dba_objects where status='INVALID' and owner='&' and object_type in ('PACKAGE','PACKAGE BODY');/select owner,object_name,object_type,status from dba_objects where status='INVALID';
--求process/session的状态select p.pid,p.spid,s.program,s.sid,s.serial# ?from v$process p,v$session s where s.paddr=p.addr;
--求当前session的状态select sn.name,ms.value ?from v$mystat ms,v$statname sn where ms.statistic#=sn.statistic# and ms.value > 0;
--求表的索引信息select ui.table_name,ui.index_name ?from user_indexes ui,user_ind_columns uic where ui.table_name=uic.table_name and ui.index_name=uic.index_name ?and ui.table_name like '&table_name%' and uic.column_name='&column_name';
--显示表的外键信息col search_condition format a54select table_name,constraint_name? from user_constraints ?where constraint_type ='R' and constraint_name in (select constraint_name from user_cons_columns where column_name='&1');
select rpad(child.table_name,25,' ') child_tablename,?rpad(cp.column_name,17,' ') referring_column,rpad(parent.table_name,25,' ') parent_tablename,?rpad(pc.column_name,15,' ') referred_column,rpad(child.constraint_name,25,' ') constraint_name ?from user_constraints child,user_constraints parent,????? user_cons_columns cp,user_cons_columns pc where child.constraint_type = 'R' and child.r_constraint_name = parent.constraint_name and? child.constraint_name = cp.constraint_name and parent.constraint_name = pc.constraint_name and? cp.position = pc.position and child.table_name ='&table_name'?order by child.owner,child.table_name,child.constraint_name,cp.position;
--显示表的分区及子分区(user_tab_subpartitions)col table_name format a16col partition_name format a16col high_value format a81select table_name,partition_name,HIGH_VALUE from user_tab_partitions where table_name='&table_name'
--使用dbms_xplan生成一个执行计划explain plan set statement_id = '&sql_id' for &sql;select * from table(dbms_xplan.display);
--求某个事务的重做信息(bytes)select s.name,m.value ? from v$mystat m,v$statname s ?where m.statistic#=s.statistic# and s.name like '%redo size%';
--求cache中缓存超过其5%的对象select o.owner,o.object_type,o.object_name,count(b.objd)?from v$bh b,dba_objects owhere b.objd = o.object_id ?group by o.owner,o.object_type,o.object_name?having count(b.objd) > (select to_number(value)*0.05 from v$parameter where name = 'db_block_buffers');
--求谁阻塞了某个session(10g)select sid, username, event, blocking_session,? seconds_in_wait, wait_time?from v$session where state in ('WAITING') and wait_class != 'Idle';
--求session的OS进程IDcol program format a54select p.spid "OS Thread", b.name "Name-User", s.program?from v$process p, v$session s, v$bgprocess b?where p.addr = s.paddr and p.addr = b.paddr UNION ALLselect p.spid "OS Thread", s.username "Name-User", s.program?from v$process p, v$session s where p.addr = s.paddr and s.username is not null;
--查会话的阻塞col user_name format a32select /*+ rule */ lpad(' ',decode(l.xidusn ,0,3,0))||l.oracle_username user_name, o.owner,o.object_name,s.sid,s.serial# ?from v$locked_object l,dba_objects o,v$session s where l.object_id=o.object_id and l.session_id=s.sid order by o.object_id,xidusn desc ;
col username format a15col lock_level format a8col owner format a18col object_name format a32select /*+ rule */ s.username, decode(l.type,'tm','table lock', 'tx','row lock', null) lock_level, o.owner,o.object_name,s.sid,s.serial#?from v$session s,v$lock l,dba_objects o where l.sid = s.sid and l.id1 = o.object_id(+) and s.username is not null ;
--求等待的事件及会话信息/求会话的等待及会话信息select se.sid,s.username,se.event,se.total_waits,se.time_waited,se.average_wait? from v$session s,v$session_event sewhere s.username is not null and se.sid=s.sid and s.status='ACTIVE' and se.event not like '%SQL*Net%' order by s.username;
select s.sid,s.username,sw.event,sw.wait_time,sw.state,sw.seconds_in_wait? from v$session s,v$session_wait swwhere s.username is not null and sw.sid=s.sid and sw.event not like '%SQL*Net%' order by s.username;
--求会话等待的file_id/block_idcol event format a24col p1text format a12col p2text format a12col p3text format a12select sid,event,p1text, p1, p2text, p2, p3text, p3? from v$session_waitwhere event not like '%SQL%' and event not like '%rdbms%' and event not like '%mon%' order by event;
select name,wait_time from v$latch l where exists (select 1 from (select sid,event,p1text, p1, p2text, p2, p3text, p3? from v$session_waitwhere event not like '%SQL%' and event not like '%rdbms%' and event not like '%mon%') x where x.p1= l.latch#);
--求会话等待的对象col owner format a18col segment_name format a32col segment_type format a32select owner,segment_name,segment_type? from dba_extentswhere file_id = &file_id and &block_id between block_id and block_id + blocks - 1;
--求buffer cache中的块信息select o.OBJECT_TYPE, substr(o.OBJECT_NAME,1,10) objname , b.objd , b.status, count(b.objd) ?from? v$bh b, dba_objects o ?where b.objd = o.data_object_id and o.owner = '&1' group by o.object_type, o.object_name,b.objd, b.status ;
--求日志文件的空间使用select le.leseq current_log_sequence#, 100*cp.cpodr_bno/le.lesiz percentage_full?from x$kcccp cp,x$kccle le?where le.leseq =cp.cpodr_seq;
--求等待中的对象select /*+rule */ s.sid, s.username, w.event, o.owner, o.segment_name, o.segment_type, ?????? o.partition_name, w.seconds_in_wait seconds, w.state ? from v$session_wait w, v$session s, dba_extents o ?where w.event in (select name from v$event_name? where parameter1 = 'file#' ?? and parameter2 = 'block#' and name not like 'control%') ?? and o.owner <> 'sys' and w.sid = s.sid and w.p1 = o.file_id and w.p2 >= o.block_id and w.p2 < o.block_id + o.blocks
--求当前事务的重做尺寸select value? from v$mystat, v$statname?where v$mystat.statistic# = v$statname.statistic# and v$statname.name = 'redo size';
--唤醒smon去清除临时段column pid new_value Smonset termout offselect p.pid from sys.v_$bgprocess b,sys.v_$process p where b.name = 'SMON' and p.addr = b.paddr/set termout onoradebug wakeup &Smonundefine Smon
--求回退率select b.value/(a.value + b.value),a.value,b.value from v$sysstat a,v$sysstat b where a.statistic#=4 and b.statistic#=5;
--求DISK READ较多的SQLselect st.sql_text from v$sql s,v$sqltext st where s.address=st.address and s.hash_value=st.hash_value and s.disk_reads > 300;
--求DISK SORT严重的SQLselect sess.username, sql.sql_text, sort1.blocks ? from v$session sess, v$sqlarea sql, v$sort_usage sort1 ?where sess.serial# = sort1.session_num ?? and sort1.sqladdr = sql.address ?? and sort1.sqlhash = sql.hash_value? and sort1.blocks > 200;
--求对象的创建代码column column_name format a36column sql_text format a99select dbms_metadata.get_ddl('TABLE','&1') from dual;select dbms_metadata.get_ddl('INDEX','&1') from dual;
--求表的索引set linesize 131select a.index_name,a.column_name,b.status, b.index_typefrom user_ind_columns a,user_indexes bwhere a.index_name=b.index_name and a.table_name='&1';
求索引中行数较多的select index_name,blevel,num_rows,CLUSTERING_FACTOR,status from user_indexes where num_rows > 10000 and blevel > 0select table_name,index_name,blevel,num_rows,CLUSTERING_FACTOR,status from user_indexes where status <> 'VALID'
--求当前会话的SID,SERIAL#select sid, serial# from v$session where audsid = SYS_CONTEXT('USERENV','SESSIONID');
--求表空间的未用空间col mbytes format 9999.9999select tablespace_name,sum(bytes)/1024/1024 mbytes from dba_free_space group by tablespace_name;
--求表中定义的触发器select table_name,index_type,index_name,uniqueness from user_indexes where table_name='&1';select trigger_name from user_triggers where table_name='&1';
--求未定义索引的表select table_name from user_tables where table_name not in (select table_name from user_ind_columns);
--执行常用的过程exec print_sql('select count(*) from tab');exec show_space2('table_name');
--求free memoryselect * from v$sgastat where name='free memory';select a.name,sum(b.value) from v$statname a,v$sesstat b where a.statistic# = b.statistic# group by a.name;
查看一下谁在使用那个可以得回滚段,或者查看一下某个可以得用户在使用回滚段,找出领回滚段不断增长的事务,再看看如何处理它,是否可以将它commit,再不行就看看能否kill它,等等, 查看当前正在使用的回滚段的用户信息和回滚段信息:set linesize 121SELECT 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 sWHERE 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 rnwhere 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_tablestart 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 cwhere 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_pctfrom 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 bwhere a.parsing_user_id = b.user_id group by username;
--查看对象的缓存情况select OWNER,NAMESPACE,TYPE,NAME,SHARABLE_MEM,LOADS,EXECUTIONS,LOCKS,PINS,KEPTfrom 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
--查看某些用户的hashselect 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_ratiofrom 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.statusFROM v$rollname n,v$rollstat s,dba_rollback_segs dWHERE 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 announcementexec 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 anno2exec 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', options=>sys.dbms_logmnr.new);
exec sys.dbms_logmnr.add_logfile(logfilename=>'/home/oracle/oradata/esal/archive/1_22912.dbf', options=>sys.dbms_logmnr.addfile);exec sys.dbms_logmnr.add_logfile(logfilename=>'/home/oracle/oradata/esal/archive/1_22913.dbf', options=>sys.dbms_logmnr.addfile);exec sys.dbms_logmnr.add_logfile(logfilename=>'/home/oracle/oradata/esal/archive/1_22914.dbf', options=>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*/
19。查看catched object SELECT owner, name, db_link, namespace, type, sharable_mem, loads, executions, locks, pins, kept FROM v$db_object_cache 20。查看V$SQLAREA SELECT SQL_TEXT, SHARABLE_MEM, PERSISTENT_MEM, RUNTIME_MEM, SORTS, VERSION_COUNT, LOADED_VERSIONS, OPEN_VERSIONS, USERS_OPENING, EXECUTIONS, USERS_EXECUTING, LOADS, FIRST_LOAD_TIME, INVALIDATIONS, PARSE_CALLS, DISK_READS, BUFFER_GETS, ROWS_PROCESSED FROM V$SQLAREA 21。查看object分类数量 select decode (o.type#,1,'INDEX' , 2,'TABLE' , 3 , 'CLUSTER' , 4, 'VIEW' , 5 , 'SYNONYM' , 6 , 'SEQUENCE' , 'OTHER' ) object_type , count(*) quantity from sys.obj$ o where o.type# > 1 group by decode (o.type#,1,'INDEX' , 2,'TABLE' , 3 , 'CLUSTER' , 4, 'VIEW' , 5 , 'SYNONYM' , 6 , 'SEQUENCE' , 'OTHER' ) union select 'COLUMN' , count(*) from sys.col$ union select 'DB LINK' , count(*) from 22。按用户查看object种类 select u.name schema, sum(decode(o.type#, 1, 1, NULL)) indexes, sum(decode(o.type#, 2, 1, NULL)) tables, sum(decode(o.type#, 3, 1, NULL)) clusters, sum(decode(o.type#, 4, 1, NULL)) views, sum(decode(o.type#, 5, 1, NULL)) synonyms, sum(decode(o.type#, 6, 1, NULL)) sequences, sum(decode(o.type#, 1, NULL, 2, NULL, 3, NULL, 4, NULL, 5, NULL, 6, NULL, 1)) others from sys.obj$ o, sys.user$ u where o.type# >= 1 and u.user# = o.owner# and u.name <> 'PUBLIC' group by u.name order by sys.link$ union select 'CONSTRAINT' , count(*) from sys.con$ 23。有关connection的相关信息 1)查看有哪些用户连接 select s.osuser os_user_name, decode(sign(48 - command), 1, to_char(command), 'Action Code #' || to_char(command) ) action, p.program oracle_process, status session_status, s.terminal terminal, s.program program, s.username user_name, s.fixed_table_sequence activity_meter, '' query, 0 memory, 0 max_memory, 0 cpu_usage, s.sid, s.serial# serial_num from v$session s, v$process p where s.paddr=p.addr and s.type = 'USER' order by s.username, s.osuser 2)根据v.sid查看对应连接的资源占用等情况 select n.name, v.value, n.class, n.statistic# from v$statname n, v$sesstat v where v.sid = 71 and v.statistic# = n.statistic# order by n.class, n.statistic# 3)根据sid查看对应连接正在运行的sql select /*+ PUSH_SUBQ */ command_type, sql_text, sharable_mem, persistent_mem, runtime_mem, sorts, version_count, loaded_versions, open_versions, users_opening, executions, users_executing, loads, first_load_time, invalidations, parse_calls, disk_reads, buffer_gets, rows_processed, sysdate start_time, sysdate finish_time, '>' || address sql_address, 'N' status from v$sqlarea where address = (select sql_address from v$session where sid = 71) 24.查询表空间使用情况select a.tablespace_name "表空间名称", 100-round((nvl(b.bytes_free,0)/a.bytes_alloc)*100,2) "占用率(%)", round(a.bytes_alloc/1024/1024,2) "容量(M)", round(nvl(b.bytes_free,0)/1024/1024,2) "空闲(M)", round((a.bytes_alloc-nvl(b.bytes_free,0))/1024/1024,2) "使用(M)", Largest "最大扩展段(M)", to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') "采样时间" from (select f.tablespace_name, sum(f.bytes) bytes_alloc, sum(decode(f.autoextensible,'YES',f.maxbytes,'NO',f.bytes)) maxbytes from dba_data_files f group by tablespace_name) a, (select f.tablespace_name, sum(f.bytes) bytes_free from dba_free_space f group by tablespace_name) b, (select round(max(ff.length)*16/1024,2) Largest, ts.name tablespace_name from sys.fet$ ff, sys.file$ tf,sys.ts$ ts where ts.ts#=ff.ts# and ff.file#=tf.relfile# and ts.ts#=tf.ts# group by ts.name, tf.blocks) c where a.tablespace_name = b.tablespace_name and a.tablespace_name = c.tablespace_name 25. 查询表空间的碎片程度 select tablespace_name,count(tablespace_name) from dba_free_space group by tablespace_name having count(tablespace_name)>10; alter tablespace name coalesce; alter table name deallocate unused; create or replace view ts_blocks_v as select tablespace_name,block_id,bytes,blocks,'free space' segment_name from dba_free_space union all select tablespace_name,block_id,bytes,blocks,segment_name from dba_extents; select * from ts_blocks_v; select tablespace_name,sum(bytes),max(bytes),count(block_id) from dba_free_space group by tablespace_name;
26.监控索引是否使用alter index &index_name monitoring usage;alter index &index_name nomonitoring usage;select * from v$object_usage where index_name = &index_name;
27.求数据文件的I/O分布select df.name,phyrds,phywrts,phyblkrd,phyblkwrt,singleblkrds,readtim,writetim ?from v$filestat fs,v$dbfile df where fs.file#=df.file# order by df.name;
28.求某个隐藏参数的值?col ksppinm format a54?col ksppstvl format a54?select ksppinm, ksppstvl ? from x$ksppi pi, x$ksppcv cv ?where cv.indx=pi.indx and pi.ksppinm like '\_%' escape '\' and pi.ksppinm like '%¶meer%';
29.求系统中较大的latchselect name,sum(gets),sum(misses),sum(sleeps),sum(wait_time) ?from v$latch_children group by name having sum(gets) > 50 order by 2;
30.求归档日志的切换频率(生产系统可能时间会很长)select start_recid,start_time,end_recid,end_time,minutes from (select test.*, rownum as rn ?from (select b.recid start_recid,to_char(b.first_time,'yyyy-mm-dd hh24:mi:ss') start_time,? a.recid end_recid,to_char(a.first_time,'yyyy-mm-dd hh24:mi:ss') end_time,round(((a.first_time-b.first_time)*24)*60,2) minutes ?from v$log_history a,v$log_history b where a.recid=b.recid+1 and b.first_time > sysdate - 1 ? order by a.first_time desc) test) y where y.rn < 30
31.求回滚段正在处理的事务select a.name,b.xacts,c.sid,c.serial#,d.sql_text?from v$rollname a,v$rollstat b,v$session c,v$sqltext d,v$transaction ewhere a.usn=b.usn and b.usn=e.xidusn and c.taddr=e.addr ?and c.sql_address=d.address and c.sql_hash_value=d.hash_value order by a.name,c.sid,d.piece;
32.求出无效的对象select 'alter procedure '||object_name||' compile;' ?from dba_objects where status='INVALID' and owner='&' and object_type in ('PACKAGE','PACKAGE BODY');/select owner,object_name,object_type,status from dba_objects where status='INVALID';
--求process/session的状态select p.pid,p.spid,s.program,s.sid,s.serial# ?from v$process p,v$session s where s.paddr=p.addr;
--求当前session的状态select sn.name,ms.value ?from v$mystat ms,v$statname sn where ms.statistic#=sn.statistic# and ms.value > 0;
--求表的索引信息select ui.table_name,ui.index_name ?from user_indexes ui,user_ind_columns uic where ui.table_name=uic.table_name and ui.index_name=uic.index_name ?and ui.table_name like '&table_name%' and uic.column_name='&column_name';
--显示表的外键信息col search_condition format a54select table_name,constraint_name? from user_constraints ?where constraint_type ='R' and constraint_name in (select constraint_name from user_cons_columns where column_name='&1');
select rpad(child.table_name,25,' ') child_tablename,?rpad(cp.column_name,17,' ') referring_column,rpad(parent.table_name,25,' ') parent_tablename,?rpad(pc.column_name,15,' ') referred_column,rpad(child.constraint_name,25,' ') constraint_name ?from user_constraints child,user_constraints parent,????? user_cons_columns cp,user_cons_columns pc where child.constraint_type = 'R' and child.r_constraint_name = parent.constraint_name and? child.constraint_name = cp.constraint_name and parent.constraint_name = pc.constraint_name and? cp.position = pc.position and child.table_name ='&table_name'?order by child.owner,child.table_name,child.constraint_name,cp.position;
--显示表的分区及子分区(user_tab_subpartitions)col table_name format a16col partition_name format a16col high_value format a81select table_name,partition_name,HIGH_VALUE from user_tab_partitions where table_name='&table_name'
--使用dbms_xplan生成一个执行计划explain plan set statement_id = '&sql_id' for &sql;select * from table(dbms_xplan.display);
--求某个事务的重做信息(bytes)select s.name,m.value ? from v$mystat m,v$statname s ?where m.statistic#=s.statistic# and s.name like '%redo size%';
--求cache中缓存超过其5%的对象select o.owner,o.object_type,o.object_name,count(b.objd)?from v$bh b,dba_objects owhere b.objd = o.object_id ?group by o.owner,o.object_type,o.object_name?having count(b.objd) > (select to_number(value)*0.05 from v$parameter where name = 'db_block_buffers');
--求谁阻塞了某个session(10g)select sid, username, event, blocking_session,? seconds_in_wait, wait_time?from v$session where state in ('WAITING') and wait_class != 'Idle';
--求session的OS进程IDcol program format a54select p.spid "OS Thread", b.name "Name-User", s.program?from v$process p, v$session s, v$bgprocess b?where p.addr = s.paddr and p.addr = b.paddr UNION ALLselect p.spid "OS Thread", s.username "Name-User", s.program?from v$process p, v$session s where p.addr = s.paddr and s.username is not null;
--查会话的阻塞col user_name format a32select /*+ rule */ lpad(' ',decode(l.xidusn ,0,3,0))||l.oracle_username user_name, o.owner,o.object_name,s.sid,s.serial# ?from v$locked_object l,dba_objects o,v$session s where l.object_id=o.object_id and l.session_id=s.sid order by o.object_id,xidusn desc ;
col username format a15col lock_level format a8col owner format a18col object_name format a32select /*+ rule */ s.username, decode(l.type,'tm','table lock', 'tx','row lock', null) lock_level, o.owner,o.object_name,s.sid,s.serial#?from v$session s,v$lock l,dba_objects o where l.sid = s.sid and l.id1 = o.object_id(+) and s.username is not null ;
--求等待的事件及会话信息/求会话的等待及会话信息select se.sid,s.username,se.event,se.total_waits,se.time_waited,se.average_wait? from v$session s,v$session_event sewhere s.username is not null and se.sid=s.sid and s.status='ACTIVE' and se.event not like '%SQL*Net%' order by s.username;
select s.sid,s.username,sw.event,sw.wait_time,sw.state,sw.seconds_in_wait? from v$session s,v$session_wait swwhere s.username is not null and sw.sid=s.sid and sw.event not like '%SQL*Net%' order by s.username;
--求会话等待的file_id/block_idcol event format a24col p1text format a12col p2text format a12col p3text format a12select sid,event,p1text, p1, p2text, p2, p3text, p3? from v$session_waitwhere event not like '%SQL%' and event not like '%rdbms%' and event not like '%mon%' order by event;
select name,wait_time from v$latch l where exists (select 1 from (select sid,event,p1text, p1, p2text, p2, p3text, p3? from v$session_waitwhere event not like '%SQL%' and event not like '%rdbms%' and event not like '%mon%') x where x.p1= l.latch#);
--求会话等待的对象col owner format a18col segment_name format a32col segment_type format a32select owner,segment_name,segment_type? from dba_extentswhere file_id = &file_id and &block_id between block_id and block_id + blocks - 1;
--求buffer cache中的块信息select o.OBJECT_TYPE, substr(o.OBJECT_NAME,1,10) objname , b.objd , b.status, count(b.objd) ?from? v$bh b, dba_objects o ?where b.objd = o.data_object_id and o.owner = '&1' group by o.object_type, o.object_name,b.objd, b.status ;
--求日志文件的空间使用select le.leseq current_log_sequence#, 100*cp.cpodr_bno/le.lesiz percentage_full?from x$kcccp cp,x$kccle le?where le.leseq =cp.cpodr_seq;
--求等待中的对象select /*+rule */ s.sid, s.username, w.event, o.owner, o.segment_name, o.segment_type, ?????? o.partition_name, w.seconds_in_wait seconds, w.state ? from v$session_wait w, v$session s, dba_extents o ?where w.event in (select name from v$event_name? where parameter1 = 'file#' ?? and parameter2 = 'block#' and name not like 'control%') ?? and o.owner <> 'sys' and w.sid = s.sid and w.p1 = o.file_id and w.p2 >= o.block_id and w.p2 < o.block_id + o.blocks
--求当前事务的重做尺寸select value? from v$mystat, v$statname?where v$mystat.statistic# = v$statname.statistic# and v$statname.name = 'redo size';
--唤醒smon去清除临时段column pid new_value Smonset termout offselect p.pid from sys.v_$bgprocess b,sys.v_$process p where b.name = 'SMON' and p.addr = b.paddr/set termout onoradebug wakeup &Smonundefine Smon
--求回退率select b.value/(a.value + b.value),a.value,b.value from v$sysstat a,v$sysstat b where a.statistic#=4 and b.statistic#=5;
--求DISK READ较多的SQLselect st.sql_text from v$sql s,v$sqltext st where s.address=st.address and s.hash_value=st.hash_value and s.disk_reads > 300;
--求DISK SORT严重的SQLselect sess.username, sql.sql_text, sort1.blocks ? from v$session sess, v$sqlarea sql, v$sort_usage sort1 ?where sess.serial# = sort1.session_num ?? and sort1.sqladdr = sql.address ?? and sort1.sqlhash = sql.hash_value? and sort1.blocks > 200;
--求对象的创建代码column column_name format a36column sql_text format a99select dbms_metadata.get_ddl('TABLE','&1') from dual;select dbms_metadata.get_ddl('INDEX','&1') from dual;
--求表的索引set linesize 131select a.index_name,a.column_name,b.status, b.index_typefrom user_ind_columns a,user_indexes bwhere a.index_name=b.index_name and a.table_name='&1';
求索引中行数较多的select index_name,blevel,num_rows,CLUSTERING_FACTOR,status from user_indexes where num_rows > 10000 and blevel > 0select table_name,index_name,blevel,num_rows,CLUSTERING_FACTOR,status from user_indexes where status <> 'VALID'
--求当前会话的SID,SERIAL#select sid, serial# from v$session where audsid = SYS_CONTEXT('USERENV','SESSIONID');
--求表空间的未用空间col mbytes format 9999.9999select tablespace_name,sum(bytes)/1024/1024 mbytes from dba_free_space group by tablespace_name;
--求表中定义的触发器select table_name,index_type,index_name,uniqueness from user_indexes where table_name='&1';select trigger_name from user_triggers where table_name='&1';
--求未定义索引的表select table_name from user_tables where table_name not in (select table_name from user_ind_columns);
--执行常用的过程exec print_sql('select count(*) from tab');exec show_space2('table_name');
--求free memoryselect * from v$sgastat where name='free memory';select a.name,sum(b.value) from v$statname a,v$sesstat b where a.statistic# = b.statistic# group by a.name;
查看一下谁在使用那个可以得回滚段,或者查看一下某个可以得用户在使用回滚段,找出领回滚段不断增长的事务,再看看如何处理它,是否可以将它commit,再不行就看看能否kill它,等等, 查看当前正在使用的回滚段的用户信息和回滚段信息:set linesize 121SELECT 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 sWHERE 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 rnwhere 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_tablestart 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 cwhere 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_pctfrom 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 bwhere a.parsing_user_id = b.user_id group by username;
--查看对象的缓存情况select OWNER,NAMESPACE,TYPE,NAME,SHARABLE_MEM,LOADS,EXECUTIONS,LOCKS,PINS,KEPTfrom 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
--查看某些用户的hashselect 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_ratiofrom 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.statusFROM v$rollname n,v$rollstat s,dba_rollback_segs dWHERE 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 announcementexec 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 anno2exec 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', options=>sys.dbms_logmnr.new);
exec sys.dbms_logmnr.add_logfile(logfilename=>'/home/oracle/oradata/esal/archive/1_22912.dbf', options=>sys.dbms_logmnr.addfile);exec sys.dbms_logmnr.add_logfile(logfilename=>'/home/oracle/oradata/esal/archive/1_22913.dbf', options=>sys.dbms_logmnr.addfile);exec sys.dbms_logmnr.add_logfile(logfilename=>'/home/oracle/oradata/esal/archive/1_22914.dbf', options=>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*/
发表评论
-
存储过程-test
2017-05-26 16:42 510select t.eqp_dcp_id as EQP_ID ... -
存储过程ppt分享
2017-05-25 09:43 829详情请参考附件压制包内的ppt -
Solaris 系统下安装Oracle11g R2和WebLogic10.3.0.0
2012-05-23 14:54 24121.首先创建系统用户和组 groupadd oi ... -
Oracle 大表复制方案存储过程实现
2012-02-23 15:15 1726procedure makePayPlayIraBakN ... -
关于英文操作系统中解析中文文件插入到oracle中乱码问题
2011-11-04 22:58 1355真实环境: windows 2008 英文版 weblog ... -
将txt,csv等文件导入到oracle
2011-09-17 23:08 1313项目使用Oracle数据库,项目开发完成后,由于遗留系统的定制 ... -
存储过程和触发器的区别
2007-12-05 16:37 7649存储过程 是 SQL 语句和 ...
相关推荐
以下是一些MySQL DBA常用的知识点,结合“mysql_mgr_test-master”这个文件名,我们可以推测这可能是一个包含MySQL管理测试脚本的项目库。 1. 数据库备份:备份是DBA工作中的关键环节,防止数据丢失。通常使用`...
Oracle DBA 常用脚本(外国网站上下载)
### DBA常用脚本知识点详解 #### 一、Oracle用户权限检查 对于Oracle数据库管理员(DBA)来说,定期审查数据库中的用户权限是一项至关重要的任务。这有助于确保系统的安全性,并且能够有效地管理不同用户对数据库...
这份"ORACLE_DBA常用脚本.ppt"资料详细介绍了DBA在管理Oracle数据库时的一些常用脚本和技巧。 首先,完整性约束是数据库设计的基础,确保数据的一致性和准确性。外键约束是实现引用完整性的关键,它限制了插入或...
以下是一些DBA常用的数据库脚本,主要用于监控Oracle数据库的表空间。 1. **监控表空间信息**: - 查询表空间详细信息:通过执行`SELECT`语句,可以获取表空间的名称、初始扩展量、下次扩展量、最小和最大扩展次数...
在数据库管理领域,DBA...老外提供的"DBA常用脚本"可能包含上述部分或全部内容,这些脚本可以帮助DBA高效地完成日常任务,提高工作效率,同时减少人为错误。在使用时,务必根据自己的数据库环境和需求进行适当的调整。
### ORACLE DBA常用脚本解析与应用 在Oracle数据库管理与优化中,熟练掌握一系列脚本对于提高数据库性能、解决复杂问题至关重要。以下是对给定脚本的深入解析及其实用场景说明。 #### 1. 监控系统资源与性能 - **...
在这个"oracle_dba常用sql脚本分类文档"中,我们可能会发现一系列针对DBA工作的实用SQL脚本,这些脚本能够帮助提升工作效率,确保数据库的稳定运行。 1. 数据库安装与升级: 在Oracle数据库的部署过程中,DBA需要...
oracle dba常用sql脚本分类文档.pdf
以下是一些关于Oracle DBA常用脚本的知识点: 1. 完整性约束检查: - 完整性约束是数据库设计的重要部分,包括主键、外键等,确保数据的一致性和准确性。 - 外键约束对性能可能有影响,因为它们会导致行级锁定,...
Linux Shell 脚本是DBA在管理Oracle数据库时的一项重要工具,特别是在自动化日常管理和监控任务方面。本文主要面向对Linux脚本不熟悉的DBA,旨在介绍如何利用Bash Shell脚本来实现Oracle数据库在Linux环境下的高效...
### Oracle DBA 数据库日常维护手册:常用SQL脚本解析 在IT行业中,数据库的高效稳定运行对于企业的业务连续性和数据安全至关重要。Oracle作为全球领先的数据库管理系统之一,其日常维护工作是确保系统性能、安全与...
Oracle DBA指南+10G备份与恢复+Oracle_DBA_数据库日常维护手册_常用SQL_脚本
### 8个DBA最常用的监控Oracle数据库的常用Shell脚本 #### 1. 检查实例的可用性 为了确保Oracle数据库的稳定运行,DBA需要定期检查Oracle实例是否正常工作。此脚本利用`ps`命令来查找与Oracle实例相关的进程。 **...
Oracle DBA(数据库管理员)在日常管理中会频繁使用各种SQL脚本来监控和优化数据库的性能。以下是一些常见的Oracle SQL脚本及其用途: 1. **监控实例等待事件**: 使用`v$session_wait`视图,可以查看当前正在等待...
首先,我们将回顾一些 DBA 常用的 Unix 命令,然后介绍如何通过 Unix Cron 来定时执行 DBA 脚本。最后,我们将介绍 8 个重要的脚本来监控 Oracle 数据库。 Unix 命令 Unix 命令是 DBA 的基本工具,以下是一些...
ORACLE DBA 日常维护数据库使用的SQL脚本 在Oracle数据库运行期间 DBA应该对数据库的运行日志及表空间的使用 情况进行监控及早发现数据库中存在的问题
DBA常用监控脚本包括查询上述数据字典视图的SQL语句。例如,要查看当前所有数据库会话,可以使用如下脚本: ```sql SELECT SID, USERNAME, PROGRAM FROM V$SESSION; ``` 要查看数据库的锁和等待事件,可以使用: ```...