autotrace是sql*plus中的一种工具,显示所执行查询的解释计划(explain plan)及用户资源
我的环境是os:win7旗舰版;oracle:10.2.0.1
一、配置方法:
1、cd E:\oracle\product\10.2.0\db_1\RDBMS\ADMIN--在这个路径下执行第三部的脚本
2、sqlplusw /nolog
SQL>conn /as sysdba --以system登录,来做这件事情
3、执行@utlxplan,这个脚本是干啥用的呢?其实,就是存放生成执行计划需要的数据
create table PLAN_TABLE (
statement_id varchar2(30),
plan_id number,
timestamp date,
remarks varchar2(4000),
operation varchar2(30),
options varchar2(255),
object_node varchar2(128),
object_owner varchar2(30),
object_name varchar2(30),
object_alias varchar2(65),
object_instance numeric,
object_type varchar2(30),
optimizer varchar2(255),
search_columns number,
id numeric,
parent_id numeric,
depth numeric,
position numeric,
cost numeric,
cardinality numeric,
bytes numeric,
other_tag varchar2(255),
partition_start varchar2(255),
partition_stop varchar2(255),
partition_id numeric,
other long,
distribution varchar2(30),
cpu_cost numeric,
io_cost numeric,
temp_space numeric,
access_predicates varchar2(4000),
filter_predicates varchar2(4000),
projection varchar2(4000),
time numeric,
qblock_name varchar2(30),
other_xml clob
);
4、那就是赋权限,不过要符合oracle的一贯的行事规则,先建个synonym,然后再赋权
(1):grant public synonym plan_table for plan_table;
(2):grant all on plan_table to public;
5、如果想要在每个模式(schema)中使用,那就得这样
在E:\oracle\product\10.2.0\db_1\sqlplus\admin下找到plustrce.sql脚本
按照上面的步骤执行之;该脚本的内容:
set echo on
drop role plustrace;
create role plustrace;
grant select on v_$sesstat to plustrace;
grant select on v_$statname to plustrace;
grant select on v_$mystat to plustrace;
grant plustrace to dba with admin option;
set echo off
如果把权限赋给所有用户,则:
grant plustrace to public;,也可把public替换为某个用户
二、使用autotrace
那就是设置几个系统变量即可控制了
1、set autotrace on/off(default)----开关
2、set autotrace on explain ----只显示优化器执行路径
3、set autotrace on statistics ----只显示sql语句的执行统计信息
4、set autotrace on autotrace ----包含了2、3的信息
5、set autotrace on traceonly ----与on的显示信息类似,就少了执行sql的结果集
就是这样的:
SQL> set autot
用法: SET AUTOT[RACE] {OFF | ON | TRACE[ONLY]} [EXP[LAIN]] [STAT[ISTICS]]
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/9333283/viewspace-700165/
,如需转载,请注明出处,否则将追究法律责任。