通过段调优顾问回收大表的分配空间和高水位线

--通过段调优顾问回收大表的分配空间和高水位线
--创建用户
SQL> create tablespace hzqtbs datafile ‘/u01/app/oracle/oradata/prod/hzqtbs.dbf‘ size 30m;

Tablespace created.

SQL> create user hzq identified by hzq default tablespace hzqtbs quota unlimited on hzqtbs account unlock;

User created.

SQL> grant create session to hzq;

Grant succeeded.

SQL> grant resource to hzq;

Grant succeeded.

SQL> conn hzq/hzq
Connected.

create table test (id number,name varchar2(20));
begin
for i in  1..1000000 loop
insert into test values(i,‘user‘||i);
commit;
end loop;
end;
/

delete test;
insert into test values(1,‘user1‘);

--查看有多少调优顾问类型
select * from DBA_ADVISOR_DEFINITIONS;

ADVISOR_ID ADVISOR_NAME             PROPERTY
---------- ------------------------------ ----------
     1 ADDM                    1
     2 SQL Access Advisor             271
     3 Undo Advisor                1
     4 SQL Tuning Advisor             935
     5 Segment Advisor              67
     6 SQL Workload Manager            0
     7 Tune MView                  31
     8 SQL Performance Analyzer         935
     9 SQL Repair Advisor             679
    10 Compression Advisor               3

--查看段调优顾问作业是否工作
select
segments_processed
,end_time
from dba_auto_segadv_summary
order by end_time;

--手动生成段顾问建议

DECLARE
my_task_id number;
obj_id number;
my_task_name varchar2(100);
my_task_desc varchar2(500);
BEGIN
my_task_name := ‘MYTEST Advice‘;
my_task_desc := ‘Manual Segment Advisor Run‘;
---------
-- Step 1 create a task
---------
dbms_advisor.create_task (
advisor_name => ‘Segment Advisor‘,
task_id => my_task_id,
task_name => my_task_name,
task_desc => my_task_desc);
---------
-- Step 2 create a object
---------
dbms_advisor.create_object (
task_name => my_task_name,
object_type => ‘TABLE‘,
attr1 => ‘HZQ‘,
attr2 => ‘TEST‘,
attr3 => NULL,
attr4 => NULL,
attr5 => NULL,
object_id => obj_id);
---------
-- Step 3
---------
dbms_advisor.set_task_parameter(
task_name => my_task_name,
parameter => ‘recommend_all‘,
value => ‘TRUE‘);
---------
-- Step 4
---------
dbms_advisor.execute_task(my_task_name);
END;
/

--查看昨天到今天运行的调优顾问(11G)
select
‘Task Name : ‘ || f.task_name || chr(10) ||
‘Start Run Time : ‘ || TO_CHAR(execution_start, ‘dd-mon-yy hh24:mi‘) || chr (10) ||
‘Segment Name : ‘ || o.attr2 || chr(10) ||
‘Segment Type : ‘ || o.type || chr(10) ||
‘Partition Name : ‘ || o.attr3 || chr(10) ||
‘Message : ‘ || f.message || chr(10) ||
‘More Info : ‘ || f.more_info || chr(10) ||
‘------------------------------------------------------‘ Advice
FROM dba_advisor_findings f
,dba_advisor_objects o
,dba_advisor_executions e
WHERE o.task_id = f.task_id
AND o.object_id = f.object_id
AND f.task_id = e.task_id
AND e. execution_start > sysdate - 1
AND e.advisor_name = ‘Segment Advisor‘
ORDER BY f.task_name;

--查看表是否有回收空间
SELECT
‘Segment Advice --------------------------‘|| chr(10) ||
‘TABLESPACE_NAME : ‘ || tablespace_name || chr(10) ||
‘SEGMENT_OWNER : ‘ || segment_owner || chr(10) ||
‘SEGMENT_NAME : ‘ || segment_name || chr(10) ||
‘ALLOCATED_SPACE : ‘ || allocated_space || chr(10) ||
‘RECLAIMABLE_SPACE: ‘ || reclaimable_space || chr(10) ||
‘RECOMMENDATIONS : ‘ || recommendations || chr(10) ||
‘SOLUTION 1 : ‘ || c1 || chr(10) ||
‘SOLUTION 2 : ‘ || c2 || chr(10) ||
‘SOLUTION 3 : ‘ || c3 Advice
FROM
TABLE(dbms_space.asa_recommendations(‘FALSE‘, ‘FALSE‘, ‘FALSE‘));

