Oracle DBA日常管理目的:这篇文档有很详细的资料记录着对一个甚至更多的ORACLE数据库每天的,每月的,每年的运行的状态的结果及检查的结果,在文档的附录中你将会看到所有检查,修改的SQL和PL/SQL代码。目录1.日常维护程序A.检查已起的所有实例B.查找一些新的警告日志C.检查DBSNMP是否在运行D.检查数据库备份是否正确E.检查备份到磁带中的文件是否正确F.检查数据库的性能是否正常合理,是否有足够的空间和资源G.将文档日志复制到备份的数据库中H.要常看DBA用户手册2.晚间维护程序A.收集VOLUMETRIC的数据3.每周维护工作A.查找那些破坏规则的OBJECT
B.查找是否有违反安全策略的问题C.查看错误地方的SQL*NET日志D.将所有的警告日志存档E.经常访问供应商的主页4.月维护程序A.查看对数据库会产生危害的增长速度B.回顾以前数据库优化性能的调整C.查看I/O的屏颈问题D.回顾FRAGMENTATION
E.将来的执行计划F.查看调整点和维护5.附录A.月维护过程B.晚间维护过程C.周维护过程6.参考文献----------------------------------------------------------------一.日维护过程A.查看所有的实例是否已起确定数据库是可用的,把每个实例写入日志并且运行日报告或是运行测试文件。当然有一些操作我们是希望它能自动运行的。可选择执行:用ORACLE管理器中的‘PROBE’事件来查看B.查找新的警告日志文件1.联接每一个操作管理系统2.使用‘TELNET’或是可比较程序3.对每一个管理实例,经常的执行$ORACLE_BASE//bdump操作,并使其能回退到控制数据库的SID。4.在提示下,使用UNIX中的‘TAIL’命令查看alert_.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:\web\phase2\default.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供应商四.月维护过程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:
-- = 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_blocksFROM
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
-- 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 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六.参考文献1. Loney, Kevin Oracle8 DBA Handbook
2. Cook, David Database Management from Crisis to Confidence
[http://www.orapub.com/]
3. Cox, Thomas B. The Database Administration Maturity Model