oracle日常巡检--检查数据库基本情况
概述
之前整理总结的关于日常巡检方面内容,主要分五块,第一块是对数据库基本情况的检查,下面介绍下相关命令,有点多,大家可以参考下:
相关命令
1、查看数据库实例状态
select instance_name,host_name,startup_time,status,database_status from v$instance;
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;
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%';
4、查看数据库中段的类型
select segment_type,count(2) from dba_segments group by segment_type order by segment_type
5、查看数据库字符集
select * from nls_database_parameters;
服务器端结果: AMERICAN_AMERICA.ZHS16GBK
1)Language: 指定服务器消息的语言, 影响提示信息是中文还是英文
2)Territory: 指定服务器的日期和数字格式,
3)Charset: 指定字符集。
6、控制文件的名称和大小
select name,block_size*file_size_blks/1024/1024 MB from v$controlfile;
7、联机重做日志文件成员的名称和大小
col member for a80; select member,bytes,type,group#,sequence# from v$log join v$logfile using (group#);
8、数据文件和临时文件的名称、大小、状态
select name,bytes/1024/1024 MB,status from v$datafile d union all select name,bytes/1024/1024 MB,status from v$tempfile;
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;
10、检查无效对象
select owner,object_name,object_type from dba_objects where status!='VALID' and owner!='SYS' and owner!='SYSTEM';
如果有记录返回,则说明存在无效对象。若这些对象与应用相关,那么需要重新编译生成这个对象
11、检查所有回滚段状态
select segment_name,owner,tablespace_name,STATUS,instance_num from dba_rollback_segs;
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);
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#';
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;
如果有记录返回,则这些对象的扩展已经快达到它定义时的最大扩展值。对于这些对象要修改它的存储结构参数。
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表空间,同时应该检查这些对象属主的缺省表空间值。
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;
如果有记录返回,则表明这些对象的下一个扩展大于该对象所属表空间的最大扩展值,需调整相应表空间的存储参数。
今天加班加的有点晚,所以偷懒下,发一下之前整理的一些日常巡检内容凑合,哈哈。
后面会分享更多关于devops和DBA方面的内容,感兴趣的朋友可以关注下!!