普通用户开启AUTOTRACE 功能
2024-08-24 02:37:44
AUTOTRACE是一个SQL*Plus工具,用于跟踪SQL的执行计划,收集执行时所耗用资源的统计信息。系统账户本身具有AUTOTRACE,其他账户需要通过手动赋予
一. 用系统账户登录(DBA)
SQL> set autotrace traceonly
SQL> select * from hr.jobs; 19 rows selected. Execution Plan
----------------------------------------------------------
Plan hash value: 944056911 --------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 19 | 627 | 3 (0)| 00:00:01 |
| 1 | TABLE ACCESS FULL| JOBS | 19 | 627 | 3 (0)| 00:00:01 |
-------------------------------------------------------------------------- Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
9 consistent gets
0 physical reads
0 redo size
1452 bytes sent via SQL*Net to client
396 bytes received via SQL*Net from client
3 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
19 rows processed SQL>
二.授予其他用户AUTOTRACE 功能
2.1 创建基础表 运行$ORACLE_HOME/rdbms/admin/utlxplan脚本来创建plan_table
SQL> conn /as sysdba --用系统账户登录
Connected.
SQL> start $ORACLE_HOME/rdbms/admin/utlxplan --执行utlxplan脚本 Table created. SQL> create public synonym plan_table for plan_table;--为表plan_table创建公共同义词 Synonym created. --如果需要限制Autotrace权限,可以把对public的授权改为对特定user的授权。
SQL> grant all on plan_table to public;--将同义词表plan_table授予给所有用户 Grant succeeded. SQL>
2.2 创建角色 运行$ORACLE_HOME/sqlplus/admin/plustrce.sql脚本
SQL> start $ORACLE_HOME/sqlplus/admin/plustrce.sql --执行创建角色的脚本
SQL>
--以下是脚本执行过程:首先 删除PLUSTRACE角色,重建PLUSTRACE角色,赋予权限
SQL> drop role plustrace;
drop role plustrace
*
ERROR at line 1:
ORA-01919: role 'PLUSTRACE' does not exist 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>
2.3 角色的授予
在创建角色后,DBA首先被授予了该角色,且可以将角色授予其它组和用户。可以手工把plustrace授予给public,则该数据库内所有的用户都将拥有plustrace角色的权限。也可以单独授予给某个组和用户。
--授予给单独用户
SQL> grant plustrace to hr; Grant succeeded. --授予给所有用户
SQL> grant plustrace to public; Grant succeeded. SQL>
现在所有用户即可使用autotrace 功能
三、AUTOTRACE的几个选项
--在sql提示符下输入set autot后将会给出设置autotrace的提示,如下:
SQL> set autot
Usage: SET AUTOT[RACE] {OFF | ON | TRACE[ONLY]} [EXP[LAIN]] [STAT[ISTICS]] set autotrace off :缺省值,将不生成autotrace 报告
set autotrace on :包含执行计划和统计信息
set autotrace traceonly :等同于set autotrace on,但不显示查询输出的结果
set autotrace on explain :只显示优化器执行路径报告
set autotrace on statistics :只显示执行统计信息
四.hr用户示例
SQL> conn hr/hr123
Connected.
SQL> set autotrace traceonly
SQL> select * from jobs; 19 rows selected. Execution Plan
----------------------------------------------------------
Plan hash value: 944056911 --------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 19 | 627 | 3 (0)| 00:00:01 |
| 1 | TABLE ACCESS FULL| JOBS | 19 | 627 | 3 (0)| 00:00:01 |
-------------------------------------------------------------------------- Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
9 consistent gets
0 physical reads
0 redo size
1452 bytes sent via SQL*Net to client
396 bytes received via SQL*Net from client
3 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
19 rows processed SQL>
最新文章
- Vi命令备忘
- 【待整理】Linux故障排查
- Teamcenter 2007 ";由于某些意外的 DBMS 错误失败";
- 75 int类型数组中除了一个数出现一次或两次以外,其他数都出现三次,求这个数。[2行核心代码]
- 301页面转向 php
- jQuery 源码基本框架
- yii2 resetful 授权验证
- JTA事务管理
- Fibonacci_array
- python创建udp服务端和客户端
- Team Foundation Server 2013 KEY(密钥)
- bootstrap css布局
- RowFilter遇上特殊字符*%'[]\
- Spring Boot 之 RESTfull API简单项目的快速搭建(三)
- asp.net的forms身份验证 单用户身份验证
- jQuery 判断浏览器
- chrome 此网页正试图从未经验证的来源加载脚本
- CDOJ 1502 string(简单贪心)
- FocusBI:SSAS体系结构(原创)
- IO模式