Oracle常用維護語句總結
--不斷更新中
1. 檢視錶空間使用情況:
SELECT a.tablespace_name "表空間名",total 表空間大小,free 表空間剩餘大小,
(total-free) 表空間使用大小,
ROUND((total-free)/total,4)*100 "使用率 %"
FROM (SELECT tablespace_name,SUM(bytes) free FROM DBA_FREE_SPACE
GROUP BY tablespace_name ) a,
(SELECT tablespace_name,SUM(bytes) total FROM DBA_DATA_FILES
GROUP BY tablespace_name) b
WHERE a.tablespace_name=b.tablespace_name
/
--根據自己需要,可以對使用率進行order by下
[@more@]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.object_name object, 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# 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
/
3. 耗資源的程式(top session)
select s.schemaname schema_name, decode(sign(48 - command), 1,
to_char(command), 'Action Code #' || to_char(command) ) action, status
session_status, s.osuser os_user_name, s.sid, p.spid , s.serial# serial_num,
nvl(s.username, '[Oracle process]') user_name, s.terminal terminal,
s.program program, st.value criteria_value from v$sesstat st, v$session s , v$process p
where st.sid = s.sid and st.statistic# = to_number('38') and ('ALL' = 'ALL'
or s.status = 'ALL') and p.addr = s.paddr order by st.value desc, p.spid asc, s.username asc, s.osuser asc
/
4. 捕捉執行很久的SQL
column username format a12
column opname format a16
column progress format a8
select username,sid,opname,
round(sofar*100 / totalwork,0) || '%' as progress,
time_remaining,sql_text
from v$session_longops , v$sql
where time_remaining <> 0
and sql_address = address
and sql_hash_value = hash_value;
5. 檢視資料庫版本
Select version FROM Product_component_version
Where SUBSTR(PRODUCT,1,6)='Oracle';
6. 檢視日誌檔案
select member from v$logfile;
7. 檢視回滾段名稱和大小
select segment_name, tablespace_name, r.status,
(initial_extent/1024) InitialExtent,(next_extent/1024) NextExtent,
max_extents, v.curext CurExtent
From dba_rollback_segs r, v$rollstat v
Where r.segment_id = v.usn(+)
order by segment_name ;
8. 檢視錶空間物理檔案的名稱及大小
select tablespace_name, file_id, file_name,
round(bytes/(1024*1024),0) total_space
from dba_data_files
order by tablespace_name;
9. 查詢產生鎖的SQL語句
set pagesize 60
set linesize 132
select s.username username,
a.sid sid,
a.owner||'.'||a.object object,
s.lockwait,
t.sql_text SQL
from v$sqltext t,
v$session s,
v$access a
where t.address = s.sql_address
and t.hash_value = s.sql_hash_value
and s.sid = a.sid
and a.owner != 'SYS'
and upper(substr(a.object,1,2)) != 'V$'
/
10. 檢查使用者是否將SYSTEM表空間作為預設表空間
select username,default_tablespace from dba_users where default_tablespace = 'SYSTEM';
11. 檢查使用者是否將SYSTEM表空間作為臨時表空間
select username,temporary_tablespace from dba_users where temporary_tablespace = 'SYSTEM';
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9896745/viewspace-926839/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- ORACLE常用語句:Oracle
- oracle常用維護查詢Oracle
- oracle資料庫常用語句Oracle資料庫
- 【LOB】Oracle lob管理常用語句Oracle
- 【PDB】Oracle pdb維護常用sql命令OracleSQL
- 【SCRIPT】Oracle表管理段管理常用語句Oracle
- Oracle行轉列、列轉行的Sql語句總結OracleSQL
- 賓語從句總結
- MySql常用操作SQL語句彙總MySql
- Oracle常用的系統查詢語句整理Oracle
- ORACLE結構化查詢語句Oracle
- SQL語句規範總結SQL
- sql語句學習總結SQL
- MySQL基本sql語句總結MySql
- MySQL -update語句流程總結MySql
- 資料庫常用的sql語句彙總資料庫SQL
- Mybatis 查詢語句結果集總結MyBatis
- sql常用語句SQL
- Matlab常用語句Matlab
- oracel常用語句
- mySql常用語句MySql
- 常用MSSQL語句SQL
- oracle常用後臺程序及sql語句執行流程OracleSQL
- SQL單表查詢語句總結SQL
- Mysql日期常用語句MySql
- 【MySQL】常用拼接語句MySql
- mysql的常用語句MySql
- MongoDB中常用語句MongoDB
- Oracle 建立序列語句Oracle
- Oracle基本SQL語句OracleSQL
- Oracle OGG日常維護Oracle
- ES6常用語法總結
- Emmet外掛常用語法總結
- 效能測試常用Oracle語句,這10個果斷收藏了!Oracle
- SQL Server 資料庫部分常用語句小結(二)SQLServer資料庫
- SQL Server 資料庫部分常用語句小結(一)SQLServer資料庫
- 常用sql進階語句SQL
- SQL 常用語句一覽SQL
- shell學習-常用語句