如何增加查询性能,降低高水位线,可用truncate(截断)
目的 提供一个产生脚本的工具,为的是降低高水位线
运行环境 sqlplus 和isqlplus
配置脚本
分两步第一是sql部分generator.sql,第二是脚本部分run.sql
你先要为truncate操作打一下基础
connect / as sysdba
alter system flush shared_pool;
你当然可以单独运行每个脚本,也可以修改合适您的脚本。
注:由于脚本有截断操作,其性质是破坏性的,应在运行前检查好,最好是一个测试环境。
需要权限为dba下面教你如何执行脚本
sqlplus "sys/<password> as sysdba" @generator.sql
sqlplus "sys/<password> as sysdba" @run.sql
注意:这个脚本是提供学习,而不是由oracle支持的服务,它被内部测试过,但是,我们不保证它一定适合您,所以一定要在修改成适合自己的脚本。
Generator.sql
connect / as sysdba
SET heading off
SET linesize 300
SET feedback off
set pages 4444
spool unscheduleremote.sql
select 'exec dbms_aqadm.unschedule_propagation('''||SCHEMA||'.'||QNAME||''','''||DESTINATION||''');' RunIt
from dba_queue_schedules
where SCHEMA||QNAME||DESTINATION in
(select SCHEMA||QNAME||DESTINATION from dba_queue_schedules where
SCHEMA ='&user' and DESTINATION !='AQ$_LOCAL');
spool off
set pages 4444
spool unschedulelocal.sql
select 'exec dbms_aqadm.unschedule_propagation('''||SCHEMA||'.'||QNAME||''');' RunIt
from dba_queue_schedules
where SCHEMA||QNAME in
(select SCHEMA||QNAME from dba_queue_schedules where
SCHEMA ='&user' and DESTINATION ='AQ$_LOCAL');
spool off
set pages 4444
spool scheduleremote.sql
select 'exec dbms_aqadm.schedule_propagation('''||SCHEMA||'.'||QNAME||''','''||DESTINATION||''');' RunIt
from dba_queue_schedules
where SCHEMA||QNAME||DESTINATION in
(select SCHEMA||QNAME||DESTINATION from dba_queue_schedules where
SCHEMA ='&user' and DESTINATION !='AQ$_LOCAL');
spool off
set pages 4444
spool schedulelocal.sql
select 'exec dbms_aqadm.schedule_propagation('''||SCHEMA||'.'||QNAME||''');' RunIt
from dba_queue_schedules
where SCHEMA||QNAME in
(select SCHEMA||QNAME from dba_queue_schedules where
SCHEMA ='&user' and DESTINATION ='AQ$_LOCAL');
spool off
spool stop.sql
select 'exec dbms_aqadm.stop_queue('''||OWNER||'.'||NAME||''');' RunIt
from dba_queues
where OWNER||NAME in
(select OWNER||OBJECT_NAME from dba_objects
where OBJECT_TYPE = 'QUEUE' and OWNER not in ('SYS','SYSTEM'));
spool off
set pages 4444
spool truncatesingle.sql
select 'truncate table '||OWNER||'.'||QUEUE_TABLE||';' RunIt
from dba_queue_tables
where OWNER||QUEUE_TABLE in
(select OWNER||OBJECT_NAME from dba_objects
where OBJECT_TYPE = 'TABLE'and OWNER not in ('SYS','SYSTEM')) and
RECIPIENTS='SINGLE';
spool off
set pages 4444
spool truncatemultiple81.sql
select 'truncate table '||OWNER||'.'||QUEUE_TABLE||';' RunIt
from dba_queue_tables
where OWNER||QUEUE_TABLE in
(select OWNER||OBJECT_NAME from dba_objects
where OBJECT_TYPE = 'TABLE'and OWNER not in ('SYS','SYSTEM')) and
RECIPIENTS='MULTIPLE' and COMPATIBLE='8.1.3';
select 'truncate table '||OWNER||'.AQ$_'||QUEUE_TABLE||'_I;' RunIt
from dba_queue_tables
where OWNER||QUEUE_TABLE in
(select OWNER||OBJECT_NAME from dba_objects
where OBJECT_TYPE = 'TABLE'and OWNER not in ('SYS','SYSTEM')) and
RECIPIENTS='MULTIPLE' and COMPATIBLE='8.1.3';
select 'truncate table '||OWNER||'.AQ$_'||QUEUE_TABLE||'_T;' RunIt
from dba_queue_tables
where OWNER||QUEUE_TABLE in
(select OWNER||OBJECT_NAME from dba_objects
where OBJECT_TYPE = 'TABLE'and OWNER not in ('SYS','SYSTEM')) and
RECIPIENTS='MULTIPLE' and COMPATIBLE='8.1.3';
select 'truncate table '||OWNER||'.AQ$_'||QUEUE_TABLE||'_H;' RunIt
from dba_queue_tables
where OWNER||QUEUE_TABLE in
(select OWNER||OBJECT_NAME from dba_objects
where OBJECT_TYPE = 'TABLE'and OWNER not in ('SYS','SYSTEM')) and
RECIPIENTS='MULTIPLE' and COMPATIBLE='8.1.3';
spool off
set pages 4444
spool truncatemultiple80.sql
select 'truncate table '||OWNER||'.'||QUEUE_TABLE||';' RunIt
from dba_queue_tables
where OWNER||QUEUE_TABLE in
(select OWNER||OBJECT_NAME from dba_objects
where OBJECT_TYPE = 'TABLE'and OWNER not in ('SYS','SYSTEM')) and
RECIPIENTS='MULTIPLE' and COMPATIBLE='8.0.3';
select 'truncate table '||OWNER||'.AQ$_'||QUEUE_TABLE||'_I;' RunIt
from dba_queue_tables
where OWNER||QUEUE_TABLE in
(select OWNER||OBJECT_NAME from dba_objects
where OBJECT_TYPE = 'TABLE'and OWNER not in ('SYS','SYSTEM')) and
RECIPIENTS='MULTIPLE' and COMPATIBLE='8.0.3';
spool off
set pages 4444
spool startnormal.sql
select 'exec dbms_aqadm.start_queue('''||OWNER||'.'||NAME||''');' RunIt
from dba_queues
where OWNER||NAME in
(select OWNER||OBJECT_NAME from dba_objects
where OBJECT_TYPE = 'QUEUE'and OWNER not in ('SYS','SYSTEM')) and
QUEUE_TYPE='NORMAL_QUEUE';
spool off
set pages 4444
spool startexception.sql
select 'exec dbms_aqadm.start_queue('''||OWNER||'.'||NAME||''', FALSE);' RunIt
from dba_queues
where OWNER||NAME in
(select OWNER||OBJECT_NAME from dba_objects
where OBJECT_TYPE = 'QUEUE'and OWNER not in ('SYS','SYSTEM')) and
QUEUE_TYPE='EXCEPTION_QUEUE';
spool off
set pages 4444
spool startnonpersistent.sql
select 'exec dbms_aqadm.start_queue('''||OWNER||'.'||NAME||''', FALSE);' RunIt
from dba_queues
where OWNER||NAME in
(select OWNER||OBJECT_NAME from dba_objects
where OBJECT_TYPE = 'QUEUE'and OWNER not in ('SYS','SYSTEM')) and
QUEUE_TYPE='NON_PERSISTENT_QUEUE';
spool off
quit