--查看MYTEST Advice段调优顾问的建议,看是否有回收空间
SELECT
‘Task Name : ‘ || f.task_name || chr(10) ||
‘Segment Name : ‘ || o.attr2 || chr(10) ||
‘Segment Type : ‘ || o.type || chr(10) ||
‘Partition Name : ‘ || o.attr3 || chr(10) ||
‘Message : ‘ || f.message || chr(10) ||
‘More Info : ‘ || f.more_info TASK_ADVICE
FROM dba_advisor_findings f
,dba_advisor_objects o
WHERE o.task_id = f.task_id
AND o.object_id = f.object_id
AND f.task_name like ‘MYTEST Advice‘
ORDER BY f.task_name;

Task Name : MYTEST Advice
Segment Name : TEST
Segment Type : TABLE
Partition Name :
Message : Enable row movement of the table HZQ.TEST and perform shrink, estimate
d savings is 19416317 bytes.
More Info : Allocated Space:24117248: Used Space:4700931: Reclaimable Space :19416317:

--回收表空间
alter table test enable row movement; --开启行迁移功能。
alter table test shrink space compact;--(可以在压缩期间进行DML操作和查询) ,收缩表,不会降低hwm
alter table test shrink space; --( 调整HWM时将阻塞DML操作),收缩表,并且降低hwm
alter table test_idx shrink space cascade;--收缩表并降低hwm,并且回收相应的索引。

--删除,重新收集手动运行顾问
DECLARE
BEGIN
dbms_advisor.delete_task (
task_name => ‘MYTEST Advice‘
);
END;
/

DECLARE
my_task_id number;
obj_id number;
my_task_name varchar2(100);
my_task_desc varchar2(500);
BEGIN
my_task_name := ‘MYTEST Advice‘;
my_task_desc := ‘Manual Segment Advisor Run‘;
---------
-- Step 1 create a task
---------
dbms_advisor.create_task (
advisor_name => ‘Segment Advisor‘,
task_id => my_task_id,
task_name => my_task_name,
task_desc => my_task_desc);
---------
-- Step 2 create a object
---------
dbms_advisor.create_object (
task_name => my_task_name,
object_type => ‘TABLE‘,
attr1 => ‘HZQ‘,
attr2 => ‘TEST‘,
attr3 => NULL,
attr4 => NULL,
attr5 => NULL,
object_id => obj_id);
---------
-- Step 3
---------
dbms_advisor.set_task_parameter(
task_name => my_task_name,
parameter => ‘recommend_all‘,
value => ‘TRUE‘);
---------
-- Step 4
---------
dbms_advisor.execute_task(my_task_name);
END;
/

--查看昨天到今天运行的调优顾问(11G)
select
‘Task Name : ‘ || f.task_name || chr(10) ||
‘Start Run Time : ‘ || TO_CHAR(execution_start, ‘dd-mon-yy hh24:mi‘) || chr (10) ||
‘Segment Name : ‘ || o.attr2 || chr(10) ||
‘Segment Type : ‘ || o.type || chr(10) ||
‘Partition Name : ‘ || o.attr3 || chr(10) ||
‘Message : ‘ || f.message || chr(10) ||
‘More Info : ‘ || f.more_info || chr(10) ||
‘------------------------------------------------------‘ Advice
FROM dba_advisor_findings f
,dba_advisor_objects o
,dba_advisor_executions e
WHERE o.task_id = f.task_id
AND o.object_id = f.object_id
AND f.task_id = e.task_id
AND e. execution_start > sysdate - 1
AND e.advisor_name = ‘Segment Advisor‘
ORDER BY f.task_name;

--查看表是否有回收空间
SELECT
‘Segment Advice --------------------------‘|| chr(10) ||
‘TABLESPACE_NAME : ‘ || tablespace_name || chr(10) ||
‘SEGMENT_OWNER : ‘ || segment_owner || chr(10) ||
‘SEGMENT_NAME : ‘ || segment_name || chr(10) ||
‘ALLOCATED_SPACE : ‘ || allocated_space || chr(10) ||
‘RECLAIMABLE_SPACE: ‘ || reclaimable_space || chr(10) ||
‘RECOMMENDATIONS : ‘ || recommendations || chr(10) ||
‘SOLUTION 1 : ‘ || c1 || chr(10) ||
‘SOLUTION 2 : ‘ || c2 || chr(10) ||
‘SOLUTION 3 : ‘ || c3 Advice
FROM
TABLE(dbms_space.asa_recommendations(‘FALSE‘, ‘FALSE‘, ‘FALSE‘));

--再次通过段调优顾问查看可回收空间
 SELECT
‘Task Name : ‘ || f.task_name || chr(10) ||
‘Segment Name : ‘ || o.attr2 || chr(10) ||
‘Segment Type : ‘ || o.type || chr(10) ||
‘Partition Name : ‘ || o.attr3 || chr(10) ||
‘Message : ‘ || f.message || chr(10) ||
‘More Info : ‘ || f.more_info TASK_ADVICE
FROM dba_advisor_findings f
,dba_advisor_objects o
WHERE o.task_id = f.task_id
AND o.object_id = f.object_id
AND f.task_name like ‘MYTEST Advice‘
ORDER BY f.task_name;  

