首页 > 数据库技术 > 详细

db2 全库完整性检查和小工具记录

时间:2019-05-05 23:44:43      阅读:160      评论:0      收藏:0      [点我收藏+]
db2 "SELECT substr(TABNAME,1,30) as TAB_NAME, STATUS, ACCESS_MODE, substr(CONST_CHECKED,1,1) as FK_CHECKED,
substr(CONST_CHECKED,2,1) as CC_CHECKED
FROM SYSCAT.TABLES WHERE STATUS = ‘C‘"

如果回显中有结果,说明有表没有完成完整性检查。通常是因为有LOAD操作造成的。
这个时候用一个小工具就可以完成自动的检查:

setIdentify.sh

db2 connect to $1
db2 -tx +w "with gen(tabname, seq) as( select rtrim(tabschema) || ‘.‘ || rtrim(tabname)
as tabname, row_number() over (partition by status) as seq
from syscat.tables
WHERE status=‘C‘ ),r(a, seq1) as (select CAST(tabname as VARCHAR(3900)), seq
from gen where seq=1 union all select r.a || ‘,‘|| rtrim(gen.tabname), gen.seq
from gen , r where (r.seq1+1)=gen.seq ), r1 as (select a, seq1 from r)
select ‘SET INTEGRITY FOR ‘ || a || ‘ IMMEDIATE CHECKED;‘ from r1
where seq1=(select max(seq1) from r1)" > db2FixCheckPending.sql

db2 -tvf db2FixCheckPending.sql

db2 全库完整性检查和小工具记录

原文:https://blog.51cto.com/accole/2389514

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!