AUTOTRACE是一个SQL*Plus工具,用于跟踪SQL的执行计划,收集执行时所耗用资源的统计信息,是SQL优化工具之一,下面给出启用AUTOTRACE 功能步骤。
一、创建基础表
运行$ORACLE_HOME/rdbms/admin/utlxplan脚本来创建plan_table
scott@ORCL> conn system/redhat --使用system帐户登陆 Connected. system@ORCL> start $ORACLE_HOME/rdbms/admin/utlxplan --执行utlxplan脚本 Table created. system@ORCL> create public synonym plan_table for plan_table; --为表plan_table创建公共同义词 Synonym created. system@ORCL> grant all on plan_table to public; --将同义词表plan_table授予给所有用户 Grant succeeded. |
二、创建角色
运行$ORACLE_HOME/sqlplus/admin/plustrce.sql脚本
system@ORCL> conn / as sysdba --使用sysdba帐户登陆 sys@ORCL> start $ORACLE_HOME/sqlplus/admin/plustrce.sql --执行创建角色的脚本 sys@ORCL> create role plustrace; Role created. sys@ORCL> Grant succeeded. sys@ORCL> grant select on v_$statname to plustrace; Grant succeeded. sys@ORCL> grant select on v_$mystat to plustrace; Grant succeeded. sys@ORCL> grant plustrace to dba with admin option; Grant succeeded. |
三、角色的授予
在创建角色后,DBA首先被授予了该角色,且可以将角色授予其它组和用户。可以手工把plustrace授予给public,
则该数据库内所有的用户都将拥有plustrace角色的权限。也可以单独授予给某个组和用户
授予给所有用户
sys@ORCL> grant plustrace to public; |
授予给单独用户
sys@ORCL> grant plustrace to scott; |
完成上述设置之后即可使用autotrace 功能