DB2收集统计信息脚本参考RUNSTATS ON

本文展示了如何使用DB2命令行工具生成并运行RUNSTATS命令,以更新指定数据库HIS中多个表的统计信息,确保数据库性能最优。通过示例说明了如何创建包含RUNSTATS命令的SQL脚本文件,并通过后台进程执行该脚本。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[db2inst1@localhost ~]$ db2level
DB21085I  Instance "db2inst1" uses "64" bits and DB2 code release "SQL09070" 
with level identifier "08010107".
Informational tokens are "DB2 v9.7.0.0", "s090521", "LINUXAMD6497", and Fix 
Pack "0".
Product is installed at "/opt/ibm/db2/V9.7".

[db2inst1@localhost ~]$ db2 connect to HIS

   Database Connection Information

 Database server        = DB2/LINUXX8664 9.7.0
 SQL authorization ID   = DB2INST1
 Local database alias   = HIS

[db2inst1@localhost ~]$ 
[db2inst1@localhost ~]$ db2 -x "select 'RUNSTATS ON TABLE '||RTRIM(Ltrim(TABLE_SCHEMA))||'.'||RTRIM(Ltrim(TABLE_NAME))||' with distribution and detailed indexes all' from SYSIBM.TABLES WHERE TABLE_SCHEMA='HIS' and TABLE_TYPE='BASE TABLE'" > t.sql
[db2inst1@localhost ~]$ more t.sql
RUNSTATS ON TABLE HIS.T with distribution and detailed indexes all                                         
                                                                                                           
                                                                                                        
RUNSTATS ON TABLE HIS.FUND_DAILY with distribution and detailed indexes all                                
                                                                                                           
                                                                                                        
RUNSTATS ON TABLE HIS.FUND_DAILY_INCOME with distribution and detailed indexes all                         
                                                                                                           
                                                                                                        
RUNSTATS ON TABLE HIS.T1 with distribution and detailed indexes all                                        
                                                                                                           
                                                                                                        
RUNSTATS ON TABLE HIS.T2 with distribution and detailed indexes all                                        
                                                                                                           
                                                                                                        
[db2inst1@localhost ~]$ pwd
/home/db2inst1
[db2inst1@localhost ~]$ nohup db2 -f /home/db2inst1/t.sql > ./runstat_t.log &
[1] 2259
[db2inst1@localhost ~]$ nohup: ignoring input and redirecting stderr to stdout

[db2inst1@localhost ~]$ 
[db2inst1@localhost ~]$ 
[1]+  Done                    nohup db2 -f /home/db2inst1/t.sql > ./runstat_t.log
[db2inst1@localhost ~]$ 

[db2inst1@localhost ~]$ tail -f runstat_t.log 
DB20000I  The RUNSTATS command completed successfully.

DB20000I  The RUNSTATS command completed successfully.

DB20000I  The RUNSTATS command completed successfully.

DB20000I  The RUNSTATS command completed successfully.

DB20000I  The RUNSTATS command completed successfully.

查看记录:

select tabname,card from syscat.tables where tabschema = 'HIS' and type='T'order by tabname asc;
select name,card from sysibm.systables where creator = 'HIS' and type='T' order by name asc;


相关参考:

 

http://blog.sina.com.cn/s/blog_4b8cae1a0102va4n.html

https://blog.csdn.net/jycjyc/article/details/100651282

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值