版權(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$SQL
2、AREA21。查看 object 分類數(shù)量22。按用戶查看 object 種類23。有關(guān) connection 的相關(guān)信息1 查看有哪些用戶連接2 根據(jù) v.sid 查看對應(yīng)連接的資源占用等情況3 根據(jù) sid 查看對應(yīng)連接正在運行的 sql 24.查詢表空間使用情況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_nam
3、e = d.tablespace_namegroup by 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
4、NextExtent, max_extents, v.curext 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_spacegrou
5、p by tablespace_name;SELECT A.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_N
6、AME;7、查看數(shù)據(jù)庫庫對象select owner, object_type, status, count(* count# from all_objects group by owner, object_type, status;8、查看數(shù)據(jù)庫的版本Select version FROM Product_component_version WhereSUBSTR(PRODUCT,1,6='Oracle'9、查看數(shù)據(jù)庫的創(chuàng)建日期和歸檔方式Select Created, Log_Mode, Log_Mode From V$Database;10、捕捉運行很久的SQLcolumn
7、 username format a12column opname 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ù)
8、表的參數(shù)信息SELECT partition_name, 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,
9、sample_size,last_analyzedFROM 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.o
10、suser os_user_name,a.owner,a.object 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
11、 = 'USER' anda.sid = s.sid anda.object='SUBSCRIBER_ATTR'order by s.username, s.osuser14。回滾段查看select rownum, sys.dba_rollback_segs.segment_name Name, v$rollstat.extentsExtents, v$rollstat.rssize Size_in_Bytes, v$rollstat.xacts XActs,v$rollstat.gets Gets, v$rollstat.waits Waits, v$roll
12、stat.writes Writes,sys.dba_rollback_segs.status status from v$rollstat, sys.dba_rollback_segs,v$rollname where v$(+ = sys.dba_rollback_segs.segment_name andv$rollstat.usn (+ = v$rollname.usn order by rownum15。耗資源的進程 (top sessionselect s.schemaname schema_name, decode(sign(48 - command,
13、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 criteria_value from v$sesstat st, v$session s , v
14、$processpwhere 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.osuser os_user_name, ls.username user_name,
15、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&
16、#39;, 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 from v$session s,v$lock l where s.sid = l.sid
17、 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 gets','consistent gets' group by
18、 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 SQL_TEXT, SHARABLE_MEM, PERSISTENT_MEM,
19、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,'INDEX' , 2,'TABLE' , 3 ,
20、39;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, 'VIEW' , 5 , 'SYNONYM' ,
21、 6 , 'SEQUENCE' , 'OTHER' unionselect'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(decode(o.type#, 3, 1, NULLclusters, sum
22、(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# =o.owner# and <> 'PUBLI
23、C' 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, gram oracle_process, status session_sta
24、tus, 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' order by s.username, s.osuser2 根據(jù)
25、 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,runtime_mem,sorts,version_count,loa
26、ded_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 address = (select sql_address fr
27、om 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_alloc-nvl(b.bytes_free,0/1024/
28、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_freefro
溫馨提示
- 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)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 綠色營銷 課件
- 西京學(xué)院《電工電子實訓(xùn)》2022-2023學(xué)年期末試卷
- 西華師范大學(xué)《中學(xué)歷史教學(xué)論》2022-2023學(xué)年第一學(xué)期期末試卷
- 西華師范大學(xué)《知識產(chǎn)權(quán)法學(xué)》2023-2024學(xué)年期末試卷
- 西華師范大學(xué)《藝術(shù)采風(fēng)》2023-2024學(xué)年第一學(xué)期期末試卷
- 2024-2025學(xué)年高中物理舉一反三系列專題2.1 溫度和溫標(含答案)
- 西華師范大學(xué)《平面設(shè)計基礎(chǔ)》2023-2024學(xué)年第一學(xué)期期末試卷
- 西華師范大學(xué)《個人理財實務(wù)》2021-2022學(xué)年第一學(xué)期期末試卷
- 西華師范大學(xué)《創(chuàng)業(yè)管理》2022-2023學(xué)年第一學(xué)期期末試卷
- 西昌學(xué)院《英漢筆譯實踐》2023-2024學(xué)年第一學(xué)期期末試卷
- 高溫合金精品PPT課件
- 課題研究計劃執(zhí)行情況(共10篇)
- DB51∕T 5057-2016 四川省高分子復(fù)合材料檢查井蓋、水箅技術(shù)規(guī)程
- 教師德育工作考核細則條例
- GB∕T 41168-2021 食品包裝用塑料與鋁箔蒸煮復(fù)合膜、袋
- 2022年聯(lián)合辦學(xué)方案范文
- 百錯圖與答案
- 百度谷歌經(jīng)緯度轉(zhuǎn)換工具
- 洗煤廠項目建議書范文
- 產(chǎn)教深度融合三年規(guī)劃
- 職業(yè)病體檢報告模版
評論
0/150
提交評論