oracle 锁定、对比统计信息



 

锁定schema统计
execute dbms_statS.unlock_schema_stats(ownname=>'SCOTT');

查看表锁定情况
SQL> select owner,table_name,STATTYPE_LOCKED from dba_tab_statistics where owner='SCOTT';

OWNER TABLE_NAME STATTYPE_L
------------------------------ ------------------------------ ----------
SCOTT BIN$ywjNKrPMSEygN6Kvb2yz7Q==$0
SCOTT BONUS ALL
SCOTT DEPT ALL
SCOTT EMP ALL
SCOTT SALGRADE ALL
SCOTT T ALL

解锁
SQL> execute dbms_statS.unlock_schema_stats(ownname=>'SCOTT');

SQL> select owner,table_name,STATTYPE_LOCKED from dba_tab_statistics where owner='SCOTT';

OWNER TABLE_NAME STATTYPE_L
------------------------------ ------------------------------ ----------
SCOTT BIN$ywjNKrPMSEygN6Kvb2yz7Q==$0
SCOTT BONUS
SCOTT DEPT
SCOTT EMP
SCOTT SALGRADE
SCOTT T

锁定表统计
execute dbms_stats.lock_table_stats(ownname=>'SCOTT',tabname=>'T');

收集统计信息将报错
execute dbms_stats.gather_table_stats(ownname=>'SCOTT',tabname=>'T');

SQL> execute dbms_stats.gather_table_stats(ownname=>'SCOTT',tabname=>'T');
BEGIN dbms_stats.gather_table_stats(ownname=>'SCOTT',tabname=>'T'); END;

*
第 1 行出现错误:
ORA-20005: object statistics are locked (stattype = ALL)
ORA-06512: 在 "SYS.DBMS_STATS", line 20337
ORA-06512: 在 "SYS.DBMS_STATS", line 20360
ORA-06512: 在 line 1

可以添加force强制覆盖
execute dbms_stats.gather_table_stats(ownname=>'SCOTT',tabname=>'T',force=>true);


SQL> create index iid_idx on t(iid) compute statistics;
create index iid_idx on t(iid) compute statistics
*
第 1 行出现错误:
ORA-38029: 对象统计信息已锁定

默认没有搜集统计信息,有点疑惑
SQL> create index iid_idx on t(iid) ;

execute dbms_statS.unlock_TABLE_stats(ownname=>'SCOTT',TABNAME=>'T');

比较对象统计信息。
SELECT *
FROM table(dbms_stats.diff_table_stats_in_pending(
ownname => 'SCOTT',
tabname => 'T',
time_stamp => NULL,
pctthreshold => 10));

SELECT *
FROM table(dbms_stats.diff_table_stats_in_pending(
ownname => 'SCOTT',
tabname => 'T',
time_stamp => NULL,
pctthreshold => 0));

SELECT *
FROM table(dbms_stats.diff_table_stats_in_stattab(
ownname => 'SCOTT',
tabname => 'T',
stattab1 => 'MYSTATS',
statid1 => 'SET1',
stattab1own => 'SCOTT',
pctthreshold => 0));

SELECT *
FROM table(dbms_stats.diff_table_stats_in_history(
ownname => 'SCOTT',
tabname => 'T',
time1 => systimestamp - to_dsinterval('0 00:00:15'),
time2 => NULL,
pctthreshold => 0));


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值