|
|
ORACLE数据库管理员应按如下方式对ORACLE数据库系统做定期监控: (1). 每天对ORACLE数据库的运行状态,日志文件,备份情况,数据 库的空间使用情况,系统资源的使用情况进行检查,发现并解决问题。 (2). 每周对数据库对象的空间扩展情况,数据的增长情况进行监控,对数据库做健康检查,对数据库对象的状态做检查。 (3). 每月对表和索引等进行Analyze,检查表空间碎片,寻找数据库性能调整的机会,进行数据库性能调整,提出下一步空间管理计划。对ORACLE数据库状态进行一次全面检查。 每天的工作 (1).确认所有的INSTANCE状态正常登陆到所有数据库或例程,检测ORACLE后台进程: $ps –ef|grep ora (2). 检查文件系统的使用(剩余空间)。如果文件系统的剩余空间小于20%,需删除不用的文件以释放空间。 $df –k (3). 检查日志文件和trace文件记录alert和trace文件中的错误。 连接到每个需管理的系统 ? 使用’telnet’ ? 对每个数据库,cd 到bdump目录,通常是$ORACLE_BASE/<SID>/bdump ? 使用 Unix ‘tail’命令来查看alert_<SID>.log文件 ? 如果发现任何新的ORA- 错误,记录并解决 (4). 检查数据库当日备份的有效性。 对RMAN备份方式: 检查第三方备份工具的备份日志以确定备份是否成功 对EXPORT备份方式: 检查exp日志文件以确定备份是否成功 对其他备份方式: 检查相应的日志文件 (5). 检查数据文件的状态记录状态不是“online”的数据文件,并做恢复。 Select file_name from dba_data_files where status=’OFFLINE’ (6). 检查表空间的使用情况 SELECT tablespace_name, max_m, count_blocks free_blk_cnt, sum_free_m,to_char(100*sum_free_m/sum_m, '99.99') || '%' AS pct_free FROM ( SELECT tablespace_name,sum(bytes)/1024/1024 AS sum_m FROM dba_data_files GROUP BY tablespace_name), ( SELECT tablespace_name AS fs_ts_name, max(bytes)/1024/1024 AS max_m, count(blocks) AS count_blocks, sum(bytes/1024/1024) AS sum_free_m FROM dba_free_space GROUP BY tablespace_name ) WHERE tablespace_name = fs_ts_name (7). 检查剩余表空间 SELECT tablespace_name, sum ( blocks ) as free_blk , trunc ( sum ( bytes ) /(1024*1024) ) as free_m, max ( bytes ) / (1024) as big_chunk_k, count (*) as num_chunks FROM dba_free_space GROUP BY tablespace_name; (8). 监控数据库性能 运行bstat/estat生成系统报告 或者使用statspack收集统计数据 (9). 检查数据库性能,记录数据库的cpu使用、IO、buffer命中率等等 使用vmstat,iostat,glance,top等命令 (10). 日常出现问题的处理。 每周的工作 (1). 控数据库对象的空间扩展情况 根据本周每天的检查情况找到空间扩展很快的数据库对象,并采取相应的措施 -- 删除历史数据 --- 扩表空间 alter tablespace <name> add datafile ‘<file>’ size <size> --- 调整数据对象的存储参数 next extent pct_increase (2). 监控数据量的增长情况 根据本周每天的检查情况找到记录数量增长很快的数据库对象,并采取相应的措施 -- 删除历史数据 --- 扩表空间 alter tablespace <name> add datafile ‘<file>’ size <size> (3). 系统健康检查 检查以下内容: init<sid>.ora controlfile redo log file archiving sort area size tablespace(system,temporary,tablespace fragment) datafiles(autoextend,location) object(number of extent,next extent,index) rollback segment logging &tracing(alert.log,max_dump_file_size,sqlnet) (4). 检查无效的数据库对象 SELECT owner, object_name, object_type FROM dba_objects WHERE status=’INVALID’。 (5). 检查不起作用的约束 SELECT owner, constraint_name, table_name, constraint_type, status FROM dba_constraints WHERE status = 'DISABLED’ AND constraint_type = 'P' (6). 检查无效的trigger SELECT owner, trigger_name, table_name, status FROM dba_triggers WHERE status = 'DISABLED’ 每月的工作 (1). Analyze Tables/Indexes/Cluster analyze table <name> estimate statistics sample 50 percent; (2). 检查表空间碎片 根据本月每周的检查分析数据库碎片情况,找到相应的解决方法 (3). 寻找数据库性能调整的机会 比较每天对数据库性能的监控报告,确定是否有必要对数据库性能进行调整 (4). 数据库性能调整 如有必要,进行性能调整 (5). 提出下一步空间管理计划 根据每周的监控,提出空间管理的改进方法 Oracle DBA 日常管理 目的:这篇文档有很详细的资料记录着对一个甚至更多的ORACLE 数据库每天的,每月的,每年的运行的状态的结果及检查的结果,在文档的附录中你将会看到所有检查,修改的SQL和PL/SQL 代码。 一.日维护过程 A.查看所有的实例是否已起 确定数据库是可用的,把每个实例写入日志并且运行日报告或是运行测试文件。当然有一些操作我们是希望它能自动运行的。 可选择执行:用ORACLE 管理器中的‘PROBE’事件来查看 B.查找新的警告日志文件 1. 联接每一个操作管理系统 2. 使用‘TELNET’或是可比较程序 3. 对每一个管理实例,经常的执行$ORACLE_BASE/<SID>/bdump 操作,并使其能回退到控制数据库的SID。 4. 在提示下,使用UNIX 中的‘TAIL’命令查看alert_<SID>.log,或是用其他方式检查文件中最近时期的警告日志 5. 如果以前出现过的一些ORA_ERRORS 又出现,将它记录到数据库恢复日志中并且仔细的研究它们,这个数据库恢复日志在〈FILE〉中 C.查看DBSNMP 的运行情况 检查每个被管理机器的‘DBSNMP’进程并将它们记录到日志中。 在UNIX 中,在命令行中,键入ps –ef | grep dbsnmp,将回看到2 个DBSNMP 进程在运行。如果没有,重启DBSNMP。 D.查数据库备份是否成功 E.检查备份的磁带文档是否成功 F.检查对合理的性能来说是否有足够的资源 1. 检查在表空间中有没有剩余空间。 对每一个实例来说,检查在表空间中是否存在有剩余空间来满足当天的预期的需要。当数据库中已有的数据是稳定的,数据日增长的平均数也是可以计算出来,最小的剩余空间至少要能满足每天数据的增 长。 A) 运行‘FREE.SQL’来检查表空间的剩余空间。 B) 运行‘SPACE.SQL’来检查表空间中的剩余空间百分率 2. 检查回滚段 回滚段的状态一般是在线的,除了一些为复杂工作准备的专用 段,它一般状态是离线的。 a) 每个数据库都有一个回滚段名字的列表。 b) 你可以用V$ROLLSTAT 来查询在线或是离线的回滚段的现在状 态. c) 对于所有回滚段的存储参数及名字, 可用DBA_ROLLBACK_SEGS 来查询。但是它不如V$ROLLSTAT 准确。 3. 识别出一些过分的增长 查看数据库中超出资源或是增长速度过大的段,这些段的存储参 数需要调整。 a) 收集日数据大小的信息, 可以用‘ANALYZE5PCT.SQL’。如果你收集的是每晚的信息, 则可跳过这一步。 b) 检查当前的范围,可用‘NR.EXTENTS.SQL’。 c) 查询当前表的大小信息。 d) 查询当前索引大小的信息。 e) 查询增长趋势。 4. 确定空间的范围。 如果范围空间对象的NEXT_EXTENT 比表空间所能提供的最大范围还要大,那么这将影响数据库的运行。如果我们找到了这个目标,可以用‘ALTER TABLESPACE COALESCE’调查它的位置,或加另外 的数据文件。 A)运行‘SPACEBOUND.SQL’。如果都是正常的,将不返回任何行。 5. 回顾CPU,内存,网络,硬件资源论点的过程 A)检查CPU的利用情况,进到x:.htm =>system metrics=>CPU 利用页,CPU 的最大限度为400,当CPU 的占用保持在350 以上有一段时间的话,我们就需要查看及研究出现的问题。 G.将存档日志复制到备用数据库中如果有一个备用数据库,将适当的存档日志复制到备用数据库的期望位置,备用数据库中保存最近期的数据。 H. 经常查阅DBA 用户手册 如果有可能的话,要广泛的阅读,包括DBA 手册,行业杂志,新闻 组或是邮件列表。 ------------------------------------------------------------- 二.晚间维护过程 大部分的数据库产品将受益于每晚确定的检查进程的运行。 A. 收集VOLUMETRIC 数据 1. 分析计划和收集数据 更准确的分析计算并保存结果。 a) 如果你现在没有作这些的话,用‘MK VOLFACT.SQL’来创建测定体积的 表。 b) 收集晚间数据大小的信息,用‘ANALYZE COMP.SQL’。 c) 收集统计结果,用‘POP VOL.SQL’。 d) 在空闲的时候检查数据,可能的话,每周或每个月进行。 我是用MS EXCEL 和ODBC 的联接来检查数据和图表的增长 ------------------------------------------------------------- 三.每周维护过程 A. 查找被破坏的目标 1. 对于每个给定表空间的对象来说,NEXT_EXTENT 的大小是相同的,如 12/14/98,缺省的NEXT_EXTENT 的DATAHI 为1G,DATALO 为500MB,INDEXES 为256MB。 A) 检查NEXT_EXTENT 的设置,可用‘NEXTEXT。SQL’。 B) 检查已有的EXTENTS,可用‘EXISTEXT。SQL’。 2. 所有的表都应该有唯一的主键 a) 查看那些表没有主键,可用‘NO_PK.SQL’。 b) 查找那些主键是没有发挥作用的,可用‘DIS_PK.SQL’。 c) 所有作索引的主键都要是唯一的,可用‘ NONUPK。SQL’来检 查。 3. 所有的索引都要放到索引表空间中。运行‘MKREBUILD_IDX。SQL’ 4. 不同的环境之间的计划应该是同样的,特别是测试环境和成品环境之间的 计划应该相同。 a) 检查不同的2 个运行环境中的数据类型是否一致,可用‘DATATYPE.SQL’。 b) 在2 个不同的实例中寻找对象的不同点, 可用‘OBJ_COORD.SQL’。 c) 更好的做法是,使用一种工具,象寻求软件的计划管理器那样的 工具。 B. 查看是否有危害到安全策略的问题。 C. 查看报错的SQL*NET 日志。 1. 客户端的日志。 2. 服务器端的日志。 D..将所有的警告日志存档 E..供应商的主页 1. ORACLE 供应商 http://www.oracle.com http://technet.oracle.com http://www.oracle.com/support http://www.oramag.com 2. Quest Software http://www.quests.com 3. Sun Microsystems http://www.sun.com ---------------------------------------------------------------- 四.月维护过程 A.查看对数据库会产生危害的增长速度 1. 从以前的记录或报告中回顾段增长的变化以此来确定段增长带来危害 B. 回顾以前数据库优化性能的调整 1. 回顾一般ORACLE 数据库的调整点,比较以前的报告来确定有害的发展 趋势。 C. 查看I/O 的屏颈问题 1. 查看前期数据库文件的活动性,比较以前的输出来判断有可能导致屏颈 问题的趋势。 D. 回顾FRAGMENTATION E. 计划数据库将来的性能 1. 比较ORACLE 和操作系统的CPU,内存,网络,及硬盘的利用率以此来确定在近期将会有的一些资源争夺的趋势 2. 当系统将超出范围时要把性能趋势当作服务水平的协议来看 F. 完成调整和维护工作 1.使修改满足避免系统资源的争夺的需要,这里面包括增加新资源或使预期 的停工。 ---------------------------------------------------------------- 五.附录 A. 日常程序 -- free.sql --To verify free space in tablespaces --Minimum amount of free space --document your thresholds: --<tablespace_name> = <amount> m SELECT tablespace_name, sum ( blocks ) as free_blk , trunc ( sum ( bytes ) / (1024*1024) ) as free_m, max ( bytes ) / (1024) as big_chunk_k, count (*) as num_chunks FROM dba_free_space GROUP BY tablespace_name 1. Space.sql -- space.sql -- To check free, pct_free, and allocated space within a tablespace -- 11/24/98 SELECT tablespace_name, largest_free_chunk , nr_free_chunks, sum_alloc_blocks, sum_free_blocks , to_char(100*sum_free_blocks/sum_alloc_blocks, '09.99') || '%' AS pct_free FROM ( SELECT tablespace_name , sum(blocks) AS sum_alloc_blocks FROM dba_data_files GROUP BY tablespace_name ) , ( SELECT tablespace_name AS fs_ts_name , max(blocks) AS largest_free_chunk , count(blocks) AS nr_free_chunks , sum(blocks) AS sum_free_blocks FROM dba_free_space GROUP BY tablespace_name ) WHERE tablespace_name = fs_ts_name 2. analyze5pct.sql -- analyze5pct.sql -- To analyze tables and indexes quickly, using a 5% sample size -- (do not use this script if you are performing the overnight -- collection of volumetric data) -- 11/30/98 BEGIN dbms_utility.analyze_schema ( '&OWNER', 'ESTIMATE', NULL, 5 ) ; END ; / 3. nr_extents.sql -- nr_extents.sql -- To find out any object reaching <threshold> -- extents, and manually upgrade it to allow unlimited -- max_extents (thus only objects we *expect* to be big -- are allowed to become big) -- 11/30/98 SELECT e.owner, e.segment_type , e.segment_name , count(*) as nr_extents , s.max_extents , to_char ( sum ( e.bytes ) / ( 1024 * 1024 ) , '999,999.90') as MB FROM dba_extents e , dba_segments s WHERE e.segment_name = s.segment_name GROUP BY e.owner, e.segment_type , e.segment_name , s.max_extents HAVING count(*) > &THRESHOLD OR ( ( s.max_extents - count(*) ) < &&THRESHOLD ) ORDER BY count(*) desc 4. spacebound.sql -- spacebound.sql -- To identify space-bound objects. If all is well, no rows are returned. -- If any space-bound objects are found, look at value of NEXT extent -- size to figure out what happened. -- Then use coalesce (alter tablespace <foo> coalesce . -- Lastly, add another datafile to the tablespace if needed. -- 11/30/98 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 B. 每晚处理程序 1. mk_volfact.sql -- mk_volfact.sql (only run this once to set it up; do not run it nightly!) -- -- Table UTL_VOL_FACTS CREATE TABLE utl_vol_facts ( table_name VARCHAR2(30), num_rows NUMBER, meas_dt DATE ) TABLESPACE platab STORAGE ( INITIAL 128k NEXT 128k PCTINCREASE 0 MINEXTENTS 1 MAXEXTENTS unlimited ) / -- Public Synonym CREATE PUBLIC SYNONYM utl_vol_facts FOR &OWNER..utl_vol_facts / -- Grants for UTL_VOL_FACTS GRANT SELECT ON utl_vol_facts TO public / 2. analyze_comp.sql -- -- analyze_comp.sql -- BEGIN sys.dbms_utility.analyze_schema ( '&OWNER','COMPUTE'); END ; / 3. pop_vol.sql -- -- pop_vol.sql -- insert into utl_vol_facts select table_name , NVL ( num_rows, 0) as num_rows , trunc ( last_analyzed ) as meas_dt from all_tables -- or just user_tables where owner in ('&OWNER') -- or a comma-separated list of owners / commit / C. 每周处理程序 1. nextext.sql -- -- nextext.sql -- -- To find tables that don't match the tablespace default for NEXT extent. -- The implicit rule here is that every table in a given tablespace should -- use the exact same value for NEXT, which should also be the tablespace's -- default value for NEXT. -- -- This tells us what the setting for NEXT is for these objects today. -- -- 11/30/98 SELECT segment_name, segment_type, ds.next_extent as Actual_Next , dt.tablespace_name, dt.next_extent as Default_Next FROM dba_tablespaces dt, dba_segments ds WHERE dt.tablespace_name = ds.tablespace_name AND dt.next_extent !=ds.next_extent AND ds.owner = UPPER ( '&OWNER' ) ORDER BY tablespace_name, segment_type, segment_name 2. existext.sql -- -- existext.sql -- -- To check existing extents -- -- This tells us how many of each object's extents differ in size from -- the tablespace's default size. If this report shows a lot of different -- sized extents, your free space is likely to become fragmented. If so, -- this tablespace is a candidate for reorganizing. -- -- 12/15/98 SELECT segment_name, segment_type , count(*) as nr_exts , sum ( DECODE ( dx.bytes,dt.next_extent,0,1) ) as nr_illsized_exts , dt.tablespace_name, dt.next_extent as dflt_ext_size FROM dba_tablespaces dt, dba_extents dx WHERE dt.tablespace_name = dx.tablespace_name AND dx.owner = '&OWNER' GROUP BY segment_name, segment_type, dt.tablespace_name, dt.next_extent 3. No_pk.sql -- -- no_pk.sql -- -- To find tables without PK constraint -- -- 11/2/98 SELECT table_name FROM all_tables WHERE owner = '&OWNER' MINUS SELECT table_name FROM all_constraints WHERE owner = '&&OWNER' AND constraint_type = 'P' 4. disPK.sql -- -- disPK.sql -- -- To find out which primary keys are disabled -- -- 11/30/98 SELECT owner, constraint_name, table_name, status FROM all_constraints WHERE owner = '&OWNER' AND status = 'DISABLED’ AND constraint_type = 'P' 5. nonuPK.sql -- -- nonuPK.sql -- -- To find tables with nonunique PK indexes. Requires that PK names -- follow a naming convention. An alternative query follows that -- does not have this requirement, but runs more slowly. -- -- 11/2/98 SELECT index_name, table_name, uniqueness FROM all_indexes WHERE index_name like '&PKNAME%' AND owner = '&OWNER' AND uniqueness = 'NONUNIQUE' SELECT c.constraint_name, i.tablespace_name, i.uniqueness FROM all_constraints c , all_indexes i WHERE c.owner = UPPER ( '&OWNER' ) AND i.uniqueness = 'NONUNIQUE' AND c.constraint_type = 'P' AND i.index_name = c.constraint_name 6. mkrebuild_idx.sql -- -- mkrebuild_idx.sql -- -- Rebuild indexes to have correct storage parameters -- -- 11/2/98 SELECT 'alter index ' || index_name || ' rebuild ' , 'tablespace INDEXES storage ' || ' ( initial 256 K next 256 K pctincrease 0 ) ; ' FROM all_indexes WHERE ( tablespace_name != 'INDEXES' OR next_extent != ( 256 * 1024 ) ) AND owner = '&OWNER' / 7. datatype.sql -- -- datatype.sql -- -- To check datatype consistency between two environments -- -- 11/30/98 SELECT table_name, column_name, data_type, data_length, data_precision, data_scale, nullable FROM all_tab_columns -- first environment WHERE owner = '&OWNER' MINUS SELECT table_name, column_name, data_type, data_length, data_precision, data_scale, nullable FROM all_tab_columns@&my_db_link -- second environment WHERE owner = '&OWNER2' order by table_name, column_name 8. obj_coord.sql -- -- obj_coord.sql -- -- To find out any difference in objects between two instances -- -- 12/08/98 SELECT object_name, object_type FROM user_objects MINUS SELECT object_name, object_type FROM user_objects@&my_db_link
|
|