DBA日常工作.docx

上传人:b****1 文档编号:1353487 上传时间:2023-04-30 格式:DOCX 页数:12 大小:19.55KB
下载 相关 举报
DBA日常工作.docx_第1页
第1页 / 共12页
DBA日常工作.docx_第2页
第2页 / 共12页
DBA日常工作.docx_第3页
第3页 / 共12页
DBA日常工作.docx_第4页
第4页 / 共12页
DBA日常工作.docx_第5页
第5页 / 共12页
DBA日常工作.docx_第6页
第6页 / 共12页
DBA日常工作.docx_第7页
第7页 / 共12页
DBA日常工作.docx_第8页
第8页 / 共12页
DBA日常工作.docx_第9页
第9页 / 共12页
DBA日常工作.docx_第10页
第10页 / 共12页
DBA日常工作.docx_第11页
第11页 / 共12页
DBA日常工作.docx_第12页
第12页 / 共12页
亲,该文档总共12页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

DBA日常工作.docx

《DBA日常工作.docx》由会员分享,可在线阅读,更多相关《DBA日常工作.docx(12页珍藏版)》请在冰点文库上搜索。

DBA日常工作.docx

DBA日常工作

1.DBA行为规范

1.1.坚决不在服务器上直接执行RM操作

当有文件需要删除时,把这些文件MV到一个规定的文件夹,然后CD进入此文件夹再进行删除操作。

1.2.不直接在生产库上做没有经过反复测试成功的修改

任何一次数据库的修改都需要在测试库上通过反复测试并且成功。

由直接领导审批后,才能对生产库进行修改。

1.3.对ddl语句心存敬畏

DBA应该知道truncate/drop等ddl操作可能带来的影响,所以应该对这些ddl操作心存敬畏,甚至应该避免执行或避免草率执行这样的操作,最好养成在ddl清除数据之前备份的习惯。

通过一些良好习惯的养成,可以使得我们少犯错误。

 

2.DBA日常工作

2.1.每日工作

2.1.1.检查ORACLE后台进程

确认所有的INSTANCE状态正常登陆到所有数据库或例程,检测ORACLE后台进程:

  $ps–ef|grepora

  

2.1.2.检查文件系统的使用(剩余空间)。

如果文件系统的剩余空间小于20%,需删除不用的文件以释放空间。

  $df–k

2.1.3.实时监控数据库告警日志、TRC文件、监听日志文件

这是必须进行的工作,并且应该根据不同的严重级别,发送不同级别的告警,及时了解数据库的变化与告警。

2.1.3.1.清理数据库日志

确认不在需要的日志需要进行清理:

$ORACLE_BASE/admin//bdump/alert_.log:

echo>alert_.log

$ORACLE_HOME/network/log/listener.log:

echo>listener.log

