编辑脚本 utlvalid.sql
Set verify off
Set space 0
Set line 120
Set heading off
Set feedback off
Set pages 1000
Spool analyze.sql
SELECT 'Analyze cluster "'||cluster_name||'" validate structure cascade;'
FROM dba_clusters
WHERE owner='SYS'
UNION
SELECT 'Analyze table "'||table_name||'" validate structure cascade;'
FROM dba_tables
WHERE owner='SYS'
AND partitioned='NO'
AND (iot_type='IOT' OR iot_type is NULL)
UNION
SELECT 'Analyze table "'||table_name||'" validate structure cascade into invalid_rows;'
FROM dba_tables
WHERE owner='SYS'
AND partitioned='YES';
spool off
它会创建一个脚本 analyze.sql。
现在执行这个脚本:
$ sqlplus "/ as sysdba"
SQL> @$ORACLE_HOME/rdbms/admin/utlvalid.sql
SQL> @analyze.sql
这个脚本(analyze.sql)不应该返回任何错误。
注意:
1. 如果存在外部表,那么可能会发生ORA-30657. 但是根据文档 Note 209355.1 ORA-30657: Using ANALYZE TABLE for an External Table,这个错误可以忽略掉。
2. 在执行脚本时下面这样的错误可以忽略掉:
SP2-0734: unknown command beginning "SQL> SELEC..." - rest of line ignored.
SP2-0042: unknown command "SQL>" - rest of line ignored.
SP2-0734: unknown command beginning "SQL> spool..." - rest of line ignored.
3. 在分析 AWR 相关的表(WRH$_...)可能会返回"ORA-00054: resource busy and acquire with NOWAIT specified"的错误。变通方案是把 AWR 临时禁用。
3.a) 找到当前快照间隔时间(snapshot interval)
select snap_interval,retention from dba_hist_wr_control;
3.b) 把快照间隔时间改为 0 来临时禁用 AWR:
exec dbms_workload_repository.modify_snapshot_settings(interval=>0);
3.c) 分析以 WRH$ 开头的表
3.d) 把快照间隔时间恢复到原来的值:
exec dbms_workload_repository.modify_snapshot_settings(interval=> returned at 3.a>);
阅读(2699) | 评论(0) | 转发(0) |