Oracle數(shù)據(jù)庫維護常用SQL語句_百度文庫_第1頁
Oracle數(shù)據(jù)庫維護常用SQL語句_百度文庫_第2頁
Oracle數(shù)據(jù)庫維護常用SQL語句_百度文庫_第3頁
Oracle數(shù)據(jù)庫維護常用SQL語句_百度文庫_第4頁
Oracle數(shù)據(jù)庫維護常用SQL語句_百度文庫_第5頁
已閱讀5頁,還剩9頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、Oracle維護常用SQL語句(查詢系統(tǒng)表和視圖提要:1、查看表空間的名稱及大小2、查看表空間物理文件的名稱及大小3、查看回滾段名稱及大小4、查看控制文件5、查看日志文件6、查看表空間的使用情況7、查看數(shù)據(jù)庫庫對象8、查看數(shù)據(jù)庫的版本9、查看數(shù)據(jù)庫的創(chuàng)建日期和歸檔方式10、捕捉運行很久的SQL11。查看數(shù)據(jù)表的參數(shù)信息12.查看還沒提交的事務(wù)13。查找object為哪些進程所用14?;貪L段查看15。耗資源的進程(top session16。查看鎖(lock情況17。查看等待(wait情況18。查看sga情況19。查看catched object20。查看V$SQLAREA21。查看object

2、分類數(shù)量22。按用戶查看object種類23。有關(guān)connection的相關(guān)信息1查看有哪些用戶連接2根據(jù)v.sid查看對應(yīng)連接的資源占用等情況3根據(jù)sid查看對應(yīng)連接正在運行的sql24.查詢表空間使用情況25.查詢表空間的碎片程度26.查詢正在運行的數(shù)據(jù)庫實例1、查看表空間的名稱及大小select t.tablespace_name, round(sum(bytes/(1024*1024,0 ts_size from dba_tablespaces t, dba_data_files dwhere t.tablespace_name = d.tablespace_namegroup by

3、t.tablespace_name;2、查看表空間物理文件的名稱及大小select tablespace_name, file_id, file_name,round(bytes/(1024*1024,0 total_spacefrom dba_data_filesorder by tablespace_name;3、查看回滾段名稱及大小select segment_name, tablespace_name, r.status,(initial_extent/1024 InitialExtent,(next_extent/1024 NextExtent, max_extents, v.cur

4、ext CurExtentFrom dba_rollback_segs r, v$rollstat vWhere r.segment_id = v.usn(+order by segment_name ;4、查看控制文件select name from v$controlfile;5、查看日志文件select member from v$logfile;6、查看表空間的使用情況select sum(bytes/(1024*1024 as free_space,tablespace_namefrom dba_free_spacegroup by tablespace_name;SELECT A.

5、TABLESPACE_NAME,A.BYTES TOTAL,B.BYTES USED, C.BYTES FREE,(B.BYTES*100/A.BYTES "% USED",(C.BYTES*100/A.BYTES "% FREE"FROM SYS.SM$TS_AVAIL A,SYS.SM$TS_USED B,SYS.SM$TS_FREE CWHERE A.TABLESPACE_NAME=B.TABLESPACE_NAME AND A.TABLESPACE_NAME=C.TABLESPACE_NAME;7、查看數(shù)據(jù)庫庫對象select owner, ob

6、ject_type, status, count(* count# from all_objects group by owner, object_type, status;8、查看數(shù)據(jù)庫的版本Select version FROM Product_component_version Where SUBSTR(PRODUCT,1,6='Oracle'9、查看數(shù)據(jù)庫的創(chuàng)建日期和歸檔方式Select Created, Log_Mode, Log_Mode From V$Database;10、捕捉運行很久的SQLcolumn username format a12column op

7、name format a16column progress format a8select username,sid,opname,round(sofar*100 / totalwork,0 | '%' as progress,time_remaining,sql_textfrom v$session_longops , v$sqlwhere time_remaining <> 0and sql_address = addressand sql_hash_value = hash_value/11。查看數(shù)據(jù)表的參數(shù)信息SELECT partition_name,

8、high_value, high_value_length, tablespace_name, pct_free, pct_used, ini_trans, max_trans, initial_extent,next_extent, min_extent, max_extent, pct_increase, FREELISTS,freelist_groups, LOGGING, BUFFER_POOL, num_rows, blocks,empty_blocks, avg_space, chain_cnt, avg_row_len, sample_size,last_analyzedFROM

9、 dba_tab_partitions-WHERE table_name = :tname AND table_owner = :townerORDER BY partition_position12.查看還沒提交的事務(wù)select * from v$locked_object;select * from v$transaction;13。查找object為哪些進程所用selectp.spid,s.sid,s.serial# serial_num,s.username user_name,a.type object_type,s.osuser os_user_name,a.owner,a.ob

10、ject object_name,decode(sign(48 - command,1,to_char(command, 'Action Code #' | to_char(command action,gram oracle_process,s.terminal terminal,gram program,s.status session_statusfrom v$session s, v$access a, v$process pwhere s.paddr = p.addr ands.type = 'USER' anda.sid = s.

11、sid anda.object='SUBSCRIBER_ATTR'order by s.username, s.osuser14?;貪L段查看Extents, v$rollstat.rssize Size_in_Bytes, v$rollstat.xacts XActs,v$rollstat.gets Gets, v$rollstat.waits Waits, v$rollstat.writes Writes,v$rollstat.usn (+ = v$rollname.usn order by rownum15。耗資源的進程(top sessionselect s.schema

12、name schema_name, decode(sign(48 - command, 1,to_char(command, 'Action Code #' | to_char(command action, statussession_status, s.osuser os_user_name, s.sid, p.spid , s.serial# serial_num,nvl(s.username, 'Oracle process' user_name, s.terminal terminal,gram program, st.value crite

13、ria_value from v$sesstat st, v$session s , v$process pwhere 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 asc16。查看鎖(lock情況select /*+ RULE */ ls.

14、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,

15、 'Row Share', 3,'Row Exclusive', 4, 'Share', 5, 'Share Row Exclusive', 6, 'Exclusive', nulllock_mode, o.owner, ls.sid, ls.serial# serial_num, ls.id1, ls.id2from sys.dba_objects o, ( select s.osuser, s.username, l.type,l.lmode, s.sid, s.serial#, l.id1, l.id2 fr

16、om 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_name17。查看等待(wait情況SELECT v$waitstat.class, v$waitstat.count count, SUM(v$sysstat.value sum_valueFROM v$waitstat, v$sysstat WHERE v$ IN ('db block get

17、s','consistent gets' group by v$waitstat.class, v$waitstat.count18。查看sga情況SELECT NAME, BYTES FROM SYS.V_$SGASTAT ORDER BY NAME ASC19。查看catched objectSELECT owner, name, db_link, namespace,type, sharable_mem, loads, executions,locks, pins, kept FROM v$db_object_cache20。查看V$SQLAREASELECT S

18、QL_TEXT, SHARABLE_MEM, PERSISTENT_MEM, RUNTIME_MEM, SORTS, VERSION_COUNT, LOADED_VERSIONS, OPEN_VERSIONS, USERS_OPENING, EXECUTIONS, USERS_EXECUTING, LOADS, FIRST_LOAD_TIME, INVALIDATIONS, PARSE_CALLS, DISK_READS, BUFFER_GETS, ROWS_PROCESSED FROM V$SQLAREA21。查看object分類數(shù)量select decode (o.type#,1,'

19、;INDEX' , 2,'TABLE' , 3 , 'CLUSTER' , 4, 'VIEW' , 5 ,'SYNONYM' , 6 , 'SEQUENCE' , 'OTHER' object_type , count(* quantity fromsys.obj$ o where o.type# > 1 group by decode (o.type#,1,'INDEX' , 2,'TABLE' , 3, 'CLUSTER' , 4,

20、'VIEW' , 5 , 'SYNONYM' , 6 , 'SEQUENCE' , 'OTHER' union select'COLUMN' , count(* from sys.col$ union select 'DB LINK' , count(* from22。按用戶查看object種類select schema, sum(decode(o.type#, 1, 1, NULL indexes,sum(decode(o.type#, 2, 1, NULL tables, sum(

21、decode(o.type#, 3, 1, NULLclusters, sum(decode(o.type#, 4, 1, NULL views, sum(decode(o.type#, 5, 1,NULL synonyms, sum(decode(o.type#, 6, 1, NULL sequences,sum(decode(o.type#, 1, NULL, 2, NULL, 3, NULL, 4, NULL, 5, NULL, 6, NULL, 1others from sys.obj$ o, sys.user$ u where o.type# >= 1 and u.user#

22、=o.owner# and <> 'PUBLIC' group by order bysys.link$ union select 'CONSTRAINT' , count(* from sys.con$23。有關(guān)connection的相關(guān)信息1查看有哪些用戶連接select s.osuser os_user_name, decode(sign(48 - command, 1, to_char(command,'Action Code #' | to_char(command action, gr

23、am oracle_process, status session_status, s.terminal terminal, gram program,s.username user_name, s.fixed_table_sequence activity_meter, '' query, 0 memory, 0 max_memory, 0 cpu_usage, s.sid, s.serial# serial_num from v$session s, v$process p where s.paddr=p.addr and s.type = 'USER&#

24、39; order by s.username, s.osuser2根據(jù)v.sid查看對應(yīng)連接的資源占用等情況select ,v.value,n.class,n.statistic#from v$statname n,v$sesstat vwhere v.sid = 71 andv.statistic# = n.statistic#order by n.class, n.statistic#3根據(jù)sid查看對應(yīng)連接正在運行的sqlselect /*+ PUSH_SUBQ */command_type,sql_text,sharable_mem,persistent_mem,runt

25、ime_mem,sorts,version_count,loaded_versions,open_versions,users_opening,executions,users_executing,loads,first_load_time,invalidations,parse_calls,disk_reads,buffer_gets,rows_processed,sysdate start_time,sysdate finish_time,'>' | address sql_address,'N' statusfrom v$sqlareawhere a

26、ddress = (select sql_address from v$session where sid = 7124.查詢表空間使用情況select a.tablespace_name "表空間名稱",100-round(nvl(b.bytes_free,0/a.bytes_alloc*100,2 "占用率(%", round(a.bytes_alloc/1024/1024,2 "容量(M",round(nvl(b.bytes_free,0/1024/1024,2 "空閑(M",round(a.bytes_al

27、loc-nvl(b.bytes_free,0/1024/1024,2 "使用(M", Largest "最大擴展段(M",to_char(sysdate,'yyyy-mm-dd hh24:mi:ss' "采樣時間"from (select f.tablespace_name,sum(f.bytes bytes_alloc,sum(decode(f.autoextensible,'YES',f.maxbytes,'NO',f.bytes maxbytes from dba_data_files fgroup by tablespace_name a,(select f.tablespace_name,sum(f.bytes bytes_freefrom dba_free_space fgroup by ta

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論