$ORACLE_BASE/admin/udump/*.trc:

rm–rf*.trc

2.1.4.实时检查备份日志验证备份有效性

每日的数据库备份都在自动进行,但毕竟是按照脚本自动备份的,也有失败的时候。

所以需要每日检查数据库备份日志.

2.1.4.1.备份校验

rman>restoredatabasevalidate;

2.1.5.查看数据库连接信息

定时对数据库的连接情况进行检查,看与数据库建立的会话数目是不是正常,如果建立了过多的连接,会消耗数据库的资源。

同时,对一些“挂死”的连接,可能需要手工进行清理。

以下的SQL语句列出当前数据库建立的会话情况:

Selectcount(*)fromv$session;――查看当前会话连接数

selectsid,serial#,username,program,machine,statusfromv$session;

注意:

SID为1到10(USERNAME列为空)的会话,是Oracle的后台进程,不要对这些会话进行任何操作

2.1.6.并发会话量

并发会话量正常时段为60以下,查询系统在20以下,如果超过这些指标,则认为系统有阻塞情况,需要查找原因,引起关注。

查询系统并发的脚本为:

selectcount

(1)fromv$sessionwherestatus='ACTIVE'andusernamenotin('SYS','SYSTEM');

2.1.7.表空间使用情况

发现表空间使用量达到阀值时,需要添加数据文件来增大表空间容量

selecta.tablespace_name,round(a.total_size)"total_size(MB)",

round(a.total_size)-round(b.free_size,3)"used_size(MB)",

round(b.free_size,3)"free_size(MB)",

round(b.free_size/total_size*100,2)||'%'free_rate

from(selecttablespace_name,sum(bytes)/1024/1024total_sizefromdba_data_filesgroupbytablespace_name)a,

(selecttablespace_name,sum(bytes)/1024/1024free_sizefromdba_free_spacegroupbytablespace_name)b

wherea.tablespace_name=b.tablespace_name(+);

2.1.8.数据文件健康状况

当发现数据文件损坏时,需要立即修复

selectfile_name,statusfromdba_data_files;

或者

Selectfile#,status,namefromv$datafile_header;

2.1.9.查看缓冲区命中率

缓冲区命中率应该保证在95%以上。

Select1-(sum(decode(name,'physicalreads',value,0))/

(sum(decode(name,'dbblockgets',value,0))+

(sum(decode(name,'consistentgets',value,0)))))"BufferHiteRate"fromv$sysstat;

2.1.10.查看LIBRARYCACHE命中率

Selectround(sum(pins-reloads)/sum(pins)*100,4)"LibraryCacheHitRatio"fromv$librarycache;

2.1.11.检查数据库等待事件

如果数据库长时间持续出现大量像bufferbusywaits、dbfilescatteredread、dbfilesequentialread、enqueue、freebufferwaits、latchfree、logfilesync、logfileparallewrite

等等非空闲待事件时,需要对其进行分析,可能存在问题的语句。

selectsid,event,p1,p2,p3,WAIT_TIME,SECONDS_IN_WAITfromv$session_waitwhereeventnotlike'SQL%'andeventnotlike'rdbms%';

2.1.12.检查数据库锁表情况

colsidfor999999

colusernamefora10

colschemanamefora10

colosuserfora16

colmachinefora16

colterminalfora20

colownerfora10

colobject_namefora30

colobject_typefora10

selectsid,serial#,username,SCHEMANAME,osuser,MACHINE,

terminal,PROGRAM,owner,object_name,object_type,o.object_id

fromdba_objectso,v$locked_objectl,v$sessions

whereo.object_id=l.object_idands.sid=l.session_id;

解锁处理:

altersystemkillsession'&sid,&serial#';

2.1.13.检查数据库性能,CPU使用、IO、BUFFER命中等

使用vmstat,iostat,sar,top等命令进行信息收集并检查这些信息,判断资源使用情况。

2.1.14.查看是否有僵死进程

selectspidfromv$processwhereaddrnotin(selectpaddrfromv$session);

有些僵死进程有阻塞其他业务的正常运行,定期杀掉僵死进程

2.1.15.每天至少优化和熟悉一个TopSQL

根据AWR或Statspack报告,每天至少了解或熟悉一个TopSQL,能优化的要提出优化和调整建议

2.2.每周工作

2.2.1.监控数据量的增长情况

根据本周每天的检查情况找到空间扩展很快的数据库对象,并采取相应的措施

2.2.2.检查无效的数据库对象

SELECTowner,object_name,object_typeFROMdba_objectsWHEREstatus='INVALID';

2.2.2.1.重建失效的索引

alterindexindex_namerebuild;

2.2.3.检查不起作用的约束

SELECTowner,constraint_name,table_name,constraint_type,status

FROMdba_constraints

WHEREstatus='DISABLE'andconstraint_type='P';

2.2.4.检查无效的trigger

SELECTowner,trigger_name,table_name,statusFROMdba_triggersWHEREstatus='DISABLED';

2.2.5.检查数据库定时作业的完成情况

如果数据库使用了Oracle的JOB来完成一些定时作业,要对这些JOB的运行情况进行检查:

selectjob,log_user,last_date,failures

fromdba_jobs;

如果FAILURES列是一个大于0的数的话,说明JOB运行失败,要进一步的检查。

2.3.每月的工作

2.3.1.AnalyzeTables/Indexes/Cluster

  analyzetableestimatestatisticssample50percent;

2.3.2.检查表空间碎片

 根据本月每周的检查分析数据库碎片情况,找到相应的解决方法

2.3.3.寻找数据库性能调整的机会

使用statspack收集统计数据,比较每天对数据库性能的监控报告,确定是否有必要对数据库性能进行调整

2.4.其他操作

2.4.1.keep经常使用得对象

--保存触发器的触发信息

CREATETABLEshared_pool_keep

KEEPDATEDATE,--启动时间

ERRMSGVARCHAR2(500)--错误信息

/

CREATEORREPLACETRIGGERSYS.triKeepPorcafterstartupONDATABASE

/****************************

数据库启动时,把调用比较频繁的存储过程固定在sharepool里面。

*****************************/

