ORA-20000 While Executing dbms_stats.gather_schema_stats

这篇文章,在于提醒不要用system,sys用户去创建其他schema的索引。

[@more@]
ORA-20000 While Executing dbms_stats.gather_schema_stats [ID 309834.1]

修改时间 08-NOV-2007 类型 PROBLEM 状态 MODERATED

In this Document
Symptoms
Cause
Solution


This document is being delivered to you via Oracle Support's Rapid Visibility (RaV) process, and therefore has not been subject to an independent technical review.

Applies to:

Oracle Server - Enterprise Edition - Version: 9.2.0.5
This problem can occur on any platform.

Symptoms

ORA-20000 while executing "dbms_stats.gather_schema_stats"
Connect as user ABC

User ABC has DBA role granted

DBA role includes "analyze any" system privilege

Also granted "analyze any" privilege explicitly to user ABC

SQL> exec dbms_stats.gather_schema_stats('SCOTT',degree=>4,cascade=>TRUE,estimate_percent=>35);
BEGIN dbms_stats.gather_schema_stats('SCOTT',degree=>4,cascade=>TRUE,estimate_pe
rcent=>35); END;
ERROR at line 1:
ORA-20000: Insufficient privileges to analyze an object in Schema
ORA-06512: at "SYS.DBMS_STATS", line 10583
ORA-06512: at "SYS.DBMS_STATS", line 10751
ORA-06512: at "SYS.DBMS_STATS", line 10805
ORA-06512: at "SYS.DBMS_STATS", line 10782
ORA-06512: at line 1

Cause

Even if user ABC (or any other user) has DBA Role granted to it(which includes "analyze any" system
privilege),the user cannot analyze any objects that belong to SYS schema

If the schema that is being analyzed(in this example,SCOTT) has any dependent objects belonging to SYS Schema,we will get this error
The small test case below will justify it

SQL> select index_name,owner from all_indexes where table_name='TOM' and table_owner='SCOTT';

INDEX_NAME OWNER
----------------- --------------------------
IDX1 SYS

Note here that an index exists (owner is SYS) on a table owned by SCOTT
SQL> conn
Enter user-name: ABC/ABC

Connected.

Note:The user ABC has DBA granted to it...select count(*) from session_privs returns 139 rows

SQL> exec dbms_stats.gather_schema_stats('SCOTT',degree=>4,cascade=>TRUE,estimate_percent=>35);
BEGIN dbms_stats.gather_schema_stats('SCOTT',degree=>4,cascade=>TRUE,estimate_pe
rcent=>35); END;

*
ERROR at line 1:
ORA-20000: Insufficient privileges to analyze an object in Schema
ORA-06512: at "SYS.DBMS_STATS", line 10583
ORA-06512: at "SYS.DBMS_STATS", line 10751
ORA-06512: at "SYS.DBMS_STATS", line 10805
ORA-06512: at "SYS.DBMS_STATS", line 10782
ORA-06512: at line 1

Solution

To implement the solution, execute the following steps:
1. Drop the index that belongs to SYS schema
SQL>drop index

To identify the table that has problem,execute the following plsql

SQL>set serveroutput on

SQL>
begin
for x in (select table_name from dba_tables where owner='SCOTT')
loop
dbms_output.put_line('TABLE : ' || x.table_name);
begin
dbms_stats.gather_table_stats(ownname => 'SCOTT',tabname =>
x.table_name, cascade => TRUE, estimate_percent => 35);
exception
when others then
dbms_output.put_line('### ERROR: ' || sqlerrm);
end;
end loop;
end;
For the above case,we will see :

TABLE : TOM
### ERROR: ORA-20000: Object IDX1 does not exist or insufficient privileges to analyze
.
Now,get the index using all_indexes

SQL>select index_name,owner from all_indexes where table_name='TOM' and table_owner='SCOTT';

It will return IDX1 as index_name and SYS as owner

2.Execute dbms_stats now.
SQL> exec dbms_stats.gather_schema_stats('SCOTT',degree=>4,cascade=>TRUE,estimate_percent=>35);

3.Recreate the index in SCOTT schema

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/3345/viewspace-1029368/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/3345/viewspace-1029368/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
EhLib 8.0 Build 8.0.023 Pro Edition FullSource for D7-XE8 亲测可用,含全部源码及 Demo The Library contains components and classes for Borland Delphi versions 7, 9, Developer Studio 2006, Delphi 2007, Embarcadero RAD Studio 2009-XE8, Lazarus. TABLE OF CONTENTS ----------------- Overview Installation Library Installation Help Demonstration Programs Registering and Prices Other information About author Where to start. ------------------- Read about EhLib for Lazarus in the file - Lazarus\readme.txt Start overview of the library with the main Demo project .\Demos\Bin\MainDemo.Exe. (Compiled Demo files are available in the Evaluation version of the library) Then you can read a summary of the new features and changes in the file history-eng.html. More detail about new features can be found in the file - About EhLib 8 Eng.doc To install a new version of the library in the IDE, use the installation program in .\Installer\EhLibInstaller.exe Overview -------- The Library contains several components and objects. TDBGridEh component TDBGridEh provides all functionality of TDBGrid and adds several new features as follows: Allows to select records, columns and rectangle areas. Special titles that can correspond to several/all columns. Footer that is able to show sum/count/other field values. Automatic column resizing to set grid width equal client width. Ability to change row and title height. Allows automatic broken of a single line long title and data row to a multiline. Title can act as button and, optionally show a sort marker. Automatically sortmarking. Ability to truncate long text with ellipsis. Lookup list can show several fields. Incremental search in lookup fields. Frozen columns. DateTime picker support for TDateField and TDateTimeField. Allows to show bitmaps from TImageList depending on field value. Allows to hide and track horizontal or vertical scrollbars. Allows to hide columns. Allows to show 3D fr
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值