当前所在位置:珠峰网资料 >> 计算机 >> Oracle认证 >> 正文
配置10g中SQL*Plus的autotrace
发布时间:2011/1/26 16:19:34 来源:www.xue.net 编辑:城市总裁吧

  AUTOTRACE 是SQL*Plus 中一个工具,可以显示所执行查询的解释计划(explain plan)以及所用的资源。这本书中大量使用了AUTOTRACE 工具。

  配置AUTOTRACE 的方法不止一种,以下是我采用的方法:

  1、

  (1)cd [ORACLE_HOME]/sqlplus/admin;

  (2)作为SYS 或SYSDBA 登录SQL*Plus;

  (3)运行@/plustrce.sql;

  (4)运行GRANT PLUSTRACE TO PUBLIC。

  Examw提示: 可以把GRANT TO PUBLIC 中的PUBLIC 替换为某个用户。

  通过将PLAN_TABLE置为public,任何人都可以使用SQL*Plus 进行跟踪。这么一来,就不需要每个用户都安装自己的计划表。

  2、还有一种做法是,在想要使用AUTOTRACE 的每个模式中分别运行@utlxplan。

  下一步是创建并授予PLUSTRACE 角色:

  (1)cd [ORACLE_HOME]/rdbms/admin

  (2)作为SYS 登录SQL*Plus;

  (3)运行@utlxplan.sql;

  (4)运行CREATE PUBLIC SYNONYM PLAN_TABLE FOR PLAN_TABLE;

  (5)运行GRANT ALL ON PLAN_TABLE TO PUBLIC。

  重申一遍,如果愿意,可以把GRANT 命令中PUBLIC 替换为每个用户。

  附实例:

  想在scott下使用autotrace

  SQL> set autotrace on;

  SP2-0618: Cannot find the Session Identifier. Check PLUSTRACE role is enabled

  SP2-0611: Error enabling STATISTICS report

  SQL> @/u01/app/oracle/product/10.2.0/db_1/sqlplus/admin/plustrce.sql

  SQL>

  SQL> drop role plustrace;

  Role dropped.

  SQL> create role plustrace;

  Role created.

  SQL>

  SQL> grant select on v_$sesstat to plustrace;

  Grant succeeded.

  SQL> grant select on v_$statname to plustrace;

  Grant succeeded.

  SQL> grant select on v_$mystat to plustrace;

  Grant succeeded.

  SQL> grant plustrace to dba with admin option;

  Grant succeeded.

  SQL>

  SQL> set echo off

  SQL>

  SQL>

  SQL>

  SQL> grant plustrace to scott;

  Grant succeeded.

  再次设置

  [oracle@oracle admin]$ sqlplus scott/tiger

  SQL*Plus: Release 10.2.0.1.0 - Production on Wed Sep 24 14:22:40 2008

  Copyright (c) 1982, 2005, Oracle. All rights reserved.

  Connected to:

  Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production

  With the Partitioning, OLAP and Data Mining options

  SQL> set autotrace on;

  SQL> set autotrace traceonly;

  SQL> set timing on;

广告合作:400-664-0084 全国热线:400-664-0084
Copyright 2010 - 2017 www.my8848.com 珠峰网 粤ICP备15066211号
珠峰网 版权所有 All Rights Reserved