DECLARE

v_errmsgvarchar(800);

BEGIN

SYS.DBMS_SHARED_POOL.KEEP('&频繁调入调出的过程','P');

INSERTINTOshared_pool_keep(keepdate,errmsg)

VALUES(SYSDATE,'');

EXCEPTIONWHENOTHERSTHEN

v_errmsg:

=substr(sqlerrm,1,200);

INSERTINTOshared_pool_keep(startupdate,execinfo,errmsg)

VALUES(sysdate,v_errmsg);

END;

/

--下面是PLSQL块,在数据库其上执行,或sharepool刷新时,执行

DECLARE

BEGIN

SYS.DBMS_SHARED_POOL.KEEP('&频繁调入调出的过程','P');

END;

altertabletest_defaultstorage(buffer_poolkeep);

2.4.2.重整表

--说明此操作发生时,会影响表的DML操作,考虑建议操作在系统维护期进行

declare

stpvarchar2(30):

='ts_1';

ifileinteger:

=10;

strvarchar2(200);

begin

forxin(selectdistinctOWNER,SEGMENT_NAME,PARTITION_NAME,SEGMENT_TYPE,TABLESPACE_NAME

fromsys.dba_extentswherefile_id=ifile

orderbysegment_typedesc,segment_name)loop

ifx.SEGMENT_TYPE='TABLE'then

str:

='ALTERTABLE'||x.owner||'.'||x.SEGMENT_name||'movetablespace'||stp||';';

elsifx.SEGMENT_TYPE='TABLEPARTITION'then

str:

='ALTERTABLE'||x.owner||'.'||x.SEGMENT_name||'movepartition'||x.PARTITION_NAME||'tablespace'||stp||';';

elsifx.SEGMENT_TYPE='TABLESUBPARTITION'then

str:

='ALTERTABLE'||x.owner||'.'||x.SEGMENT_name||'movesubpartition'||x.PARTITION_NAME||'tablespace'||stp||';';

elsifx.SEGMENT_TYPE='INDEX'then

str:

='ALTERINDEX'||x.owner||'.'||x.SEGMENT_name||'rebuildtablespace'||stp||';';

elsifx.SEGMENT_TYPE='INDEXPARTITION'then

str:

='ALTERINDEX'||x.owner||'.'||x.SEGMENT_name||'rebuildpartition'||x.PARTITION_NAME||'tablespace'||stp||';';

elsifx.SEGMENT_TYPE='INDEXSUBPARTITION'then

str:

='ALTERINDEX'||x.owner||'.'||x.SEGMENT_name||'rebuildsubpartition'||x.PARTITION_NAME||'tablespace'||stp||';';

elsifx.SEGMENT_TYPE='LOBPARTITION'then

begin

select'ALTERTABLE'||table_owner||'.'||table_name||'movepartition'||partition_name||'tablespace'||stp||'lob('||column_name||')storeas(tablespace'||stp||');'

intostr

fromdba_lob_partitions

wherelob_name=x.segment_nameandlob_partition_name=x.partition_name;

exception

whenno_data_foundthen

null;

end;

elsifx.SEGMENT_TYPE='LOBSEGMENT'then

