实际工作中,不管是接手管理一个新的数据库还是定期对数据进行检查,我们都需要一个全面系统的工作,以下是我自己的实际工作操作并结合网上一些前辈对oracle巡检的经验总结的一篇文章,希望可以给到新人以参考并得到老鸟的补充和建议。
Ps:文中的系统平台为linux,除过系统平台的检查外,oracle数据库的检查同样适用windows平台。
一、系统配置
----------------------------------------------------------
1、查看主机名
[root@wtdb2 ~]# uname -n
wtdb2
2、查看运行的硬件平台类型
[root@wtdb2 ~]# uname -im
x86_64 x86_64
3、查看cpu类型
[root@wtdb2 ~]# uname -p
x86_64
4、查看cpu型号及参数信息
[root@wtdb2 ~]# more /proc/cpuinfo
processor : 0
vendor_id : AuthenticAMD
cpu family : 16
model : 2
model name : Quad-Core AMD Opteron(tm) Processor 8356
stepping : 3
cpu MHz : 2300.084
cache size : 512 KB
5、查看内存信息
[root@wtdb2 ~]# free
total used free shared buffers cached
Mem: 32907676 13428340 19479336 0 587384 8346640
-/+ buffers/cache: 4494316 28413360
Swap: 26869752 0 26869752
6、查看操作系统版本
[root@wtdb2 ~]# lsb_release -d
Description: Red Hat Enterprise Linux AS release 4 (Nahant Update 6)
或
[root@wtdb2 ~]# cat /etc/redhat-release
Red Hat Enterprise Linux AS release 4 (Nahant Update 6)
7、查看操作系统内核信息
[root@wtdb2 ~]# uname -sr
Linux 2.6.9-67.ELlargesmp
8、查看服务器信息
[root@wtdb2 ~]# /usr/sbin/dmidecode |grep "Product Name"
Product Name: ProLiant DL785 G5
二、内容参数
----------------------------------------------------------------------
1、共享内存等
[root@wtdb2 ~]# cat /etc/sysctl.conf |grep -v "#" |grep -v "^$"
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
kernel.shmall = 2097152
kernel.shmmax = 21474836480
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
fs.file-max = 65536
net.ipv4.ip_local_port_range = 1024 65000
net.core.rmem_default = 262144
net.core.rmem_max = 262144
net.core.wmem_default = 262144
net.core.wmem_max = 262144
2、oracle用户限制
[root@wtdb2 ~]# su - oracle
[oracle@wtdb2 ~]$ ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
file size (blocks, -f) unlimited
pending signals (-i) 1024
max locked memory (kbytes, -l) 32
max memory size (kbytes, -m) unlimited
open files (-n) 65536
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
stack size (kbytes, -s) 10240
cpu time (seconds, -t) unlimited
max user processes (-u) 16384
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
三、磁盘的空间(非ASM环境)
----------------------------------------------------------------------------------
[root@wtdb2 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
25G 14G 11G 57% /
/dev/mapper/VolGroup00-LogVol01
81G 8.7G 69G 12% /u01
/dev/mapper/mpath47 50G 3.0G 44G 7% /u02/arch
/dev/cciss/c0d0p1 99M 15M 80M 16% /boot
none 16G 0 16G 0% /dev/shm
20.20.20.2:/u02/bak 591G 286G 276G 51% /u02/bak
四、数据库配置
-------------------------------------------------------------------------------------
1、查看RDBMS版本
SQL> select * from v$version;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Release 10.2.0.4.0 - Production
CORE 10.2.0.4.0 Production
TNS for Linux: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production
2、查看安装选项
SQL> select * from v$option;
PARAMETER VALUE
---------------------------------------- ----------
Partitioning TRUE
Objects TRUE
Real Application Clusters TRUE
3、已被使用的产品选项
SQL> select comp_id, comp_name, version,status from dba_registry;
COMP_ID COMP_NAME VERSION STATUS
---------------------------------------------------------------------- ----
SDO Spatial 10.2.0.4.0 VALID
ORDIM Oracle interMedia 10.2.0.4.0 VALID
AMD OLAP Catalog 10.2.0.4.0 VALID
EM Oracle Enterprise Manager 10.2.0.4.0 VALID
XDB Oracle XML Database 10.2.0.4.0 VALID
CONTEXT Oracle Text 10.2.0.4.0 VALID
EXF Oracle Expression Filter 10.2.0.4.0 VALID
RUL Oracle Rules Manager 10.2.0.4.0 VALID
OWM Oracle Workspace Manager 10.2.0.4.3 VALID
ODM Oracle Data Mining 10.2.0.4.0 VALID
CATALOG Oracle Database Catalog Views 10.2.0.4.0 VALID
4、数据库参数
参数文件
SQL> show parameter spfile;
SQL> select NAME,VALUE,ISDEFAULT as "Default",ISSYS_MODIFIABLE as "Dynamic" from v$system_parameter order by name;
数据库非默认参数
SQL> select name , value from v$parameter where isdefault='FALSE';
NAME VALUE
---------------------------------------- ----------------------------------------
processes 3000
sessions 3500
sga_max_size 4294967296
large_pool_size 218103808
spfile +DATA01/zjcsc/spfilezjcsc.ora
sga_target 4294967296
control_files +DATA01/zjcsc/controlfile/current.260.72
5、内存管理配置
a、查看sga
SQL> show sga
Total System Global Area 4294967296 bytes
Fixed Size 2286080 bytes
Variable Size 2107317760 bytes
Database Buffers 2181038080 bytes
Redo Buffers 4325376 bytes
SQL> show parameter sga
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
lock_sga boolean FALSE
pre_page_sga boolean FALSE
sga_max_size big integer 4G
sga_target big integer 4G
b、查看pga
SQL> show parameter pga
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
pga_aggregate_target big integer 3203M
五、文件和日志
----------------------------------------------------------------------------------
1、查看跟踪文件,待补充
2、检查alert.log
SQL> show parameter dump
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
background_core_dump string partial
background_dump_dest string /u01/app/oracle/admin/zjcsc/bdump
core_dump_dest string /u01/app/oracle/admin/zjcsc/cdump
max_dump_file_size string UNLIMITED
shadow_core_dump string partial
user_dump_dest string /u01/app/oracle/admin/zjcsc/udump
SQL> host
[oracle@wtdb2 ~]$ cd /u01/app/oracle/admin/zjcsc/bdump/
[oracle@wtdb2 bdump]$ more alert_zjcsc2.log
3、检查控制文件
记录数据库的物理机构及同步信息,建议同时存在2份以上的控制文件,并保存在不同的磁盘上。
SQL> show parameter control_files;
或者
SQL> select status,name,is_recovery_dest_file,(block_size*file_size_blks)/1024/1024 "Mbytes" from v$controlfile;
4、检查审计文件
SQL> show parameter audit_file_dest
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
audit_file_dest string /u01/app/oracle/admin/zjcsc/adump
如果没有设定,默认审计文件在$ORACLE_HOME/rdbms/audit
5、redo log 文件
建议配置多redo日志组(2个以上的日志组),对redo日志进行镜像保存,配置2个及其以上的redo日志镜像。
connect as sysdba
SQL> select group#,thread#,bytes,members,archived,status from v$log;
SQL> select * from v$logfile order by 1;
SQL>
select l.group#, lf.member as Logfile,l.status,l.bytes/1024/1024 as "Size/MB"
from v$log l,v$logfile lf
where l.group#=lf.group#
order by group#;
GROUP# LOGFILE STATUS Size/MB
---------- -------------------------------------------------- ---------------- ----------
1 +DATA01/zjcsc/onlinelog/group_1.261.729380855 INACTIVE 50
2 +DATA01/zjcsc/onlinelog/group_2.262.729380855 INACTIVE 50
3 +DATA01/zjcsc/onlinelog/group_3.265.729380935 INACTIVE 50
4 +DATA01/zjcsc/onlinelog/group_4.266.729380935 INACTIVE 50
5 +DATA01/zjcsc/onlinelog/group_5.315.729393001 CURRENT 100
6 +DATA01/zjcsc/onlinelog/group_6.316.729393021 ACTIVE 100
7 +DATA01/zjcsc/onlinelog/group_7.317.729393041 INACTIVE 100
8 +DATA01/zjcsc/onlinelog/group_8.318.729393053 INACTIVE 100
9 +DATA01/zjcsc/onlinelog/group_9.319.729393091 INACTIVE 100
10 +DATA01/zjcsc/onlinelog/group_10.320.729393109 CURRENT 100
6、archived log 文件
如果空间允许,建议归档日志保存2份及其以上镜像。
connect as sysdba
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u02/arch
Oldest online log sequence 31135
Next log sequence to archive 31139
Current log sequence 31139
select * from v$archive_dest;
select * from v$archive;
select * from v$archived_log;
6、数据文件
a、查看数据文件(所有数据文件总和)大小
SQL> select count(*) "count",sum(bytes)/1024/1024 "Mbyters" from v$datafile;
count Mbyters
---------- ----------
75 708672
b、查看数据文件位置及大小
SQL> select tablespace_name,file_id,bytes,autoextensible,status,file_name from dba_data_files;
TABLESPACE_NAME FILE_ID BYTES AUT STATUS FILE_NAME
------------------------------ ---------- ---------- --- --------- --------------------------------------------------
USERS 4 1845493760 YES AVAILABLE +DATA01/zjcsc/datafile/users.259.729380787
SYSAUX 3 5368709120 YES AVAILABLE +DATA01/zjcsc/datafile/sysaux.257.729380787
UNDOTBS1 2 1.0737E+10 YES AVAILABLE +DATA01/zjcsc/datafile/undotbs1.258.729380787
SYSTEM 1 2147483648 YES AVAILABLE +DATA01/zjcsc/datafile/system.256.729380787
UNDOTBS2 5 1.0737E+10 YES AVAILABLE +DATA01/zjcsc/datafile/undotbs2.264.729380887
c、查看数据文件是否自动扩展,默认系统表空间的是自动扩展的。
SQL> select file_id, tablespace_name, bytes, maxbytes, maxblocks, increment_by, file_name from dba_data_files where autoextensible = 'YES';
FILE_ID TABLESPACE_NAME BYTES MAXBYTES MAXBLOCKS INCREMENT_BY FILE_NAME
---------- ------------------------------ ---------- ---------- ---------- ------------ --------------------------------------------------
4 USERS 1845493760 3.4360E+10 4194302 160 +DATA01/zjcsc/datafile/users.259.729380787
3 SYSAUX 5368709120 3.4360E+10 4194302 12800 +DATA01/zjcsc/datafile/sysaux.257.729380787
2 UNDOTBS1 1.0737E+10 3.4360E+10 4194302 12800 +DATA01/zjcsc/datafile/undotbs1.258.729380787
1 SYSTEM 2147483648 3.4360E+10 4194302 12800 +DATA01/zjcsc/datafile/system.256.729380787
5 UNDOTBS2 1.0737E+10 3.4360E+10 4194302 12800 +DATA01/zjcsc/datafile/undotbs2.264.729380887
48 BIZMONITOR 209715200 3.4360E+10 4194302 1280 +DATA01/ts_ssvc_bizmonitor.dbf
49 WLANINDEX 209715200 3.4360E+10 4194302 1280 +DATA01/ts_ssvc_wlanindex.dbf
六、表空间
--------------------------------------------------------------------------------------------------------------------
1、查看表空间使用情况,可查询dba_tablespace; dba_free_space; dba_data_files;
select * from (
Select a.tablespace_name,
round(a.bytes/1024/1024,3) total_bytes,
round(b.bytes/1024/1024,3) free_bytes,
round(a.bytes/1024/1024 - b.bytes/1024/1024,3) use_bytes,
round((1 - b.bytes/a.bytes)*100,3) || '%' use
from (select tablespace_name,
sum(bytes) bytes
from dba_data_files
group by tablespace_name) a,
(select tablespace_name,
sum(bytes) bytes
from dba_free_space
group by tablespace_name) b
where a.tablespace_name = b.tablespace_name
union all
select c.tablespace_name,
round(c.bytes/1024/1024,3) total_bytes,
round( (c.bytes-d.bytes_used)/1024/1024,3) free_bytes,
round(d.bytes_used/1024/1024,3) use_bytes,
round(d.bytes_used*100/c.bytes,3) || '%' use
from
(select tablespace_name,sum(bytes) bytes
from dba_temp_files group by tablespace_name) c,
(select tablespace_name,sum(bytes_cached) bytes_used
from v$temp_extent_pool group by tablespace_name) d
where c.tablespace_name = d.tablespace_name
)
order by tablespace_name;
2、表空间可用性检查(online or offline)
SQL> select tablespace_name,status from dba_tablespaces;
TABLESPACE_NAME STATUS
------------------------------ ---------
SYSTEM ONLINE
UNDOTBS1 ONLINE
SYSAUX ONLINE
TEMP ONLINE
USERS ONLINE
UNDOTBS2 ONLINE
4、查看表空间管理类型(数据字典管理or本地管理,9i之后默认的管理方式为本地管理方式)
SQL> select tablespace_name, extent_management from dba_tablespaces;
5、查看临时表空间
a、检查当前永久表空间和临时表空间
SQL> select tablespace_name, contents from dba_tablespaces;
b、检查是否存在永久表空间类型的临时表空间(10G之后应该不会有这种情况)
SQL> select u.username, t.tablespace_name
from dba_users u, dba_tablespaces t
where u.temporary_tablespace = t.tablespace_name
and t.contents <> 'TEMPORARY';
c、检查临时表空间大小
SQL> select tablespace_name, sum(bytes)/1024/1024 mb
from dba_temp_files
group by tablespace_name;
d、查看临时表空间使用的高水位线(同一时间最大的使用量)
SQL> select tablespace_name, sum(bytes_cached)/1024/1024 mb
from v$temp_extent_pool
group by tablespace_name;
e、查看临时表空间当前使用情况
待定。。。
6、表空间碎片问题
待定。。。
七、数据库对象
-------------------------------------------------------------------------------------------------------------------
1、检查无效的数据库对象
无效数据对象,应在系统不繁忙的时候,进行手工删除,防止在系统压力较大的时候,手工编译或者自动编译,否则可能会导致的数据库死锁。
SQL> SELECT owner,object_type,object_name,status,LAST_DDL_TIME FROM dba_objects WHERE status like 'INVALID';
2、查看在系统表空间(system,sysaux)内的非系统用户(sys,system)对象。
SQL> select owner, segment_name, segment_type from dba_segments where tablespace_name = 'SYSTEM' and owner not in ('SYS','SYSTEM');
OWNER SEGMENT_NAME SEGMENT_TYPE
---------- ---------------------------------------- ------------------
ZJCSC517 LOGIN_DATE_CZH_7 INDEX
ZJCSC517 LOGIN_ID_CZH_7 INDEX
ZJCSC517 LOGIN_TYPE_CZH_7 INDEX
3、检查数据库连接
SQL> SELECT * FROM DBA_DB_LINKS;
4、检查索引
索引需要维护。对于表的删除或者添加操作都会间接地对index进行相应的操作。过时的index结构会产生碎片,此时index需要被重新建立。
belevel是B-tree索引形式的一部分,与oracle为搜索某些记录而减少index搜索的次数相关联。在一些情况下,BLEVEL需要单独的磁盘命中。
如果blevel>4,那么建议重建index
SQL> select * from dba_indexes where blevel>4;
八、安全管理
------------------------------------------------------------------------------------------------------------------------
database / administrator
检查sys/system 不要使用默认密码
检查被授予DBA权限的用户,收回不必要的
select grantee,granted_role from dba_role_privs where granted_role='DBA'
检查被授予SYSDBA权限的用户
select * from v$pwfile_users;
九、监听器的设置
------------------------------------------------------------------------------------------------------------------------
1、位于服务器端的监听程序时单独的进程。它从客户端接收连接请求,并管理这些对服务端的请求。
cd $ORACLE_HOME/network/admin
more listener.ora
2、SQLNET.ORA设置
包含了客户端和服务器对SQL*NET配置的设置信息。
cd $ORACLE_HOME/network/admin
more sqlnet.log
3、TNSNAMES.ORA
包含了与连接描述符相匹配的网络服务名。连接描述符包括监听程序的地址以及connect_data
cd $ORACLE_HOME/network/admin
more tnsnames.ora
十、数据库性能
------------------------------------------------------------------------------------------------------------------------
statspack或者awr报告
十一、数据库备份和恢复概况
------------------------------------------------------------------------------------------------------------------------
检查备份恢复策略
建议:根据不同的数据库失败情况制定相应的恢复策略
全库恢复
表空间恢复
数据文件恢复
表恢复
制定的恢复策略进行恢复测试。