网站首页 > 技术文章 正文
概述
生产环境中,经常会遇到表由于数据不断插入,导致空间越来越大,由于前期配置问题,没有做分区或者其他优化,而且生产数据实时向表插入。要删除历史数据来释放空间。所以DBA一般都需要定期去对Oracle表碎片做整理,简单整理表碎片整理流程如下:
1、定位存在碎片的对象
使用如下脚本,检查需要进行碎片整理的对象:
--all tables(partition_tables + non_partition_tables ) select a.owner, a.table_name, a.num_rows, a.avg_row_len, round(a.avg_row_len * a.num_rows / 1024 / 1024, 2) real_bytes_MB, round(b.seg_bytes_mb, 2) seg_bytes_mb, decode(a.num_rows, 0, 100, (1 - round(a.avg_row_len * a.num_rows / 1024 / 1024 / b.seg_bytes_mb, 2)) * 100) || '%' frag_percent from dba_tables a, (select owner, segment_name, sum(bytes / 1024 / 1024) seg_bytes_mb from dba_segments group by owner, segment_name) b where a.table_name = b.segment_name and a.owner = b.owner and a.owner not in ('SYS', 'SYSTEM', 'OUTLN', 'DMSYS', 'TSMSYS', 'DBSNMP', 'WMSYS', 'EXFSYS', 'CTXSYS', 'XDB', 'OLAPSYS', 'ORDSYS', 'MDSYS', 'SYSMAN') and decode(a.num_rows, 0, 100, (1 - round(a.avg_row_len * a.num_rows / 1024 / 1024 / b.seg_bytes_mb, 2)) * 100) > 30 order by b.seg_bytes_mb desc;
2、统计信息检查
2.1 统计信息检查
查看统计信息收集日期,确保碎片查询结果准确:
select owner,table_name,last_analyzed from dba_tables Where owner='<OWNER>' AND table_name='<TABLE_NAME>';
2.2 统计信息收集
如果统计信息过旧,则重新收集统计信息:
exec dbms_stats.gather_table_stats(ownname=>'<OWNER>', tabname =>'<TABLE_NAME>');
3、表碎片整理
3.1 打开行移动
alter table <TABLE_NAME> enable row movement ;
3.2 进行表收缩
alter table <TABLE_NAME> shrink space cascade ;
3.3 失效对象编译
语句可能会造成引用表<TABLE_NAME>的对象(如存储过程、包、视图等)变为无效。
运行如下脚本,重新编译失效对象。
@?/rdbms/admin/utlrp.sql
4、对象收缩后的结果检查
运行如下脚本,确认对象空间是否已经完成收缩。
--all tables(partition_tables + non_partition_tables ) select a.owner, a.table_name, a.num_rows, a.avg_row_len, round(a.avg_row_len * a.num_rows / 1024 / 1024, 2) real_bytes_MB, round(b.seg_bytes_mb, 2) seg_bytes_mb, decode(a.num_rows, 0, 100, (1 - round(a.avg_row_len * a.num_rows / 1024 / 1024 / b.seg_bytes_mb, 2)) * 100) || '%' frag_percent from dba_tables a, (select owner, segment_name, sum(bytes / 1024 / 1024) seg_bytes_mb from dba_segments group by owner, segment_name) b where a.table_name = b.segment_name and a.owner = b.owner and a.owner not in ('SYS', 'SYSTEM', 'OUTLN', 'DMSYS', 'TSMSYS', 'DBSNMP', 'WMSYS', 'EXFSYS', 'CTXSYS', 'XDB', 'OLAPSYS', 'ORDSYS', 'MDSYS', 'SYSMAN') and decode(a.num_rows, 0, 100, (1 - round(a.avg_row_len * a.num_rows / 1024 / 1024 / b.seg_bytes_mb, 2)) * 100) > 30 order by b.seg_bytes_mb desc;
5、性能监控
监控数据库会话,是否存在异常等待事件:
select inst_id ,sid,serial#,sql_id,event,machine,module,program,seconds_in_wait from gv$session ; --看会话在做什么操作 select sid, sql_text from v$session a, v$sql b where sid in(85,160) and(b.sql_id = a.sql_id or b.sql_id = a.prev_sql_id);
篇幅有限,这一块就整理到这了,后面会分享更多devops和DBA方面的内容,感兴趣的朋友可以关注下~
猜你喜欢
- 2024-10-13 oracle中system、sysaux或者临时表空间占用过大一般是什么原因?
- 2024-10-13 oracle数据库定期备份与删除过期备份文件
- 2024-10-13 Oracle审计日志过大?如何清理及关闭审计机制?
- 2024-10-13 oracle下使用oci快速卸载数据文件,12c的1017问题
- 2024-10-13 详解Oracle 11g如何清理数据库的历史日志
- 2024-10-13 常用SQL系列之(六):删除方式、数据库、表及索引元信息查询等
- 2024-10-13 Oracle 分区表 范围分区、列表分区、HASH分区及组合分区
- 2024-10-13 记一次生产数据库SYSAUX表空间清理过程,值得收藏
- 2024-10-13 关于Oracle数据库12c 新特性总结 oracle数据库12c版本
- 2024-10-13 SQL中的DROP操作:撤销索引、表和数据库的利器
你 发表评论:
欢迎- 最近发表
-
- 前端流行框架Vue3教程:13. 组件传递数据_Props
- 前端必看!10 个 Vue3 救命技巧,解决你 90% 的开发难题?
- JAVA和JavaScript到底是什么关系?是亲戚吗?
- Java和js有什么区别?(java和javascript的区别和联系)
- 东方标准|Web和Java的区别,如何选择这两个专业
- 前端面试题-JS 中如何实现大对象深度对比
- 360前端一面~面试题解析(360前端笔试)
- 加班秃头别慌!1 道 Vue 面试题,快速解锁大厂 offer 通关密码
- 焦虑深夜刷题!5 道高频 React 面试题,吃透 offer 稳了
- 2025Web前端面试题大全(整理版)面试题附答案详解,最全面详细
- 标签列表
-
- 前端设计模式 (75)
- 前端性能优化 (51)
- 前端模板 (66)
- 前端跨域 (52)
- 前端md5加密 (49)
- 前端路由 (55)
- 前端数组 (65)
- 前端定时器 (47)
- 前端懒加载 (45)
- 前端接口 (46)
- Oracle RAC (73)
- oracle恢复 (76)
- oracle 删除表 (48)
- oracle 用户名 (74)
- oracle 工具 (55)
- oracle 内存 (50)
- oracle 导出表 (57)
- oracle查询数据库 (45)
- oracle约束 (46)
- oracle 中文 (51)
- oracle链接 (47)
- oracle的函数 (57)
- mac oracle (47)
- 前端调试 (52)
- 前端登录页面 (48)
本文暂时没有评论,来添加一个吧(●'◡'●)