Oracle授权普通用户查看执行计划
利用不同的方法查看執行計劃有對應不同的授權方法。
一、?explain plan與dbms_xplan.display
最常用的方法,plsqldev的F5對應也是這個。這個命令會產生執行計劃,并把執行計劃保存到"PLAN_TABLE"中,查看執行計劃使用 select * from table(dbms_xplan.display);
啟用方法(9i需手動啟用):
--創建PLAN_TABLE,存儲執行計劃 SQL> @$ORACLE_HOME/rdbms/admin/utlxplan.sql--創建同義詞使多個用戶可以共享一個plan_table,并授權給public create public synonym plan_table for plan_table; grant all on plan_table to public;Prerequisites
To issue an?EXPLAIN?PLAN?statement, you must have the privileges necessary to insert rows into an existing output table that you specify to hold the execution plan.
You must also have the privileges necessary to execute the SQL statement for which you are determining the execution plan. If the SQL statement accesses a view, then you must have privileges to access any tables and views on which the view is based. If the view is based on another view that is based on a table, then you must have privileges to access both the other view and its underlying table.
To examine the execution plan produced by an?EXPLAIN?PLAN?statement, you must have the privileges necessary to query the output table.
The?EXPLAIN?PLAN?statement is a data manipulation language (DML) statement, rather than a data definition language (DDL) statement. Therefore, Oracle Database does not implicitly commit the changes made by an?EXPLAIN?PLAN?statement. If you want to keep the rows generated by an?EXPLAIN?PLAN?statement in the output table, then you must commit the transaction containing the statement.
參考?EXPLAIN PLAN
二、 autotrace
實際上它需要兩個東西:PLAN_TABLE 和?plustrace角色,另外plsqldev是不支持用autotrace的。
執行以下腳本創建plustrace角色,并執行grant plustrace to public授權,這樣所有用戶都可以使用autotrace跟蹤工具。
@?/sqlplus/admin/plustrce.sql grant plustrace to public;腳本內容如下
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三、?dbms_xplan.display_cursor
基本信息:select * from table(dbms_xplan.display_cursor);
grant select on v_$session to tempuser; grant select on v_$sql_plan to tempuser; grant select on v_$sql to tempuser;高級統計:select * from table(dbms_xplan.display_cursor(null,null,'ADVANCED? ALLSTATS LAST PEEKED_BINDS'));
grant select on v_$sql_plan_statistics_all to tempuser; --這里statistics_level =all讓統計信息最為詳盡 alter session set statistics_level =all;查看真實執行計劃
set linesize 200 pagesize 999 alter session set statistics_level=all; -- 執行sql select * from table(dbms_xplan.display_cursor(null,null,'advanced -PROJECTION iostats,last'));參考
oracle 9i啟用Execution Plan的方法 | 學步園
utlxplan_ITPUB博客
https://www.iteye.com/blog/falchion-616234
授權普通非DBA用戶可以有權限查看執行計劃的方法_weixin_33923762的博客-CSDN博客
授予普通用戶查看執行計劃權限_ITPUB博客
總結
以上是生活随笔為你收集整理的Oracle授权普通用户查看执行计划的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 人工智能识别手写数学公式
- 下一篇: 动手学习数据分析——第一部分