Oracle 日常檢查

概述:

回顧當初做Oracle dba的日子,經常檢查的內容整理了一下,今天分享給大家,希望對大家有所幫助。

Oracle 日常檢查

1、檢查資料庫的連線情況

1)

檢視當前不為空的連線

select * from v$session where username is not null

主要字典解析:

SID 會話(session)的ID號;

SERIAL# 會話的序列號,和SID一起用來唯一標識一個會話;

USERNAME 建立該會話的使用者名稱;

PROGRAM 這個會話是用什麼工具連線到資料庫的;

STATUS 當前這個會話的狀態,ACTIVE表示會話正在執行某些任務,INACTIVE表示當前會話沒有執行任何操作;

2)

檢視不同使用者的連線數

select username,count(username) from v$session where username is not null group by username;

3)

#連線數

select count(*) from v$session;

4)

#併發連線數(sql developer 中的clients)

Select count(*) from v$session where status=‘ACTIVE’;

5)

#最大併發數

show parameter processes

2、表空間使用統計

SELECT a。tablespace_name, round(((a。bytes - b。bytes) * 100) / a。maxbytes, 2) “% USED”, round(((a。maxbytes - a。bytes + b。bytes) * 100) / a。maxbytes, 2) “% FREE”, round(a。maxbytes / 1024 / 1024 / 1024, 2) “TOTAL(G)”, round((a。bytes - b。bytes) / 1024 / 1024 / 1024, 2) “USED(G)”, round((a。maxbytes - a。bytes + b。bytes) / 1024 / 1024 / 1024, 2) “FREE(G)”, round(a。maxbytes / 1024 / 1024, 2) “TOTAL(M)”, round((a。bytes - b。bytes) / 1024 / 1024, 2) “USED(M)”, round((a。maxbytes - a。bytes + b。bytes) / 1024 / 1024, 2) “FREE(M)” FROM (SELECT ddf。tablespace_name, SUM(decode(ddf。autoextensible, ‘NO’, ddf。bytes, (sqrt((ddf。bytes + ddf。maxbytes) * (ddf。bytes + ddf。maxbytes)) + sqrt((ddf。bytes - ddf。maxbytes) * (ddf。bytes - ddf。maxbytes))) / 2)) maxbytes, SUM(ddf。bytes) bytes FROM dba_data_files ddf GROUP BY ddf。tablespace_name) a, (SELECT dfs。tablespace_name, SUM(dfs。bytes) bytes FROM dba_free_space dfs GROUP BY dfs。tablespace_name) b WHERE a。tablespace_name = b。tablespace_name(+) ORDER BY round(((a。bytes - b。bytes) * 100) / a。maxbytes, 2) DESC;

3、檢查擴充套件異常的物件

select Segment_Name,Segment_Type,TableSpace_Name, (Extents / Max_extents) * 100 PercentFrom sys。DBA_SegmentsWhere Max_Extents != 0and (Extents / Max_extents) * 100 >= 95order By Percent;

如果有記錄返回,則這些物件的擴充套件已經快達到它定義時的最大擴充套件值。

4、檢查system表空間的內容

select distinct (owner)from dba_tableswhere tablespace_name = ‘SYSTEM’and owner != ‘SYS’and owner != ‘SYSTEM’unionselect distinct (owner)from dba_indexeswhere tablespace_name = ‘SYSTEM’and owner != ‘SYS’and owner != ‘SYSTEM’;

如果記錄返回,則表明system表空間記憶體在一些非system和sys使用者的物件。應該進一步檢查這些物件是否與我們應用相關。如果相關請把這些物件移到非System表空間,同時應該檢查這些物件屬主的預設表空間值。

5、檢查物件的下一個擴充套件和表空間的最大 擴充套件值

select a。table_name, a。next_extent, a。tablespace_namefrom all_tables a, (select tablespace_name, max(bytes) as big_chunk from dba_free_space group by tablespace_name) fwhere f。tablespace_name = a。tablespace_name and a。next_extent > f。big_chunkunionselect a。index_name, a。next_extent, a。tablespace_namefrom all_indexes a, (select tablespace_name, max(bytes) as big_chunk from dba_free_space group by tablespace_name) fwhere f。tablespace_name = a。tablespace_name and a。next_extent > f。big_chunk;

如果有記錄返回,則表明這些物件的下一個擴充套件值大於該物件所屬表空間的最大擴充套件值,需調整相應表空間的儲存引數。

喜歡的可以點關注,我將分享更多的Oracle實戰專案經驗,謝謝。