TASK_ADVICE
--------------------------------------------------------------------------------
Task Name : MYTEST Advice
Segment Name : TEST
Segment Type : TABLE
Partition Name :
Message : The free space in the object is less than 10MB.
More Info : Allocated Space:65536: Used Space:1824: Reclaimable Space :63712:
时间: 2024-09-30 18:45:35

通过段调优顾问回收大表的分配空间和高水位线的相关文章

通过段调优顾问帮助解决行链接问题

--解决行链接问题 SQL> create tablespace hzqtbs datafile '/u01/app/oracle/oradata/prod/hzqtbs.dbf' size 600m; Tablespace created. SQL> create user hzq identified by hzq default tablespace hzqtbs quota unlimited on hzqtbs account unlock; User created. SQL>

Android性能调优篇之探索JVM内存分配

详细内容请查看我的简书地址:Android性能调优篇之探索JVM内存分配 或者我的个人博客地址:Android性能调优篇之探索JVM内存分配

性能调优7:多表连接 - join

在产品环境中,往往存在着大量的表连接情景,不管是inner join.outer join.cross join和full join(逻辑连接符号),在内部都会转化为物理连接(Physical Join),SQL Server共有三种物理连接:Nested Loop(嵌套循环),Merge Join(合并连接)和Hash Join(哈希连接).这三个物理连接的处理方式不同,分别应用在不同的场景中. 在同一时刻,表连接只能是两表(或者是数据集,也就是表的一部分)之间的连接,通常按照表处于Join操

android性能测试与调优:使用 DDMS 查看内存分配情况

1. 启用自己的APK后 2. 点击左边更新heap 3. 点击右边的heap中的垃圾回收cause GC,等待数秒出现回收内存与数据情况(由于内存回收了APK运行出现异常crash) 4. 点击一个数据类型,出现柱状图分析

【oracle11g,13】表空间管理2:undo表空间管理(调优) ,闪回原理

一.undo空间原理: dml操作会产生undo数据. update时,sever process 会在databuffer 中找到该记录的buffer块,没有就从datafile中找并读入data buffer.在修改之前,原始数据先放到undo段,并在数据块头记录undo段(acitve 状态)中该数据块的位置,读写这个块时会占用事务槽,会将该事务号记录在数据块的头部.然后在进行update,并将该块放到dirty list检查点队列,等待dbwr进行写操作. 二.创建新的undo表空间替换

Java GC 专家系列3:GC调优实践

本篇是”GC专家系列“的第三篇.在第一篇理解Java垃圾回收中我们学习了几种不同的GC算法的处理过程,GC的工作方式,新生代与老年代的区别.所以,你应该已经了解了JDK 7中的5种GC类型,以及每种GC对性能的影响. 在第二篇Java垃圾回收的监控中介绍了在真实场景中JVM是如何运行GC,如何监控GC数据以及有哪些工具可用来方便进行GC监控. 在本篇中,我将基于真实的案例来介绍一些GC调优的最佳选项.写本篇文章时,我假设你已经理解了前两篇的内容.为了深入理解本部分内容,你最好先浏览一下前两篇的内

linux内存基础知识和相关调优方案

内存是计算机中重要的部件之一,它是与CPU进行沟通的桥梁.计算机中所有程序的运行都是在内存中进行的,因此内存的性能对计算机的影响非常大.内存作用是用于暂时存放CPU中的运算数据,以及与硬盘等外部存储器交换的数据.只要计算机在运行中,CPU就会把需要运算的数据调到内存中进行运算,当运算完成后CPU再将结果传送出来,内存的运行也决定了计算机的稳定运行.对于整个操作系统来说,内存可能是最麻烦的的设备.而其性能的好坏直接影响着整个操作系统. 我们知道CPU是不能与硬盘打交道的,只有数据被载入到内存中才可

调优过程

性能调优 1 百胜表规范 USE ERP_DW GO /* 功能说明: 创建[区域]维度表 修改说明: Create by LY on 2011-09-07 */ IF EXISTS (SELECT 1 FROM SYSOBJECTS WHERE id = OBJECT_ID('Dim_Area') AND type = 'U') BEGIN DROP TABLE Dim_Area END GO CREATE TABLE [dbo].[Dim_Area] ( AreaCode VARCHAR(2

JVM性能调优

一.JVM性能调优策略 二.性能调优 1.Java线程池(java.util.concurrent.ThreadPoolExecutor) 大多数JVM6上的应用采用的线程池都是JDK自带的线程池,之所以把成熟的Java线程池进行罗嗦说明,是因为该线程池的行为与我们想象的有点出入.Java线程池有几个重要的配置参数: corePoolSize:核心线程数(最新线程数) maximumPoolSize:最大线程数,超过这个数量的任务会被拒绝,用户可以通过RejectedExecutionHandl