RDBMS 19.20
参考文档:
Database Administrator’s Guide
19 Managing Space for Schema Objects
19.3.2.4 Running the Segment Advisor Manually
针对表SOE.CUSTOMERS进行段指导
-- 创建段指导
variable id number;
begin
declare
name varchar2(100);
descr varchar2(500);
obj_id number;
begin
name:='Manual_Employees';
descr:='Segment Advisor Example';
dbms_advisor.create_task (
advisor_name => 'Segment Advisor',
task_id => :id,
task_name => name,
task_desc => descr);
dbms_advisor.create_object (
task_name => name,
object_type => 'TABLE',
attr1 => 'SOE',
attr2 => 'CUSTOMERS',
attr3 => NULL,
attr4 => NULL,
attr5 => NULL,
object_id => obj_id);
dbms_advisor.set_task_parameter(
task_name => name,
parameter => 'recommend_all',
value => 'TRUE');
dbms_advisor.execute_task(name);
end;
end;
/
-- 查看段指导是否运行完毕
select task_name, status
from dba_advisor_tasks
where task_name = 'Manual_Employees'
and advisor_name = 'Segment Advisor';
-- 查看段指导对应的结果
select af.task_name, ao.attr2 segname, ao.attr3 partition, ao.type, af.message
from dba_advisor_findings af, dba_advisor_objects ao
where ao.task_id = af.task_id
and ao.object_id = af.object_id
and af.task_name = 'Manual_Employees'
select task_name,message,more_info from dba_advisor_findings where task_name = 'Manual_Employees'
--select * from DBA_ADVISOR_RECOMMENDATIONS where task_name = 'Manual_Employees'
--select * from DBA_ADVISOR_ACTIONS where task_name = 'Manual_Employees'
select task_name,command,attr1,attr2,attr3 from DBA_ADVISOR_ACTIONS where task_name like '%SYS_AUTO_SPCADV%'
select * from DBA_ADVISOR_OBJECTS where task_name = 'Manual_Employees'
-- 查看近期的段指导建议
select tablespace_name,
segment_name,
segment_type,
partition_name,
recommendations,
c1
from table(dbms_space.asa_recommendations('FALSE', 'FALSE', 'FALSE'));
--部分结果示例
SYS@test>select task_name,message,more_info from dba_advisor_findings where task_name = 'Manual_Employees'
2 ;
TASK_NAME
--------------------------------------------------------------------------------
MESSAGE
--------------------------------------------------------------------------------
MORE_INFO
--------------------------------------------------------------------------------
Manual_Employees
The free space in the object is less than 10MB.
Allocated Space:180355072: Used Space:178803055: Reclaimable Space :1552017:
SYS@test>
SYS@test>select task_name,command,attr1,attr2,attr3 from DBA_ADVISOR_ACTIONS where task_name like '%SYS_AUTO_SPCADV%';
TASK_NAME
--------------------------------------------------------------------------------
COMMAND
----------------------------------------------------------------
ATTR1
--------------------------------------------------------------------------------
ATTR2
--------------------------------------------------------------------------------
ATTR3
--------------------------------------------------------------------------------
SYS_AUTO_SPCADV126200902092023
SHRINK SPACE
alter table "OGG"."GGS_DDL_HIST" shrink space
TASK_NAME
--------------------------------------------------------------------------------
COMMAND
----------------------------------------------------------------
ATTR1
--------------------------------------------------------------------------------
ATTR2
--------------------------------------------------------------------------------
ATTR3
--------------------------------------------------------------------------------
alter table "OGG"."GGS_DDL_HIST" shrink space COMPACT
alter table "OGG"."GGS_DDL_HIST" enable row movement
TASK_NAME
--------------------------------------------------------------------------------
COMMAND
----------------------------------------------------------------
ATTR1
--------------------------------------------------------------------------------
ATTR2
--------------------------------------------------------------------------------
ATTR3
--------------------------------------------------------------------------------
SYS_AUTO_SPCADV126200902092023
ENABLE COMPRESSION
alter table "SOE"."ORDERS" compress for oltp
TASK_NAME
--------------------------------------------------------------------------------
COMMAND
----------------------------------------------------------------
ATTR1
--------------------------------------------------------------------------------
ATTR2
--------------------------------------------------------------------------------
ATTR3
--------------------------------------------------------------------------------
alter table "SOE"."ORDERS" move
TASK_NAME
--------------------------------------------------------------------------------
COMMAND
----------------------------------------------------------------
ATTR1
--------------------------------------------------------------------------------
ATTR2
--------------------------------------------------------------------------------
ATTR3
--------------------------------------------------------------------------------
SYS_AUTO_SPCADV126200902092023
ENABLE COMPRESSION
alter table "SOE"."CUSTOMERS" compress for oltp
TASK_NAME
--------------------------------------------------------------------------------
COMMAND
----------------------------------------------------------------
ATTR1
--------------------------------------------------------------------------------
ATTR2
--------------------------------------------------------------------------------
ATTR3
--------------------------------------------------------------------------------
alter table "SOE"."CUSTOMERS" move
TASK_NAME
--------------------------------------------------------------------------------
COMMAND
----------------------------------------------------------------
ATTR1
--------------------------------------------------------------------------------
ATTR2
--------------------------------------------------------------------------------
ATTR3
--------------------------------------------------------------------------------
SYS_AUTO_SPCADV126200902092023
ENABLE COMPRESSION
alter table "OGG"."GGS_DDL_HIST" compress for oltp
TASK_NAME
--------------------------------------------------------------------------------
COMMAND
----------------------------------------------------------------
ATTR1
--------------------------------------------------------------------------------
ATTR2
--------------------------------------------------------------------------------
ATTR3
--------------------------------------------------------------------------------
alter table "OGG"."GGS_DDL_HIST" move
TASK_NAME
--------------------------------------------------------------------------------
COMMAND
----------------------------------------------------------------
ATTR1
--------------------------------------------------------------------------------
ATTR2
--------------------------------------------------------------------------------
ATTR3
--------------------------------------------------------------------------------
SYS_AUTO_SPCADV258251302092023
SHRINK SPACE
alter table "OGG"."GGS_DDL_HIST" shrink space
TASK_NAME
--------------------------------------------------------------------------------
COMMAND
----------------------------------------------------------------
ATTR1
--------------------------------------------------------------------------------
ATTR2
--------------------------------------------------------------------------------
ATTR3
--------------------------------------------------------------------------------
alter table "OGG"."GGS_DDL_HIST" shrink space COMPACT
alter table "OGG"."GGS_DDL_HIST" enable row movement
TASK_NAME
--------------------------------------------------------------------------------
COMMAND
----------------------------------------------------------------
ATTR1
--------------------------------------------------------------------------------
ATTR2
--------------------------------------------------------------------------------
ATTR3
--------------------------------------------------------------------------------
SYS_AUTO_SPCADV616480909092023
SHRINK SPACE
alter table "OGG"."GGS_DDL_HIST" shrink space
TASK_NAME
--------------------------------------------------------------------------------
COMMAND
----------------------------------------------------------------
ATTR1
--------------------------------------------------------------------------------
ATTR2
--------------------------------------------------------------------------------
ATTR3
--------------------------------------------------------------------------------
alter table "OGG"."GGS_DDL_HIST" shrink space COMPACT
alter table "OGG"."GGS_DDL_HIST" enable row movement
TASK_NAME
--------------------------------------------------------------------------------
COMMAND
----------------------------------------------------------------
ATTR1
--------------------------------------------------------------------------------
ATTR2
--------------------------------------------------------------------------------
ATTR3
--------------------------------------------------------------------------------
SYS_AUTO_SPCADV705541309092023
SHRINK SPACE
alter table "OGG"."GGS_DDL_HIST" shrink space
TASK_NAME
--------------------------------------------------------------------------------
COMMAND
----------------------------------------------------------------
ATTR1
--------------------------------------------------------------------------------
ATTR2
--------------------------------------------------------------------------------
ATTR3
--------------------------------------------------------------------------------
alter table "OGG"."GGS_DDL_HIST" shrink space COMPACT
alter table "OGG"."GGS_DDL_HIST" enable row movement
TASK_NAME
--------------------------------------------------------------------------------
COMMAND
----------------------------------------------------------------
ATTR1
--------------------------------------------------------------------------------
ATTR2
--------------------------------------------------------------------------------
ATTR3
--------------------------------------------------------------------------------
SYS_AUTO_SPCADV705541309092023
ENABLE COMPRESSION
alter table "OGG"."GGS_DDL_HIST" compress for oltp
TASK_NAME
--------------------------------------------------------------------------------
COMMAND
----------------------------------------------------------------
ATTR1
--------------------------------------------------------------------------------
ATTR2
--------------------------------------------------------------------------------
ATTR3
--------------------------------------------------------------------------------
alter table "OGG"."GGS_DDL_HIST" move
8 rows selected.
SYS@test>
END