문서의 선택한 두 판 사이의 차이를 보여줍니다.
양쪽 이전 판 이전 판 다음 판 | 이전 판 | ||
dbms:oracle:admin:managequery [2008/11/03 11:11] starlits |
— (현재) | ||
---|---|---|---|
줄 1: | 줄 1: | ||
- | ====== 오라클 데이타베이스 관리를 위한 쿼리 모음 ====== | ||
- | |||
- | ===== 테이블스페이스 ===== | ||
- | |||
- | - 테이블스페이스 사용량 확인 <code sql> | ||
- | SELECT a.tablespace_name , | ||
- | | ||
- | | ||
- | NVL( b.free , 0 ) " | ||
- | | ||
- | FROM ( | ||
- | SELECT tablespace_name , | ||
- | | ||
- | FROM | ||
- | GROUP BY tablespace_name | ||
- | ) a , | ||
- | ( | ||
- | SELECT tablespace_name , | ||
- | | ||
- | FROM | ||
- | GROUP BY tablespace_name | ||
- | ) b | ||
- | WHERE a.tablespace_name = b.tablespace_name( + ) | ||
- | ORDER BY a.tablespace_name ; | ||
- | </ | ||
- | |||
- | |||
- | ===== 귀차니즘 ===== | ||
- | <code sql> | ||
- | -- Index ***** | ||
- | -- 10분이내에 수행된 쿼리중 세션에 남아있는 쿼리 | ||
- | -- Buffer Cache Hit Ratio | ||
- | -- Library Cache Hit Ratio | ||
- | -- Data Dictionary Cache Hit Ratio | ||
- | -- 테이블 스페이스 사용량 | ||
- | -- 오라클서버의 메모리 | ||
- | -- cpu를 많이 사용하는 쿼리문과 프로세스아이디, | ||
- | -- 프로세스 아이디를 이용하여 쿼리문 알아내기 | ||
- | -- 세션 죽이기(SID, | ||
- | -- 오라클 세션과 관련된 테이블*/ | ||
- | -- 현재 커서 수 확인 | ||
- | -- V$LOCK 을 사용한 잠금 경합 모니터링 | ||
- | -- 락이 걸린 세션 자세히 알아보기 | ||
- | -- 락이 걸린 세션 간단히 알아보기 | ||
- | -- 락이 걸린 세션을 찾아 내어 세션을 죽이려고 해도 죽지 않는 경우 | ||
- | -- alter session으로 죽지않는 프로세스 죽이기 | ||
- | |||
- | ======================================================================== | ||
- | </ | ||
- | |||
- | - 10분이내에 수행된 쿼리중 세션에 남아있는 쿼리 <code sql> | ||
- | select sql_text | ||
- | from v$sqltext a, v$session b | ||
- | where a.hash_value = b.sql_hash_value | ||
- | and logon_time <= to_date(to_char(sysdate,' | ||
- | </ | ||
- | - Buffer Cache Hit Ratio <code sql> | ||
- | SELECT ROUND(((1-(SUM(DECODE(name, | ||
- | (SUM(DECODE(name, | ||
- | (SUM(DECODE(name, | ||
- | FROM V$SYSSTAT; | ||
- | </ | ||
- | - Library Cache Hit Ratio <code sql> | ||
- | SELECT (1-SUM (reloads)/ | ||
- | From V$LIBRARYCACHE; | ||
- | </ | ||
- | - Data Dictionary Cache Hit Ratio <code sql> | ||
- | SELECT (1-SUM(getmisses)/ | ||
- | FROM V$ROWCACHE; | ||
- | </ | ||
- | - 테이블 스페이스 사용량 <code sql> | ||
- | SELECT a.tablespace_name, | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | from ( | ||
- | round((sum(bytes)/ | ||
- | | ||
- | group by tablespace_name) a, | ||
- | | ||
- | | ||
- | | ||
- | group by tablespace_name) b | ||
- | where a.tablespace_name = b.tablespace_name(+) | ||
- | order by | ||
- | </ | ||
- | - 오라클서버의 메모리 <code sql> | ||
- | select * from v$sgastat | ||
- | |||
- | select pool, sum(bytes) " | ||
- | from v$sgastat | ||
- | where pool = ' | ||
- | group by pool | ||
- | </ | ||
- | - cpu를 많이 사용하는 쿼리문과 프로세스아이디, | ||
- | select c.sql_text | ||
- | ,b.SID | ||
- | , b.SERIAL# | ||
- | ,b.machine | ||
- | ,b.OSUSER | ||
- | , | ||
- | from v$process a, v$session b, v$sqltext c | ||
- | where a.addr = b.paddr | ||
- | and b.sql_hash_value = c.hash_value | ||
- | --and a.spid = ' | ||
- | order by c.PIECE | ||
- | </ | ||
- | - cpu를 많이 사용하는 쿼리문과 프로세스아이디, | ||
- | select c.sql_text | ||
- | from v$process a, v$session b, v$sqltext c | ||
- | where a.addr = b.paddr | ||
- | and b.sql_hash_value = c.hash_value | ||
- | and a.spid = ' | ||
- | order by c.PIECE | ||
- | </ | ||
- | - 프로세스 아이디를 이용하여 쿼리문 알아내기 <code sql> | ||
- | select c.sql_text | ||
- | ,b.SID | ||
- | , b.SERIAL# | ||
- | ,b.machine | ||
- | ,b.OSUSER | ||
- | , | ||
- | from v$process a, v$session b, v$sqltext c | ||
- | where a.addr = b.paddr | ||
- | and b.sql_hash_value = c.hash_value | ||
- | and a.spid = ' | ||
- | order by c.PIECE | ||
- | </ | ||
- | |||
- | |||
- | |||
- | |||
- | -- 세션 죽이기(SID, | ||
- | |||
- | --ALTER SYSTEM KILL SESSION ' | ||
- | |||
- | |||
- | |||
- | -- 오라클 세션과 관련된 테이블*/ | ||
- | |||
- | --select count(*) from v$session where machine =' | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | -- 현재 커서 수 확인 | ||
- | |||
- | SELECT sid, count(sid) cursor | ||
- | |||
- | FROM V$OPEN_CURSOR | ||
- | |||
- | WHERE user_name = ' | ||
- | |||
- | GROUP BY sid | ||
- | |||
- | ORDER BY cursor DESC | ||
- | |||
- | |||
- | |||
- | SELECT sql_text, count(sid) cnt | ||
- | |||
- | FROM v$OPEN_CURSOR | ||
- | |||
- | GROUP BY sql_text | ||
- | |||
- | ORDER BY cnt DESC | ||
- | |||
- | |||
- | |||
- | select * from v$session_wait | ||
- | |||
- | |||
- | |||
- | select sid, serial#, username, taddr, used_ublk, used_urec | ||
- | |||
- | from v$transaction t, v$session s | ||
- | |||
- | where t.addr = s.taddr; | ||
- | |||
- | |||
- | |||
- | select * from sys.v_$open_cursor | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | -- V$LOCK 을 사용한 잠금 경합 모니터링 | ||
- | |||
- | SELECT s.username, s.sid, s.serial#, s.logon_time, | ||
- | |||
- | DECODE(l.type, | ||
- | |||
- | ' | ||
- | |||
- | NULL) "LOCK LEVEL", | ||
- | |||
- | o.owner, o.object_name, | ||
- | |||
- | FROM v$session s, v$lock l, dba_objects o | ||
- | |||
- | WHERE s.sid = l.sid | ||
- | |||
- | AND o.object_id = l.id1 | ||
- | |||
- | AND s.username IS NOT NULL | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | -- 락이 걸린 세션 자세히 알아보기 | ||
- | |||
- | select a.sid, a.serial#, | ||
- | |||
- | decode(c.lmode, | ||
- | |||
- | decode (a.command, | ||
- | |||
- | decode(a.lockwait, | ||
- | |||
- | from v$session a, | ||
- | |||
- | where a.sid=c.sid and b.object_id=c.id1 | ||
- | |||
- | and c.type=' | ||
- | |||
- | |||
- | |||
- | |||
- | -- 락이 걸린 세션 간단히 알아보기 | ||
- | |||
- | select a.sid, a.serial#, b.type, c.object_name, | ||
- | |||
- | | ||
- | |||
- | from v$session a, v$lock b, dba_objects c | ||
- | |||
- | where a.sid = b.sid | ||
- | |||
- | and b.id1 = c.object_id | ||
- | |||
- | and b.type = ' | ||
- | |||
- | select a.sid, a.serial#, a.username, a.process, b.object_name | ||
- | |||
- | from v$session a , dba_objects b, v$lock c | ||
- | |||
- | where a.sid=c.sid and b.object_id = c.id1 | ||
- | |||
- | and c.type = ' | ||
- | |||
- | |||
- | |||
- | |||
- | -- 락이 걸린 세션을 찾아 내어 세션을 죽이려고 해도 죽지 않는 경우 | ||
- | |||
- | --아래 쿼리문으로 OS단의 PROCESS ID를 찾아내어 OS에서 죽인다 | ||
- | |||
- | --kill -9 프로세스아이디 | ||
- | |||
- | select substr(s.username, | ||
- | |||
- | s.sid " | ||
- | |||
- | p.spid "PROC SPID", | ||
- | |||
- | from v$process p, v$session s, v$access a | ||
- | |||
- | where a.sid=s.sid and | ||
- | |||
- | p.addr=s.paddr and | ||
- | |||
- | s.username != ' | ||
- | |||
- | --위 쿼리문의 결과가 있다면 락이 걸린 세션이 있다는것이므로 아래의 쿼리문으로 세션을 죽인다 | ||
- | |||
- | ALTER SYSTEM KILL SESSION ' | ||
- | </ | ||
- | |||