ORACLE關於鎖表查詢的部分SQL

--查詢表空間名稱和大小數據庫

 

  SELECT UPPER (F.TABLESPACE_NAME) "表空間名",session

         D.TOT_GROOTTE_MB "表空間大小(M)",併發

         D.TOT_GROOTTE_MB - F.TOTAL_BYTES "已使用空間(M)",spa

         TO_CHAR (ROUND ((D.TOT_GROOTTE_MB - F.TOTAL_BYTES) / D.TOT_GROOTTE_MB * 100, 2), '990.99') "使用比",orm

         F.TOTAL_BYTES "空閒空間(M)",進程

         F.MAX_BYTES "最大塊(M)"it

    FROM (  SELECT TABLESPACE_NAME,io

                   ROUND (SUM (BYTES) / (1024 * 1024), 2) TOTAL_BYTES,table

                   ROUND (MAX (BYTES) / (1024 * 1024), 2) MAX_BYTES後臺

              FROM SYS.DBA_FREE_SPACE

          GROUP BY TABLESPACE_NAME) F,

         (  SELECT DD.TABLESPACE_NAME,

                   ROUND (SUM (DD.BYTES) / (1024 * 1024), 2) TOT_GROOTTE_MB

              FROM SYS.DBA_DATA_FILES DD

          GROUP BY DD.TABLESPACE_NAME) D

   WHERE D.TABLESPACE_NAME = F.TABLESPACE_NAME

ORDER BY 4 DESC;

 

 

 

 

--查看數據庫引發鎖表的SQL語句:

 

  SELECT A.USERNAME,

         A.MACHINE,

         A.PROGRAM,

         A.SID,

         A.SERIAL#,

         A.STATUS,

         C.PIECE,

         C.SQL_TEXT

    FROM V$SESSION A,

         V$SQLTEXT C

   WHERE     A.SID IN (SELECT DISTINCT T2.SID

                         FROM V$LOCKED_OBJECT T1,

                              V$SESSION T2

                        WHERE T1.SESSION_ID = T2.SID)

         AND A.SQL_ADDRESS = C.ADDRESS(+)

ORDER BY C.PIECE;

 

 

--查看數據庫鎖的狀況必需要有DBA權限,能夠使用一下SQL 語句:

 

 

SELECT object_id, session_id, locked_mode FROM v$locked_object;

 

  SELECT t2.username,

         t2.sid,

         t2.serial#,

         t2.logon_time

    FROM v$locked_object t1, v$session t2

   WHERE t1.session_id = t2.sid

ORDER BY t2.logon_time;

 

 

--查看被鎖的表

 

SELECT P.SPID,

       A.SERIAL#,

       C.OBJECT_NAME,

       B.SESSION_ID,

       B.ORACLE_USERNAME,

       B.OS_USER_NAME

  FROM V$PROCESS P,

       V$SESSION A,

       V$LOCKED_OBJECT B,

       ALL_OBJECTS C

 WHERE     P.ADDR = A.PADDR

       AND A.PROCESS = B.PROCESS

       AND C.OBJECT_ID = B.OBJECT_ID;

      

      

      

--殺掉進程

ALTER SYSTEM KILL SESSION 'sid,serial#';

 

--查看鏈接數

SELECT COUNT (*) FROM v$session;

 

--查看併發鏈接數

SELECT COUNT(*) FROM V$SESSION WHERE STATUS='ACTIVE';

 

--查看鏈接的進程

SELECT SID, SERIAL#, USERNAME, OSUSER FROM V$SESSION;

 

--查看數據庫使用的裸設備

  SELECT *

    FROM dba_data_files

ORDER BY file_name;

 

  SELECT *

    FROM dba_temp_files

ORDER BY file_name;

 

  SELECT *

    FROM v$controlfile

ORDER BY file_name;

 

  SELECT *

    FROM v$logfile;

 

--具體的方法是查詢dba_data_filesdba_temp_filesv$controlfilev$logfile看這四類文件具體佔用的裸設備

 

--查詢全部用戶表使用大小的前三十名

select * from (select segment_name,bytes from dba_segments where owner = USER order by bytes desc ) where rownum <= 30;

 

--如下的SQL語句列出當前數據庫創建的會話狀況:

select sid,serial#,username,program,machine,status from v$session;

 

--若是DBA要手工斷開某個會話,則執行:

alter system kill session 'SID,SERIAL#';

--注意,上例中SID17(USERNAME列爲空)的會話,是Oracle的後臺進程,不要對這些會話進行任何操做。

 

--查詢表空間有那些表:

select table_name from all_tables where tablespace_name= 'TEMP';

相關文章
相關標籤/搜索