愿你出走半生,归来仍是少年

Kratos
专注于用户阅读体验的响应式博客主题
  1. 首页
  2. Oracle
  3. 正文

[自制工具]批量后台更新统计信息

2021年12月15日 3337点热度 0人点赞 0条评论

有时需要批量收集数据库的统计信息,如在大量数据迁移或大量数据更新以后,但是收集的时间可能会较长,为了避免网络中断等意外情况可能引起的麻烦,今天调试了这个小脚本,可以分用户批量执行,同时记录执行时间等日志信息,比较实用。
执行方式:
sh /tmp/gather_schema_stats.sh syspasswd ip port service "schema1 schema2" degree&
详见以下代码:

cat > /tmp/gather_schema_stats.sh << EOF2
#!/bin/bash

# Usage:
# sh /tmp/gather_schema_stats.sh syspasswd ip port service "schema1 schema2" degree&

gather_schema_stats() {
date
sqlplus /nolog << EOF
connect sys/\$1@\$2:\$3/\$4 as sysdba
set timing on
exec dbms_stats.gather_schema_stats(ownname=>'\$5',options=>'GATHER AUTO',estimate_percent=>dbms_stats.auto_sample_size,method_opt=>'for all columns size auto',degree=>\$6,cascade=>TRUE);
exit
EOF
date
}

for SCHEMAS in \${5}
do
TIMESTAMP=\date "+%Y%m%d"\;LOG_FILE=/tmp/gather_schema_stats_\${TIMESTAMP}_\${SCHEMAS}.log
gather_schema_stats \${1} \${2} \${3} \${4} \${SCHEMAS} \$6 > \${LOG_FILE} 2>&1
done
EOF2

最后生成的脚本及日志如下所示:

ll /tmp
total 36
-rw-r----- 1 oracle oinstall  409 Dec 15 19:17 gather_schema_stats_20211215_CM.log
-rw-r----- 1 oracle oinstall  409 Dec 15 19:17 gather_schema_stats_20211215_CUSTCARE.log
-rw-r----- 1 oracle oinstall  409 Dec 15 19:18 gather_schema_stats_20211215_DW_TOTALCC.log
-rw-r----- 1 oracle oinstall  409 Dec 15 19:18 gather_schema_stats_20211215_OTHER_USER.log
-rw-r----- 1 oracle oinstall  409 Dec 15 19:18 gather_schema_stats_20211215_REPORT.log
-rw-r----- 1 oracle oinstall  409 Dec 15 19:18 gather_schema_stats_20211215_SXGIS.log
-rw-r----- 1 oracle oinstall  409 Dec 15 19:18 gather_schema_stats_20211215_TOTALCC_FC.log
-rw-r----- 1 oracle oinstall  600 Dec 15 19:17 gather_schema_stats.sh

值得注意的是,收集统计信息的各个参数配置,采用了最佳实践配置,可以放心参考使用。

标签: 暂无
最后更新:2021年12月15日

liking

这个人很懒,什么都没留下

点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

归档

  • 2026 年 6 月
  • 2026 年 3 月
  • 2026 年 2 月
  • 2025 年 12 月
  • 2025 年 11 月
  • 2025 年 4 月
  • 2025 年 2 月
  • 2025 年 1 月
  • 2024 年 12 月
  • 2024 年 10 月
  • 2024 年 7 月
  • 2024 年 5 月
  • 2024 年 4 月
  • 2023 年 11 月
  • 2023 年 10 月
  • 2023 年 8 月
  • 2023 年 7 月
  • 2023 年 5 月
  • 2023 年 3 月
  • 2023 年 2 月
  • 2022 年 12 月
  • 2022 年 11 月
  • 2022 年 10 月
  • 2022 年 9 月
  • 2022 年 8 月
  • 2022 年 6 月
  • 2022 年 5 月
  • 2022 年 3 月
  • 2022 年 2 月
  • 2022 年 1 月
  • 2021 年 12 月
  • 2021 年 11 月
  • 2021 年 10 月
  • 2021 年 8 月
  • 2021 年 7 月
  • 2021 年 6 月
  • 2021 年 5 月
  • 2021 年 4 月
  • 2021 年 3 月
  • 2021 年 2 月
  • 2021 年 1 月
  • 2020 年 12 月
  • 2020 年 11 月
  • 2020 年 10 月
  • 2020 年 9 月
  • 2020 年 8 月
  • 2020 年 7 月
  • 2020 年 6 月
  • 2020 年 5 月
  • 2020 年 3 月
  • 2020 年 2 月
  • 2019 年 12 月
  • 2019 年 11 月
  • 2019 年 10 月
  • 2019 年 9 月
  • 2019 年 8 月
  • 2019 年 7 月
  • 2019 年 6 月
  • 2019 年 5 月
  • 2019 年 4 月
  • 2019 年 2 月
  • 2018 年 12 月
  • 2018 年 11 月
  • 2018 年 8 月
  • 2018 年 7 月
  • 2018 年 6 月
  • 2018 年 5 月
  • 2018 年 4 月
  • 2018 年 3 月
  • 2018 年 2 月
  • 2018 年 1 月
  • 2017 年 12 月
  • 2017 年 11 月
  • 2017 年 8 月
  • 2017 年 6 月
  • 2017 年 5 月
  • 2017 年 3 月
  • 2016 年 9 月
  • 2016 年 8 月
  • 2016 年 7 月
  • 2016 年 6 月
  • 2016 年 5 月
  • 2015 年 10 月
  • 2014 年 10 月
  • 2014 年 8 月
  • 2014 年 3 月
  • 2013 年 12 月
  • 2013 年 8 月
  • 2013 年 7 月
  • 2013 年 6 月
  • 2013 年 4 月
  • 2012 年 11 月
  • 2012 年 7 月
  • 2012 年 6 月
  • 2012 年 5 月
  • 2012 年 2 月
  • 2011 年 10 月
  • 2011 年 8 月
  • 2011 年 3 月
  • 2010 年 11 月
  • 2010 年 10 月
  • 2010 年 9 月
  • 2010 年 8 月
  • 2010 年 7 月
  • 2010 年 5 月
  • 2010 年 4 月
  • 2010 年 1 月
  • 2009 年 11 月
  • 2009 年 8 月
  • 2009 年 5 月
  • 2009 年 3 月
  • 2009 年 2 月
  • 2008 年 11 月
  • 2008 年 10 月
  • 2008 年 8 月
  • 2008 年 4 月
  • 2007 年 4 月

分类

  • BigData
  • kubernetes
  • linux
  • MongoDB
  • MySQL
  • Oracle
  • PostgreSQL
  • 备份恢复
  • 安装配置
  • 性能优化
  • 技术杂谈
  • 未分类
  • 梦回红楼
  • 测试
  • 生活点滴
  • 网站建设
  • 自制工具
  • 轻松一刻
  • 运维知识
  • 问题处理

COPYRIGHT © 2026 愿你出走半生,归来仍是少年. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang