Oracle基本檢視總結

kuqlan發表於2012-06-19

當我們基本熟悉了Oracle體系架構後,可能需要將這些資訊從資料庫字典中查出來看以便診斷和分析。如下是根據Oracle 的體系架構整理出來基本檢視分類列表:

一、資料庫和例項資訊

select * from gV$INSTANCE

select * from V$DATABASE

select * from V$version

select * from V$option

--select s.NAME,s.BYTES/1024/1024 bytesM, s.RESIZEABLE from v$sgainfo s

select * from v$sgainfo

[@more@]

二、物理結構相關的資訊

select * from v$parameter p where p.ISDEFAULT='FALSE'

select * from v$SPPARAMETER sp where sp.ORDINAL=1

select * from v$pwfile_users

select * from V$CONTROLFILE

select * from V$CONTROLFILE_RECORD_SECTION

select * from V$DATAFILE

select * from V$TABLESPACE

select * from DBA_DATA_FILES

select * from DBA_TABLESPACES

select * from v$log

select * from v$logfile

select * from V$THREAD

select * from DBA_ROLLBACK_SEGS

select * from DBA_UNDO_EXTENTS

select * from V$ROLLNAME

select * from V$ROLLSTAT

select * from V$UNDOSTAT

select * from V$TRANSACTION

select * from DBA_HIST_UNDOSTAT

select * from DBA_TEMP_FILES

select * from v$sort_segment

select * from V$TEMPFILE

select * from v$sort_usage

select * from v$tempseg_usage;

三、儲存相關資訊

DBA_EXTENTS

DBA_SEGMENTS

DBA_TABLESPACES

DBA_DATA_FILES

DBA_FREE_SPACE

四、資料庫段和物件資訊:

select * from DBA_OBJECTS

select * from DBA_TABLES

select * from DBA_INDEXES

select * from DBA_IND_COLUMNS

select * from V$OBJECT_USAGE

五、程式、回話、SQL等資訊:

select * from V$process

select * from V$session

select * from V$sql

select * from V$NLS_PARAMETERS

六、使用者和資源限定資訊

DBA_USERS

DBA_PROFILES

DBA_USERS

DBA_TS_QUOTAS

七、綜合應用案例:

1表空使用情況

select substr(a.TABLESPACE_NAME,1,30) TablespaceName,

sum(a.bytes/1024/1024) as "Totle_size(M)",

sum(nvl(b.free_space1/1024/1024,0)) as "Free_space(M)",

sum(a.bytes/1024/1024)-sum(nvl(b.free_space1/1024/1024,0)) as "Used_space(M)",

round((sum(a.bytes/1024/1024)-sum(nvl(b.free_space1/1024/1024,0)))

*100/sum(a.bytes/1024/1024),2) as "Used_percent%" from dba_data_files a,

(select sum(nvl(bytes,0)) free_space1,file_id from dba_free_space

group by file_id) b where a.file_id = b.file_id(+) group by a.TABLESPACE_NAME

order by "Used_percent%";

2、鎖表情況查詢:

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.owner,o.object_id,o.object_name object,o.subobject_name, 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# seria ,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

--alter system kill session 'sid,serial';

3、作業系統的PID至資料庫的Session的關聯

SELECT s.SID, p.pid, p.spid signaled, s.osuser, s.program

FROM v$process p, v$session s

WHERE p.addr = s.paddr;

--還可以透過和 v$bgprocess 連線查詢到後臺程式的名字:

SELECT s.SID SID, p.spid threadid, p.program processname, bg.NAME NAME

FROM v$process p, v$session s, v$bgprocess bg

WHERE p.addr = s.paddr

AND p.addr = bg.paddr

AND bg.paddr <> '00';

4、根據作業系統PID定位SQL文字:

SELECT /*+ ORDERED */

sql_text

FROM v$sqltext a

WHERE (a.hash_value, a.address) IN (

SELECT DECODE (sql_hash_value,

0, prev_hash_value,

sql_hash_value

),

DECODE (sql_hash_value, 0, prev_sql_addr, sql_address)

FROM v$session b

WHERE b.paddr = (SELECT addr

FROM v$process c

WHERE c.spid = TO_NUMBER ('&pid', 'xxxx')))

ORDER BY piece ASC

5、查詢執行是將較長(比例為100毫秒)SQLSession

select s.SID,s.SERIAL#,w.EVENT,s.PADDR,s.USERNAME,w.SECONDS_IN_WAIT,sql.SQL_TEXT,sql.SQL_FULLTEXT,

s.OSUSER,s.MACHINE,s.PROCESS,s.WAIT_CLASS,s.WAIT_TIME,s.STATE,s.ROW_WAIT_OBJ#,s.ROW_WAIT_ROW#,s.LAST_CALL_ET

,s.ROW_WAIT_BLOCK#,s.BLOCKING_SESSION

from v$session_wait w ,v$session s,v$sql sql

where w.SID=s.SID and s.SQL_ID=sql.SQL_ID

and w.EVENT not in ('SQL*Net message from client')

and s.LAST_CALL_ET >100; --100毫秒以上的等待

6、檢視臨時表空間使用情況

select SEGBLK#*8192/1024/1024/1024 from v$sort_usage

select USERNAME,SQLHASH,SEGTYPE,SEGFILE#,SEGBLK# as size_GB from v$sort_usage

select * from v$session where prev_hash_value in(select sqlhash from v$sort_usage)

7UNDO表空間及回滾段資訊的查詢

select file_name,bytes/1024/1024/1024 from dba_data_files

where tablespace_name like 'UNDOTBS1'

select usn,xacts,rssize/1024/1024/1024,hwmsize/1024/1024/1024,shrinks

from v$rollstat order by rssize;

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/18841027/viewspace-1058594/,如需轉載,請註明出處,否則將追究法律責任。

相關文章