begin

select'ALTERTABLE'||owner||'.'||table_name||'movetablespace'||stp||'lob('||column_name||')storeas(tablespace'||stp||');'

intostr

fromdba_lobs

wheresegment_name=x.segment_name;

exception

whenno_data_foundthen

null;

end;

/*elsifx.SEGMENT_TYPE='LOBINDEX'then

begin

select'ALTERTABLE'||owner||'.'||table_name||'movetablespace'||stp||'lob('||column_name||')storeas(tablespace'||stp||');'

intostr

fromdba_lobs

whereindex_name=x.segment_name;

exception

whenno_data_foundthen

null;

end;*/

endif;

dbms_output.put_line(str);

--insertintotest.clvalues(str);

endloop;

commit;

end;

2.4.3.重整索引

--说明此操作发生时,会影响表的DML操作,建议考虑操作在系统维护期进行

declare

stpvarchar2(30):

='TESTING_LYX_2';

ifileinteger:

=10;

strvarchar2(200);

tbs_namevarchar2(30):

='TESTING_LYX';

begin

forxin(selectOWNER,SEGMENT_NAME,PARTITION_NAME,SEGMENT_TYPE,TABLESPACE_NAME

fromsys.dba_segmentswheretablespace_name=tbs_name

orderbysegment_typedesc,segment_name)loop

ifx.SEGMENT_TYPE='TABLE'then

str:

='ALTERTABLE'||x.owner||'.'||x.SEGMENT_name||'movetablespace'||stp||';';

elsifx.SEGMENT_TYPE='TABLEPARTITION'then

str:

='ALTERTABLE'||x.owner||'.'||x.SEGMENT_name||'movepartition'||x.PARTITION_NAME||'tablespace'||stp||';';

elsifx.SEGMENT_TYPE='TABLESUBPARTITION'then

str:

='ALTERTABLE'||x.owner||'.'||x.SEGMENT_name||'movesubpartition'||x.PARTITION_NAME||'tablespace'||stp||';';

elsifx.SEGMENT_TYPE='INDEX'then

str:

='ALTERINDEX'||x.owner||'.'||x.SEGMENT_name||'rebuildtablespace'||stp||';';

elsifx.SEGMENT_TYPE='INDEXPARTITION'then

str:

='ALTERINDEX'||x.owner||'.'||x.SEGMENT_name||'rebuildpartition'||x.PARTITION_NAME||'tablespace'||stp||';';

elsifx.SEGMENT_TYPE='INDEXSUBPARTITION'then

str:

='ALTERINDEX'||x.owner||'.'||x.SEGMENT_name||'rebuildsubpartition'||x.PARTITION_NAME||'tablespace'||stp||';';

elsifx.SEGMENT_TYPE='LOBPARTITION'then

begin

select'ALTERTABLE'||table_owner||'.'||table_name||'movepartition'||partition_name||'tablespace'||stp||'lob('||column_name||')storeas(tablespace'||stp||');'

intostr

fromdba_lob_partitions

wherelob_name=x.segment_nameandlob_partition_name=x.partition_name;

exception

whenno_data_foundthen

null;

end;

elsifx.SEGMENT_TYPE='LOBSEGMENT'then

begin

select'ALTERTABLE'||owner||'.'||table_name||'movetablespace'||stp||'lob('||column_name||')storeas(tablespace'||stp||');'

intostr

fromdba_lobs

wheresegment_name=x.segment_name;

exception

whenno_data_foundthen

null;

end;

/*elsifx.SEGMENT_TYPE='LOBINDEX'then

begin

select'ALTERTABLE'||owner||'.'||table_name||'movetablespace'||stp||'lob('||column_name||')storeas(tablespace'||stp||');'

intostr

fromdba_lobs

whereindex_name=x.segment_name;

exception

whenno_data_foundthen

null;

end;*/

endif;

dbms_output.put_line(str);

--insertintotest.clvalues(str);

endloop;

commit;

end;

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 幼儿教育 > 幼儿读物

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2