oracle日常巡檢--檢查數據庫基本情況

概述

之前整理總結的關於日常巡檢方面內容,主要分五塊,第一塊是對數據庫基本情況的檢查,下面介紹下相關命令,有點多,大家可以參考下:


相關命令

1、查看數據庫實例狀態

select instance_name,host_name,startup_time,status,database_status from v$instance; 
oracle日常巡檢--檢查數據庫基本情況

2、查看數據庫數據塊大小

set line 250
col name for a50
select file#,name,block_size from v$datafile;
select group#,members,bytes/1024/1024 ,blocksize from v$log;
select name,block_size ,file_size_blks from v$controlfile;
oracle日常巡檢--檢查數據庫基本情況

oracle日常巡檢--檢查數據庫基本情況

oracle日常巡檢--檢查數據庫基本情況

3、查看oracle各組件的大小

官方建議OLTP:SGA=(Host Memory)*80%*80% OLAP:SGA=(Host Memory)*80%*50%

官方建議OLTP:PGA=(Host Memory)*80%*20% OLAP:PGA=(Host Memory)*80%*50%

set line 250
col name for a50
col value for a50
col describ for a80
select x.ksppinm name, y.ksppstvl value, x.ksppdesc describ from x$ksppi x, x$ksppcv y where x.inst_id = userenv('Instance') and y.inst_id = userenv('Instance')
and x.indx = y.indx and x.ksppinm like'%pool_size%';
oracle日常巡檢--檢查數據庫基本情況

4、查看數據庫中段的類型

select segment_type,count(2) from dba_segments group by segment_type order by segment_type
oracle日常巡檢--檢查數據庫基本情況

5、查看數據庫字符集

select * from nls_database_parameters;

服務器端結果: AMERICAN_AMERICA.ZHS16GBK

1)Language: 指定服務器消息的語言, 影響提示信息是中文還是英文

2)Territory: 指定服務器的日期和數字格式,

3)Charset: 指定字符集。

oracle日常巡檢--檢查數據庫基本情況

6、控制文件的名稱和大小

select name,block_size*file_size_blks/1024/1024 MB from v$controlfile;
oracle日常巡檢--檢查數據庫基本情況

7、聯機重做日誌文件成員的名稱和大小

col member for a80;
select member,bytes,type,group#,sequence# from v$log join v$logfile using (group#);
oracle日常巡檢--檢查數據庫基本情況

8、數據文件和臨時文件的名稱、大小、狀態

select name,bytes/1024/1024 MB,status from v$datafile d union all select name,bytes/1024/1024 MB,status from v$tempfile;
oracle日常巡檢--檢查數據庫基本情況

9、查看錶空間情況

SELECT a.tablespace_name "表空間名", total "表空間大小", free "表空間剩餘大小", (total - free) "表空間使用大小", total / (1024 * 1024 * 1024) "表空間大小(G)", 
free / (1024 * 1024 * 1024) "表空間剩餘大小(G)",(total - free) / (1024 * 1024 * 1024) "表空間使用大小(G)", 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;
oracle日常巡檢--檢查數據庫基本情況

10、檢查無效對象

select owner,object_name,object_type from dba_objects where status!='VALID' and owner!='SYS' and owner!='SYSTEM';

如果有記錄返回,則說明存在無效對象。若這些對象與應用相關,那麼需要重新編譯生成這個對象

oracle日常巡檢--檢查數據庫基本情況

11、檢查所有回滾段狀態

select segment_name,owner,tablespace_name,STATUS,instance_num from dba_rollback_segs;

oracle日常巡檢--檢查數據庫基本情況

12、查看每天產生歸檔日誌的數據量

alter session set nls_date_format=‘yyyy.mm.dd hh24:mi:ss‘;
select trunc(completion_time) as ARC_DATE,
count(*) as COUNT,
round((sum(blocks * block_size) / 1024 / 1024), 2) as ARC_MB
from v$archived_log
group by trunc(completion_time)
order by trunc(completion_time);
oracle日常巡檢--檢查數據庫基本情況

13、查看磁盤空間分配

asmcmd lsdg

[grid@nwppdb1:/home/grid]$asmcmd lsdg
State Type Rebal Sector Block AU Total_MB Free_MB Req_mir_free_MB Usable_file_MB Offline_disks Voting_files Name
MOUNTED EXTERN N 512 4096 8388608 511992 388480 0 388480 0 N DGDATA01/
MOUNTED EXTERN N 512 4096 8388608 51200 50728 0 50728 0 Y DGGRID1/
MOUNTED EXTERN N 512 4096 8388608 51200 50768 0 50768 0 N DGGRID2/
MOUNTED EXTERN N 512 4096 8388608 511992 432832 0 432832 0 N DGRECOVERY/
MOUNTED EXTERN N 512 4096 8388608 307208 302200 0 302200 0 N DGSYSTEM/

14、查看oracle連接數以及活躍連接數

select t.INST_ID,count(*) count_all,sum(case when t.STATUS = 'ACTIVE' then 1 else 0 end) count_active from gv$session t group by t.INST_ID order by t.inst_id;
select sid,serial#,username,program,machine,status from v$session;
alter system kill session 'SID,SERIAL#';
oracle日常巡檢--檢查數據庫基本情況

oracle日常巡檢--檢查數據庫基本情況

15、檢查一些擴展異常的對象

select Segment_Name,Segment_Type,TableSpace_Name, (Extents / Max_extents) * 100 Percent From sys.DBA_Segments

Where Max_Extents != 0 and (Extents / Max_extents) * 100 >= 95 order By Percent;

如果有記錄返回,則這些對象的擴展已經快達到它定義時的最大擴展值。對於這些對象要修改它的存儲結構參數。

oracle日常巡檢--檢查數據庫基本情況

16、檢查system表空間內的內容

select distinct (owner),table_name,status
from dba_tables
where tablespace_name = 'SYSTEM'
and owner != 'SYS'
and owner != 'SYSTEM'
union
select distinct (owner),table_name,status
from dba_indexes
where tablespace_name = 'SYSTEM'
and owner != 'SYS'
and owner != 'SYSTEM';

如果有記錄返回,則表明system表空間內存在一些非system和sys用戶的對象。應該進一步檢查這些對象是否與我們應用相關。如果相關請把這些對象移到非System表空間,同時應該檢查這些對象屬主的缺省表空間值。

oracle日常巡檢--檢查數據庫基本情況

17、檢查對象的下一擴展與表空間的最大擴展值

select a.table_name, a.next_extent, a.tablespace_name
from all_tables a,
(select tablespace_name, max(bytes) as big_chunk
from dba_free_space
group by tablespace_name) f
where f.tablespace_name = a.tablespace_name
and a.next_extent > f.big_chunk
union
select a.index_name, a.next_extent, a.tablespace_name
from all_indexes a,
(select tablespace_name, max(bytes) as big_chunk
from dba_free_space
group by tablespace_name) f
where f.tablespace_name = a.tablespace_name
and a.next_extent > f.big_chunk;

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

oracle日常巡檢--檢查數據庫基本情況


今天加班加的有點晚,所以偷懶下,發一下之前整理的一些日常巡檢內容湊合,哈哈。

後面會分享更多關於devops和DBA方面的內容,感興趣的朋友可以關注下!!

oracle日常巡檢--檢查數據庫基本情況


分享到:


相關文章: