您好,登錄后才能下訂單哦!
################################################V$active_session_history################################################ set line 1000 col session_id for 99999999 col session_serial# for 9999999 col program for a30 col sql_id for a30 col event for a30 col seq# for 999999 col count(*) for 99999 select session_id,session_serial#,program,sql_id,event,seq#,count(*) from v$active_session_history where sample_time between to_date('2018-12-27 08:00:00','yyyy-mm-dd hh34:mi:ss') and to_date('2018-12-28 09:00:00','yyyy-mm-dd hh34:mi:ss') and sql_id is not null group by session_id,session_serial#,program,sql_id,event,seq# having count(*) >1; set line 100 col sample_time for a30 col sample_id for 9999999 col event for a30 col seq# for 9999999999 col sql_id for a30 select sample_time,sample_id,event,seq#,sql_id from v$active_session_history where session_id=&session_id and session_serial#=&session_serial# and event='&event' and seq#=&seq#; set line 200 col session_id for 999999999999 col session_serial for 9999999999 col xid for 9999999999 col program for a30 col event for a30 col blocking_session for 99999999 select session_id,session_serial,xid,program,event,blocking_session from v$active_session_history where between to_date('2018-12-27 08:00:00','yyyy-mm-dd hh34:mi:ss') and to_date('2018-12-28 09:00:00','yyyy-mm-dd hh34:mi:ss') and sql_id is not null and xid is not null set line 200 col session_id for 999999 col session_serial# for 9999999 col seq# for 99999999 col event for a30 col count(*) for 999999 select inst_num, session_id,session_serial#,seq#,event, count(*) from dba_hist_active_sess_history where sample_time between to_date('2018-12-28 00:00:00','yyyy-mm-dd hh34:mi:ss') and to_date('2018-12-29 00:00:00','yyyy-mm-dd hh34:mi:ss') group by inst_num, session_id,session_serial#,seq#,event order by count(*); set line 100 col sample_id for 999999 col inst_num for 99 col blocking_session for 999999 select sample_id,inst_num,blocking_session from dba_hist_active_sess_history where sample_time between to_date('2018-12-28 00:00:00','yyyy-mm-dd hh34:mi:ss') and to_date('2018-12-29 00:00:00','yyyy-mm-dd hh34:mi:ss') and event='&event' and inst_num=&inst_num and session_id=&session_id and session_serial=&session_serial and seq#=&seq# set line 100 col program for a30 col inst_num for 99 col sql_id for a30 select program,inst_num,event,sql_id from dba_hist_active_sess_history where sample_id=&sample_id and inst_num=&inst_num and session_id=&session_id and session_serial#=&session_serial# -- in_connection_mgmt -- in_parse -- in_hard_parse -- in_sql_execution -- in_plsql_execution -- in_plsql_rpc -- in_plsql_compliation -- in_java_execution -- in_bind -- in_cursor_close -- in_sequence_load select in_connection_mgmt, in_parse, in_hard_parse, in_sql_execution, in_plsql_execution, in_plsql_rpc, in_plsql_compliation, in_java_execution, in_bind, in_cursor_close, in_sequence_load from dba_hist_active_sess_history where inst_num=&inst_num and SESSION_ID=&session_id and session_serial#=&session_serial# set line 100 col session_id for 99999999 col session_serial# for 9999999 col sql_id for a30 col sql_exec_id for 9999999 col count(*) for 99999999 select session_id,session_serial#,sql_id,sql_exec_id,count(*) from dba_hist_active_sess_history group by session_id,session_serial#,sql_id,sql_exec_id order by count(*); set line 100 col opname for a30 col plsql_entry_id for 999999 col p1 for a30 col p2 for a30 col p3 for a30 select opname,plsql_entry_id,p1,p2,p3 from dba_hist_active_sess_history where instance_number=&instance_number and session_id=&session_id and session_serial#=&session_serial set line 100 col program for a30 col inst_num for 99 col blocking_session for 99999999 col blocking_session_serial# for 99999999999 col blocking_inst_id for 9999 select program,inst_num,event,blocking_session,blocking_session_serial#,blocking_inst_id,sql_id from dba_hist_active_sess_history where inst_num=&inst_num and session_id=&session_id and session_serial#=&session_serial# select type,parameter from v$rowcache where cache#=10 ###############################V$session_longops,v$session#####查看進(jìn)程剩余耗時(shí)##################################### set line 200 col sid for 999999999999 col SERIAL# for 99999999999 col PROGRAM for a30 col opname for a30 col time_remaining for 99999999999999 SELECT a.SID,a.SERIAL#,a.PROGRAM "程序進(jìn)程",b.OPNAME "操作名稱",b.TIME_REMAINING "剩余時(shí)間(秒)" FROM v$session a,v$session_longops b WHERE a.SID = b.SID AND a.SERIAL# = b.SERIAL# AND a.PROGRAM LIKE '%rman%' AND time_remaining >0; #############################oradebug######################################################################################### 1.session Tracing alter session set tracefile_identifier='10046'; alter session set timed_statistics = true; alter session set statistics_level=all; alter session set max_dump_file_size = unlimited; alter session set events '10046 trace name context forever,level 12'; 2.tracing process select p.PID,p.SPID,s.SID from v$process p,v$session s where s.paddr = p.addr and s.sid = &SESSION_ID / select 'ospid: ' || p.spid || ' # ''' ||s.sid||','||s.serial#||''' '|| s.osuser || ' ' ||s.machine ||' '||s.username ||' '||s.program line from v$session s , v$process p where p.addr = s.paddr and s.username <> ' '; connect / as sysdba oradebug setospid 9834 oradebug unlimit oradebug event 10046 trace name context forever,level 12 oradebug tracefile_name oradebug event 10046 trace name context off connect / as sysdba oradebug setorapid 9834 oradebug unlimit oradebug event 10046 trace name context forever,level 12 oradebug tracefile_name oradebug event 10046 trace name context off -- 10053 trace ####################################################v$SQLAREA#################################################################### yyyy-mm-dd hh34:mi:ss set line 200 col sql_id for a30 col last_active_time for a30 col first_load_time col last_load_time col executions col buffer_gets col user_io_wait_time col cpu_time col elapsed_time col physical_read_requests col physical_read_bytes select sql_id, last_active_time, first_load_time, last_load_time, executions, buffer_gets, user_io_wait_time, cpu_time, elapsed_time, physical_read_requests, physical_read_bytes from v$SQLAREA order by physical_read_bytes desc; ##############################################實(shí)驗(yàn):檢查兩個(gè)表中的數(shù)據(jù)及對(duì)應(yīng)的數(shù)據(jù)的條數(shù)是否相同######################################## 1.建立視圖 create or replace view v as select * from emp where deptno!=10 union all select * from emp where ename='SCOTT' 2.要求查找視圖V和表emp中不同的數(shù)據(jù) SELECT rownum,empno,ename FROM v WHERE ename='SCOTT'; SELECT rownum,empno,ename FROM emp WHERE ename='SCOTT'; 3.比較數(shù)據(jù)集不同 select v.empno,v.ename ,b.empno,b.ename from v full join emp b on(v.empno=b.empno) where (v.empno is null or b.empno is null); ####################################################統(tǒng)計(jì)信息###################################### dba_tab_statistics dba_tab_col_statistics set line 100 -- var low_value number; -- var high_value varchar2(100); -- select DBMS_STATS.CONVERT_RAW_VALUE('yuiovbssas',:high_value) from dual; col owner for a10 col table_name for a20 col column_name for a30 col high_value for a30 col low_value for a30 col num_nulls for 9999 col histogram for a30 select owner,table_name,column_name,high_value,low_value,num_nulls,histogram from dba_tab_col_statistics where table_name='' and column_name='' and owner=''; set line 200 col owner for a20 col table_name for a20 col num_rows for 99999 col partition_name for a20 col LAST_ANALYZED for a30 col blocks for 99999 col empty_blocks for 99999 select owner,table_name,num_rows,partition_name,LAST_ANALYZED,blocks,empty_blocks from dba_tab_statistics where owner='' and table_name=''; -- -- -- -- -- -- -- -- -- -- 索引統(tǒng)計(jì)系信息-- -- -- -- -- -- -- -- 查看索引的聚簇因子, -- 聚簇因子應(yīng)該與表的塊數(shù)近似 set line 100 col ower for a10 col table_name for a20 col index_name for a20 col clustering_factor for 999999999 col NUM_ROWS for 99999 select owner,table_name,index_name,clustering_factor,NUM_ROWS from dba_indexes where index_name='&index_name' and owner='&owner' and table_name='&table_name'; 查看數(shù)據(jù)表當(dāng)前占用block數(shù)目 select count(dbms_rowid.rowid_block_number(rowid)) from &table_name; -- -- -- -- -- -- -- -- -- -- -- --列統(tǒng)計(jì)信息 -- -- -- -- -- -- -- -- -- -- -- -- set line 100 verify off col low_value for a30 col high_value for a30 col num_distinct for 99999 col num_nulls for 9999999 select low_value,high_value,num_distinct,num_nulls from dba_tab_col_statistics where table_name='&table_name' and owner='&owner' and column_name='&column_name'; -- 1 41,43,43,45,53,53,24 5F75746C245F6C6E635F696E645F7061727473 10807 0 var l varchar2(100); exec dbms_stats.convert_row_value('5F75746C245F6C6E635F696E645F7061727473',:l); print l; #######################V$sqlarea######################################## set line 200 col sql_id for a30 col plan_hash_value for 30 col executions for 99999 col first_load_time for a30 col disk_reads for 99999 col buffer_gets for 9999999 col cpu_time for 9999999999 col last_load_time for 999999999 col last_active_time for 99999999 col loads for 999999 select sql_id,plan_hash_value,executions,first_load_time,disk_reads,buffer_gets,cpu_time,last_load_time,last_active_time,loads from v$sqlarea where sql_id='<>'; ###################################################################查詢隱含參數(shù) SELECT KSPPINM, KSPPSTVL, KSPPDESC FROM X$KSPPI X, X$KSPPCV Y WHERE X.INDX = Y.INDX AND KSPPINM = '_db_file_optimizer_read_count'; #################通過創(chuàng)建索引來避免全表掃描,不必要的排序,函數(shù)索引,重建索引避免全表掃描################# 1.創(chuàng)建復(fù)合索引 create index <index_name> on <table_name>(column_name,0) tablespace <tablespace_name>; 原理:雖然對(duì)于單鍵值B樹索引而言NULL值不入索引,但對(duì)于復(fù)合索引B樹索引來說,NULL值是入索引的。 2.對(duì)于需要排序的列創(chuàng)建索引 create index <index_name> table_name(column_name) tablespace <tablespace_name>; 3. 百分號(hào)在最前面的like條件確實(shí)是沒法走索引的,-----'%....' 但同時(shí)我們也知道對(duì)于有百分號(hào)的like條件, 如果百分號(hào)的like條件的最后面,則這種情況下是可以走索引的。-----'...%' 在不改變SQL的情形下把百分號(hào)從like條件的最前面移到最后面 create index <index_name> on <table_name>(reverse(column_name)) ; 4.創(chuàng)建全局索引 create index <index_name> on <table_name> (<column_name>) online tablespace <tablespace_name> ###################對(duì)癥下藥 1.如果是統(tǒng)計(jì)信息不準(zhǔn)或是因?yàn)镃BO計(jì)算某些SQL的成本所用的公式先天不足而導(dǎo)致的SQL性能問題, 我們可以通過重新收集統(tǒng)計(jì)信息,或者手動(dòng)修改統(tǒng)計(jì)信息,或者使用Hint來加以解決。 2.如果是SQL語句的寫法問題,我們可以通過在不更改業(yè)務(wù)邏輯的情況下改寫SQL來加以解決。 3.如果是不必要的全表掃描/排序而導(dǎo)致的目標(biāo)SQL的性能問題,我們可以通過建立合適的索引(包括函數(shù)索引、位圖索引)來解決。 4.如果是因?yàn)楦鞣N原因?qū)е碌哪繕?biāo)SQL的執(zhí)行計(jì)劃不穩(wěn)定,可以通過使用hint、sql profile或者spm來加以解決。 5.如果是表或者索引的不良設(shè)計(jì)導(dǎo)致的目標(biāo)SQL的性能問題,我們可以通過重新設(shè)計(jì)表/索引,重新組織表的里的數(shù)據(jù)來加以解決。 6.如果上述調(diào)整措施都失效,可以考慮用并行來縮短目標(biāo)SQL的執(zhí)行時(shí)間。 7.如果上述調(diào)整措施都失效,調(diào)整SQL。 #################創(chuàng)建索引############################## create index <index_name> table_name(column_name) tablespace <tablespace_name> online nologging parallel 2; alter index <index_name> noparallel; ##################分區(qū)表信息確認(rèn)################## 1. set line 100 col table_name for a30 col num_rows for 999999 col blocks for 9999999 col avg_row_len for 99999999 col partitioned for a10 col ext_M for 9999999 select table_name, num_rows ,--記錄數(shù) blocks, avg_row_len, partitioned, --是否分區(qū) num_rows * avg_row_len /1024/1024/1024/0.9 est_M -- "數(shù)據(jù)量大小" from dba_tables where table_name='&table_name'; set line 100 col partitioning_type for a10 col subpartitioning_type for a10 select partitioning_type, --分區(qū)類型 subpartitioning_type from dba_part_tables where table_name='&table_name' set line 100 col owner for a10 col name for a20 col object_type for a30 col column_name for a30 --分區(qū)列 col column_position for a30 select * from dba_part_key_columns where name ='&table_name'; #############SPM######################## 在當(dāng)前session中禁掉spm并同時(shí)開啟自動(dòng)捕獲sql plan baseline alter session set optimizer_use_sql_plan_baseline=false; alter session set optimizer_capture_sql_plan_baseline=true; select sql_handle,plan_name,origin,enabled,accepted,sql_text from dba_sql_plan_baseline where sql_text like ''; ############################執(zhí)行計(jì)劃###################### alter session set statistics_level='ALL' ; set line 200 pages 100 select * from table(dbms_xplan.display_cursor(null,null,'allstats last')); ------------------------------------------------------------------------------------- | Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers | ------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | | 9 |00:00:00.01 | 4 | |* 1 | COUNT STOPKEY | | 1 | | 9 |00:00:00.01 | 4 | | 2 | TABLE ACCESS FULL| T1 | 1 | 9 | 9 |00:00:00.01 | 4 | ------------------------------------------------------------------------------------- Starts:表示每個(gè)具體執(zhí)行計(jì)劃步驟被重復(fù)執(zhí)行的次數(shù) E-Rows:表示執(zhí)行計(jì)劃中cbo對(duì)每一個(gè)具體執(zhí)行計(jì)劃步驟返回結(jié)果集cardinality的預(yù)估值 A-Rows:表示執(zhí)行計(jì)劃中每個(gè)具體步驟的返回結(jié)果集的cardinality的實(shí)際值 A-Time:表示執(zhí)行計(jì)劃中每一個(gè)具體執(zhí)行計(jì)劃中實(shí)際執(zhí)行時(shí)間 Buffers:表示執(zhí)行計(jì)劃中每一個(gè)具體執(zhí)行計(jì)劃步驟實(shí)際消耗的邏輯讀 ###########################選擇率################################3 對(duì)于like '%...%'這樣的模糊查詢條件,cbo默認(rèn)的可選擇率5%來評(píng)估其返回結(jié)果集的cardinality的值 ###################查詢表空間使用率 COLUMN ts_name format a35 heading "Tablespace" COLUMN unalloc_size format 999,999 heading "Unalloc(MB)" COLUMN used_size format 999,999,999 heading "Used(MB)" COLUMN free_size format 999,999 heading "Free(MB)" COLUMN capacity format 99,99 heading "Used_pct(%)" SELECT a.tablespace_name ts_name ,a.unalloc_size ,nvl(f.free_size, 0) free_size ,a.used_size - nvl(f.free_size, 0) used_size ,round((a.used_size - nvl(f.free_size, 0)) / (a.unalloc_size + a.used_size) ,2)*100 capacity FROM (SELECT tablespace_name ,round(SUM(bytes) / 1024 / 1024) free_size ,round(AVG(bytes)/1024/1024) avg_size FROM dba_free_space GROUP BY tablespace_name) f ,(SELECT tablespace_name ,round(SUM(user_bytes) / 1024 / 1024) used_size ,round(SUM(decode(autoextensible ,'YES' ,decode(sign(maxbytes - user_bytes) ,-1 ,0 ,maxbytes - user_bytes) ,0)) / 1024 / 1024) unalloc_size FROM dba_data_files WHERE status='AVAILABLE' GROUP BY tablespace_name) a WHERE 1 = 1 AND a.tablespace_name = f.tablespace_name(+) ORDER BY capacity DESC; ######################用戶密碼過期查改 select username,account_status,PROFILE from dba_users where username='&username'; SELECT * FROM dba_profiles WHERE profile='DEFAULT' AND resource_name='PASSWORD_LIFE_TIME'; ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED; select username,account_status,PROFILE from dba_users where username='&username'; -------------------------------------------------------------------更新分割線2019-1-16------------------------------------------------ #########################表空間數(shù)據(jù)文件丟失,處理方法###################### startup mount alter database datafile 7 offline drop; (在非歸檔模式下脫機(jī)數(shù)據(jù)文件,需要加上drop參數(shù)) alter database open; 數(shù)據(jù)庫開啟后,現(xiàn)在可以重新將表空間脫機(jī) alter tablespace <tablespace_name> offline for recover;(當(dāng)數(shù)據(jù)文件被誤刪時(shí),表空間的脫機(jī)命令需要加上for recover參數(shù)) ##################創(chuàng)建兩個(gè)新的聯(lián)機(jī)日志文件組,并進(jìn)行一次手工的日志切換 alter database add logfile group 4 ('<logfile_path2>','<logfile_path3>') size 200m; alter database add logfile group 5 ('<logfile_path2>','<logfile_path3>') size 200m; alter system switch logfile; ###############創(chuàng)建聯(lián)機(jī)日志文件組 alter database add logfile member '<logfile_path>' to group 1; alter database add logfile member '<logfile_path>' to group 2; alter database add logfile member '<logfile_path>' to group 3; ###############如何轉(zhuǎn)移system表空間 1.startup mount 2.!mv <old_file_name> <new_file_name> 3.alter database rename file '<old_file_name>' to '<new_file_name>'; 4.alter database open; ##############如何轉(zhuǎn)移非system表空間 1.alter tablespace <tablespace_name> offline; 2.!mv <old_file_name> <new_file_name> 3.alter tablespace <tablespace> rename datafile '<old_file_name>' to '<new_file_name>'; 4.alter tablespace <tablespace_name> online; ###############創(chuàng)建臨時(shí)表空間組 使用臨時(shí)表空間組的好處 1.同一個(gè)用戶,在不同的session里可以使用不同的臨時(shí)表空間 每一個(gè)用戶有一個(gè)默認(rèn)的臨時(shí)表,同一個(gè)用戶登錄多個(gè)session的時(shí)候,如果不使用臨時(shí)表空間組,那么所有的session使用同一個(gè)臨時(shí)表空間,容易產(chǎn)生瓶頸問題。 2.在并行操作中,不同的從屬進(jìn)程可以使用不同的臨時(shí)表空間 3.在數(shù)據(jù)庫層面可以同時(shí)指定多個(gè)默認(rèn)臨時(shí)表空間 create tempoary tablespace temp1 tempfile '<file_path>' size 10m; create tempoary tablespace temp2 tempfile '<file_path>' size 10m; create tempoary tablespace temp3 tempfile '<file_path>' size 10m; create tempoary tablespace temp4 tempfile '<file_path>' size 10m; alter tablespace temp1 tablespace group temp_test; alter tablespace temp2 tablespace group temp_test; alter tablespace temp3 tablespace group temp_test; alter tablespace temp4 tablespace group temp_test; ############刪除臨時(shí)表空間組(當(dāng)組內(nèi)沒有成員時(shí),該空間組自動(dòng)刪除) alter tablespace temp1 tablespace group ''; alter tablespace temp2 tablespace group ''; alter tablespace temp3 tablespace group ''; alter tablespace temp4 tablespace group ''; -------------------------------------------------------------------更新分割線2019-1-21-------------------------------------------------------------------------------------- ################創(chuàng)建用戶 create user <username> profile default identified by <password> password expire default tablespace <default_tablespace> tempoary tablespace <temp_tablespace> account unlock; password expire :用來設(shè)置用戶口令過期,失效,強(qiáng)制用戶登錄數(shù)據(jù)庫時(shí)必須修改口令 account unlock:創(chuàng)建用戶的時(shí)候解鎖用戶,默認(rèn)該選項(xiàng) ###################################查看最近7天的DB time########################## set line 100 col DATE_TIME for a40 col STAT_NAME for a40 col per_sec for 99999 WITH sysstat AS (select sn.begin_interval_time begin_interval_time, sn.end_interval_time end_interval_time, ss.stat_name stat_name, ss.value e_value, lag(ss.value, 1) over(order by ss.snap_id) b_value from dba_hist_sysstat ss, dba_hist_snapshot sn where trunc(sn.begin_interval_time) >= sysdate - 7 and ss.snap_id = sn.snap_id and ss.dbid = sn.dbid and ss.instance_number = sn.instance_number and ss.dbid = (select dbid from v$database) and ss.instance_number = (select instance_number from v$instance) and ss.stat_name = 'DB time') select to_char(BEGIN_INTERVAL_TIME, 'mm-dd hh34:mi') || to_char(END_INTERVAL_TIME, ' hh34:mi') date_time, stat_name, round((e_value - nvl(b_value, 0)) / (extract(day from(end_interval_time - begin_interval_time)) * 24 * 60 * 60 + extract(hour from(end_interval_time - begin_interval_time)) * 60 * 60 + extract(minute from(end_interval_time - begin_interval_time)) * 60 + extract(second from(end_interval_time - begin_interval_time))), 0) per_sec from sysstat where (e_value - nvl(b_value, 0)) > 0 and nvl(b_value, 0) > 0; ##############################表空間與文件和用戶對(duì)應(yīng)關(guān)聯(lián), set line 200 col name for a60 select t.name,f.name from v$datafile f,v$tablespace t where t.ts#=f.ts# order by 1; select t.name,count(f.name) from v$datafile f,v$tablespace t where t.ts#=f.ts# group by t.name order by 1; select username,default_tablespace from dba_users where account_status='OPEN'; ##############################表空間使用率 COLUMN ts_name format a35 heading "Tablespace" COLUMN unalloc_size format 999,999 heading "Unalloc(MB)" COLUMN used_size format 999,999,999 heading "Used(MB)" COLUMN free_size format 999,999 heading "Free(MB)" COLUMN capacity format 99,99 heading "Used_pct(%)" SELECT a.tablespace_name ts_name ,a.unalloc_size ,nvl(f.free_size, 0) free_size ,a.used_size - nvl(f.free_size, 0) used_size ,round((a.used_size - nvl(f.free_size, 0)) / (a.unalloc_size + a.used_size) ,2)*100 capacity FROM (SELECT tablespace_name ,round(SUM(bytes) / 1024 / 1024) free_size ,round(AVG(bytes)/1024/1024) avg_size FROM dba_free_space GROUP BY tablespace_name) f ,(SELECT tablespace_name ,round(SUM(user_bytes) / 1024 / 1024) used_size ,round(SUM(decode(autoextensible ,'YES' ,decode(sign(maxbytes - user_bytes) ,-1 ,0 ,maxbytes - user_bytes) ,0)) / 1024 / 1024) unalloc_size FROM dba_data_files WHERE status='AVAILABLE' GROUP BY tablespace_name) a WHERE 1 = 1 AND a.tablespace_name = f.tablespace_name(+) ORDER BY capacity DESC; ###############################################asm sqlplus / as sysasm select * from v$asm_operation; <==> $asmcmd lsop asmcmd rebal --power N <diskgroup> -- 修改磁盤組reblance的并行度 asmcmd lsdg ################################################# ——————————————————————————————————我是分割線 更新時(shí)間 2019年1月24日 ———————————————————— ###########################轉(zhuǎn)載于網(wǎng)絡(luò)######################查看sga,pga等使用率 set line 100 select name,total,round(total-free,2) used, round(free,2) free,round((total-free)/total*100,2) pctused from (select 'SGA' name,(select sum(value/1024/1024) from v$sga) total, (select sum(bytes/1024/1024) from v$sgastat where name='free memory')free from dual) union select name,total,round(used,2)used,round(total-used,2)free,round(used/total*100,2)pctused from ( select 'PGA' name,(select value/1024/1024 total from v$pgastat where name='aggregate PGA target parameter')total, (select value/1024/1024 used from v$pgastat where name='total PGA allocated')used from dual) union select name,round(total,2) total,round((total-free),2) used,round(free,2) free,round((total-free)/total*100,2) pctused from ( select 'Shared pool' name,(select sum(bytes/1024/1024) from v$sgastat where pool='shared pool')total, (select bytes/1024/1024 from v$sgastat where name='free memory' and pool='shared pool') free from dual) union select name,round(total,2)total,round(total-free,2) used,round(free,2) free,round((total-free)/total,2) pctused from ( select 'Default pool' name,( select a.cnum_repl*(select value from v$parameter where name='db_block_size')/1024/1024 total from x$kcbwds a, v$buffer_pool p where a.set_id=p.LO_SETID and p.name='DEFAULT' and p.block_size=(select value from v$parameter where name='db_block_size')) total, (select a.anum_repl*(select value from v$parameter where name='db_block_size')/1024/1024 free from x$kcbwds a, v$buffer_pool p where a.set_id=p.LO_SETID and p.name='DEFAULT' and p.block_size=(select value from v$parameter where name='db_block_size')) free from dual) union select name,nvl(round(total,2),0)total,nvl(round(total-free,2),0) used,nvl(round(free,2),0) free,nvl(round((total-free)/total,2),0) pctused from ( select 'KEEP pool' name,(select a.cnum_repl*(select value from v$parameter where name='db_block_size')/1024/1024 total from x$kcbwds a, v$buffer_pool p where a.set_id=p.LO_SETID and p.name='KEEP' and p.block_size=(select value from v$parameter where name='db_block_size')) total, (select a.anum_repl*(select value from v$parameter where name='db_block_size')/1024/1024 free from x$kcbwds a, v$buffer_pool p where a.set_id=p.LO_SETID and p.name='KEEP' and p.block_size=(select value from v$parameter where name='db_block_size')) free from dual) union select name,nvl(round(total,2),0)total,nvl(round(total-free,2),0) used,nvl(round(free,2),0) free,nvl(round((total-free)/total,2),0) pctused from ( select 'RECYCLE pool' name,( select a.cnum_repl*(select value from v$parameter where name='db_block_size')/1024/1024 total from x$kcbwds a, v$buffer_pool p where a.set_id=p.LO_SETID and p.name='RECYCLE' and p.block_size=(select value from v$parameter where name='db_block_size')) total, (select a.anum_repl*(select value from v$parameter where name='db_block_size')/1024/1024 free from x$kcbwds a, v$buffer_pool p where a.set_id=p.LO_SETID and p.name='RECYCLE' and p.block_size=(select value from v$parameter where name='db_block_size')) free from dual) union select name,nvl(round(total,2),0)total,nvl(round(total-free,2),0) used,nvl(round(free,2),0) free,nvl(round((total-free)/total,2),0) pctused from( select 'DEFAULT 16K buffer cache' name,(select a.cnum_repl*16/1024 total from x$kcbwds a, v$buffer_pool p where a.set_id=p.LO_SETID and p.name='DEFAULT' and p.block_size=16384) total, (select a.anum_repl*16/1024 free from x$kcbwds a, v$buffer_pool p where a.set_id=p.LO_SETID and p.name='DEFAULT' and p.block_size=16384) free from dual) union select name,nvl(round(total,2),0)total,nvl(round(total-free,2),0) used,nvl(round(free,2),0) free,nvl(round((total-free)/total,2),0) pctused from( select 'DEFAULT 32K buffer cache' name,(select a.cnum_repl*32/1024 total from x$kcbwds a, v$buffer_pool p where a.set_id=p.LO_SETID and p.name='DEFAULT' and p.block_size=32768) total, (select a.anum_repl*32/1024 free from x$kcbwds a, v$buffer_pool p where a.set_id=p.LO_SETID and p.name='DEFAULT' and p.block_size=32768) free from dual) union select name,total,total-free used,free, (total-free)/total*100 pctused from ( select 'Java Pool' name,(select sum(bytes/1024/1024) total from v$sgastat where pool='java pool' group by pool)total, ( select bytes/1024/1024 free from v$sgastat where pool='java pool' and name='free memory')free from dual) union select name,Round(total,2),round(total-free,2) used,round(free,2) free, round((total-free)/total*100,2) pctused from ( select 'Large Pool' name,(select sum(bytes/1024/1024) total from v$sgastat where pool='large pool' group by pool)total, ( select bytes/1024/1024 free from v$sgastat where pool='large pool' and name='free memory')free from dual) order by pctused desc; / set line 100 select name,total,round(total-free,2) used, round(free,2) free,round((total-free)/total*100,2) pctused from (select 'SGA' name,(select sum(value/1024/1024) from v$sga) total, (select sum(bytes/1024/1024) from v$sgastat where name='free memory')free from dual) union select name,total,round(used,2)used,round(total-used,2)free,round(used/total*100,2)pctused from ( select 'PGA' name,(select value/1024/1024 total from v$pgastat where name='aggregate PGA target parameter')total, (select value/1024/1024 used from v$pgastat where name='total PGA allocated')used from dual); #################################################鎖相關(guān) ####------------------------------------ v$transaction XIDUSN 表示當(dāng)前事務(wù)使用的回滾段的編號(hào) XIDSLOT 表示該事物在回滾段頭部的事務(wù)表中對(duì)應(yīng)的記錄編號(hào) XIDSQN 說明序列號(hào) STATUS 說明該事物是否為活動(dòng)的 select XIDUSN,XIDSLOT,XIDSQN,STATUS from v$transaction; ####------------------------------------------- v$lock 記錄session已經(jīng)獲得的鎖定以及正在請(qǐng)求的鎖定的信息 SID 說明session的id TYPE 鎖定級(jí)別,主要關(guān)注TX和TM LMODE 已經(jīng)獲得的鎖定的模式,以數(shù)字編碼表示 0 - none 1 - null (NULL) 2 - row-S (SS) 3 - row-X (SX) 4 - share (S) 5 - S/Row-X (SSX) 6 - exclusive (X) REQUEST 正在請(qǐng)求的鎖定的模式,以數(shù)字編碼表示 0 - none 1 - null (NULL) 2 - row-S (SS) 3 - row-X (SX) 4 - share (S) 5 - S/Row-X (SSX) 6 - exclusive (X) BLOCK 是否阻止了其他用戶獲得鎖定,大于0說明是,等于0說明否 set line 100 select sid,type,id1,id2, decode(LMODE,0,'None',1,'Null',2,'row share',3,'row exclusive',4,'share',5,'share row exclusive',6,'exclusive') lock_mode , decode(REQUEST,0,'None',1,'Null',2,'row share',3,'row exclusive',4,'share',5,'share row exclusive',6,'exclusive') request_mode, block from v$lock where sid=&sid; 注: type為鎖類型 對(duì)TM而言id1為表對(duì)象,id2始終為0 對(duì)TX將ID1.ID2分別對(duì)應(yīng)哪個(gè)事務(wù), lock_mode 持有鎖 request_mode請(qǐng)求鎖 block 被這個(gè)鎖鎖住的 TX: 行級(jí)鎖,就一種模式,排他鎖 TM: 表級(jí)鎖,行級(jí)排他鎖 ID1的拆解 select trunc(&ID1/power(2,16)) as undo_blk#, bitand(&ID1,to_number('ffff','xxxx')) + 0 as slot# from dual; ###------------- v$enqueue_lock--把正在請(qǐng)求的鎖列出來 其中的記錄按照申請(qǐng)鎖定的時(shí)間先后順序排列,先申請(qǐng)鎖定 的session排在前面,排在前面的session將會(huì)先獲得鎖定 ###------------- v$lock_object 記錄了當(dāng)前已經(jīng)被鎖定的對(duì)象的信息 ####-------------- 在數(shù)據(jù)庫系統(tǒng)中我們同時(shí)可以獲得的TX鎖定的總個(gè)數(shù)由初始化參數(shù)transaction決定, 而可以獲得TM鎖定的個(gè)數(shù)由初始化參數(shù)dml_locks決定 ####-------------- dba_ddl_locks; ######################數(shù)據(jù)泵數(shù)據(jù)遷移,前后對(duì)象類型比對(duì) select owner,object_type,count(*) from dba_objects where owner in ('&username') group by owner,object_type order by 1; --csv-- select owner||','||object_type||','||count(*) from dba_objects where owner in ('&username') group by owner,object_type order by 1; 方便粘貼到excel表格中
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。