SQL_TRACE set linesize 10000; set pagesize 20000; set serveroutput on; alter session set sql_trace=true; select count(*) from firefox; alter session set sql_trace=false; --查看sql_trace trace file select * from v$diag_info where name like 'Default%'; select sid,serial# from v$session ; variable x number; exec :x:=1; alter session set events '10046 trace name context forever,level 12'; select count(*) from firefox where object_id=:x; alter session set events '10046 trace name context off'; select object_name from dba_objects where object_id=426 or object_id=427 SQL> select * from aux_stats$; 收集系統信息 exec dbms_stats.gather_system_stats(gathering_mode=>'start'); alter system flush_cache; select count(*) from fire_t01; select * from aux_stats$; 初始化參數; db_file_multiblock_read_count 查看數據表一共有多少個塊; select blocks from user_tables where table_name='FIREFOX'; set autotrace on; SELECT * FROM FIREFOX; SELECT /*+ blocks/k=cost */ 1029/10.4 from dual; 查看數據塊大小 show parameter db_block_size; select * from sys.aux_stats$; SYSSTATS_MAIN IOSEEKTIM 10 SYSSTATS_MAIN IOTFRSPEED 4096 SYSSTATS_MAIN CPUSPEEDNW 2657.0122 #單塊讀的時間 sreadtim = IOSEEKTIM+(size of one block/IOTFRSPEED). =10+(8192/4096)=12 #多塊數據塊讀取的時間 mreadtim=IOSEEKTIM+(MBRC * SIZE OF one block) / IOTFRSPEED) =10+((16*8192)/4096)=42 io_cost=(1046(blocks)/16)*(42/12)=232.75 cpu_cost=cpu_cost=cpucycles/(cpuspeed*sreadtim) =116192792/(2657.0122*12*1000)=4.48 cost=io_cost+cpu_cost = 232.75 + 4.48 = 如何查看cpucycles:PLAN_TABLE、PLAN_TABLE$; create table firefox1 as select * from firefox where rownum<100; create index idx_firefox on firefox(object_id); create index idx_firefox1 on firefox1(object_id); begin dbms_stats.gather_table_stats( user, 'firefox', cascade => true, estimate_percent => null, method_opt =>'for all columns size 1' ); end; / begin dbms_stats.gather_table_stats( user, 'firefox1', cascade => true, estimate_percent => null, --徹底精確地分析; method_opt =>'for all columns size 1' ); end; / alter session set events '10053 trace name context forever,level 12'; select * from firefox,firefox1 where firefox.object_id = firefox1.object_id; alter session set events '10053 trace name context off'; select * from v$diag_info where name like 'Default%'; 對SGA區的動態調整; SQL> show sga; 網絡鏈接 --session &processes; SQL> select username,paddr from v$session where username is not null; USERNAME PADDR ------------------------------ ---------------- SYS 00000000F04DAE60 SYS 00000000F04DAE60 C##SCOTT 00000000F04DBEA0 select addr from v$process where background is null and addr='00000000F04DAE60'; select * from v$process where background is null and addr='00000000F04DAE60'; set autotrace on stat; select username,paddr from v$session where username is not null; select addr from v$process where background is null and addr='00000000F04DAE60'; CBO計算成本時索引的權重修正值. show parameter OPTIMIZER_INDEX_COST_ADJ; alter session set OPTIMIZER_INDEX_COST_ADJ=10; 優化器--optimizer_mode first_rows [1|10|100|1000] first 優化器--optimizer_dynamic_sampling 動態採樣的級別0to10 默認值(9i 1, >= 10g 2) 查看當前sql/plus 的SID SELECT sid, serial# FROM v$session WHERE audsid=SYS_CONTEXT('USERENV','SESSIONID'); select a.name,b.value from v$sesstat b.v$statname a where a.static#=b.statistic# and a.name ='CPU used by this session' and sid=69; 顯示各類文件的I/O統計信息 - 數據文件,臨時文件,控制文件,日誌文件,歸檔文件... select file_no,filetype_name,LARGE_READ_MEGABYTES,SMALL_READ_MEGABYTES,SMALL_SYNC_READ_LATENCY from v$iostat_file; 對象--v$segstat 得到某對象的各種統計信息; select * from v$segstat where obj#=79605 and statistic_name='physical_reads';