[20160904]表统计信息lock.txt

[20160904]表统计信息lock.txt

晚上看链接:https://blogs.oracle.com/Database4CN/entry/%E8%AF%8A%E6%96%AD%E7%BB%9F%E8%AE%A1%E4%BF%A1%E6%81%AF%E4%B8%8D%E6%94%B6%E9%9B%86%E5%8E%9F%E5%9B%A0

提到如果导入使用ROWS=n,会导致导入的表lock,测试看看:

官方有如下解释:
If ROWS=n, then statistics for all imported tables will be locked after the import operation is finished.

--自己测试看看。作者测试使用的是exp/imp,我先测试看看expdp/impdp是否存在这个问题。

1.环境:
SCOTT@test01p> @ ver1
PORT_STRING          VERSION    BANNER                                                                       CON_ID
-------------------- ---------- ---------------------------------------------------------------------------- ------
IBMPC/WIN_NT64-9.1.0 12.1.0.1.0 Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production      0

SCOTT@test01p> create table deptx as select * from dept ;
Table created.

2.导出(expdp):
D:\tools\rlwrap>expdp scott/btbtms@test01p DIRECTORY=TMP_EXPDP DUMPFILE=deptx.dmp tables=deptx
expdp scott/btbtms@test01p DIRECTORY=TMP_EXPDP DUMPFILE=deptx.dmp tables=deptx
Export: Release 12.1.0.1.0 - Production on Sun Sep 4 20:27:10 2016
Copyright (c) 1982, 2013, Oracle and/or its affiliates.  All rights reserved.
Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
Starting "SCOTT"."SYS_EXPORT_TABLE_01":  scott/a*******@test01p DIRECTORY=TMP_EXPDP DUMPFILE=deptx.dmp tables=deptx
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 64 KB
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Processing object type TABLE_EXPORT/TABLE/STATISTICS/MARKER
. . exported "SCOTT"."DEPTX"                             6.007 KB       4 rows
Master table "SCOTT"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SCOTT.SYS_EXPORT_TABLE_01 is:
  D:\TMP\EXPDP\DEPTX.DMP
Job "SCOTT"."SYS_EXPORT_TABLE_01" successfully completed at Sun Sep 4 20:28:03 2016 elapsed 0 00:00:51

3.导入(impdp):
D:\tools\rlwrap>impdp scott/btbtms@test01p DIRECTORY=TMP_EXPDP DUMPFILE=deptx.dmp tables=deptx CONTENT=METADATA_ONLY REMAP_TABLE=SCOTT.DEPTX:DEPTY
impdp scott/btbtms@test01p DIRECTORY=TMP_EXPDP DUMPFILE=deptx.dmp tables=deptx CONTENT=METADATA_ONLY REMAP_TABLE=SCOTT.DEPTX:DEPTY
Import: Release 12.1.0.1.0 - Production on Sun Sep 4 20:33:38 2016
Copyright (c) 1982, 2013, Oracle and/or its affiliates.  All rights reserved.
Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
Master table "SCOTT"."SYS_IMPORT_TABLE_01" successfully loaded/unloaded
Starting "SCOTT"."SYS_IMPORT_TABLE_01":  scott/a**@test01p DIRECTORY=TMP_EXPDP DUMPFILE=deptx.dmp tables=deptx CONTENT=METADATA_ONLY REMAP_TABLE=SCOTT.DEPTX:DEPTY
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Processing object type TABLE_EXPORT/TABLE/STATISTICS/MARKER
Job "SCOTT"."SYS_IMPORT_TABLE_01" successfully completed at Sun Sep 4 20:34:06 2016 elapsed 0 00:00:25

SELECT table_name
      ,global_stats
      ,user_stats
      ,stattype_locked
      ,stale_stats
      ,last_analyzed
  FROM DBA_TAB_STATISTICS
 WHERE owner = USER AND table_name IN ('DEPTX', 'DEPTY');

TABLE_NAME GLO USE STATT STA LAST_ANALYZED
---------- --- --- ----- --- -------------------
DEPTX      YES NO        NO  2016-09-04 20:19:55
DEPTY      NO  NO

--可以发现没有锁定。

4.测试使用exp:

D:\tools\rlwrap>exp scott/btbtms@test01p file=deptx.dmp tables=deptx
exp scott/btbtms@test01p file=deptx.dmp tables=deptx
Export: Release 12.1.0.1.0 - Production on Sun Sep 4 20:44:08 2016
Copyright (c) 1982, 2013, Oracle and/or its affiliates.  All rights reserved.
Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set
About to export specified tables via Conventional Path ...
. . exporting table                          DEPTX          4 rows exported
Export terminated successfully without warnings.

SCOTT@test01p> drop table depty purge ;
Table dropped.

SCOTT@test01p> rename deptx to deptx_old;
Table renamed.

D:\tools\rlwrap>imp scott/btbtms@test01p file=deptx tables=deptx rows=N
imp scott/btbtms@test01p file=deptx tables=deptx rows=N
Import: Release 12.1.0.1.0 - Production on Sun Sep 4 20:48:32 2016
Copyright (c) 1982, 2013, Oracle and/or its affiliates.  All rights reserved.
Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

Export file created by EXPORT:V12.01.00 via conventional path
import done in ZHS16GBK character set and AL16UTF16 NCHAR character set
. importing SCOTT's objects into SCOTT
. importing SCOTT's objects into SCOTT
Import terminated successfully without warnings.

SELECT table_name
      ,global_stats
      ,user_stats
      ,stattype_locked
      ,stale_stats
      ,last_analyzed
  FROM DBA_TAB_STATISTICS
 WHERE owner = USER AND table_name IN ('DEPTX', 'DEPTY');

TABLE_NAME GLO USE STATT STA LAST_ANALYZED
---------- --- --- ----- --- -------------------
DEPTX      YES NO  ALL   NO  2016-09-04 20:48:32

--stattype_locked=ALL,说明表统计信息已经锁定。再次导入:

D:\tools\rlwrap>imp scott/btbtms@test01p file=deptx tables=deptx rows=Y ignore=y
imp scott/btbtms@test01p file=deptx tables=deptx rows=Y ignore=y
Import: Release 12.1.0.1.0 - Production on Sun Sep 4 20:51:04 2016
Copyright (c) 1982, 2013, Oracle and/or its affiliates.  All rights reserved.
Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

Export file created by EXPORT:V12.01.00 via conventional path
import done in ZHS16GBK character set and AL16UTF16 NCHAR character set
. importing SCOTT's objects into SCOTT
. importing SCOTT's objects into SCOTT
. . importing table                        "DEPTX"          4 rows imported
IMP-00017: following statement failed with ORACLE error 20005:
 "BEGIN  DBMS_STATS.SET_TABLE_STATS(NULL,'"DEPTX"',NULL,NULL,NULL,4,4,20,6); "
 "END;"
IMP-00003: ORACLE error 20005 encountered
ORA-20005: object statistics are locked (stattype = ALL)
ORA-06512: at "SYS.DBMS_STATS", line 14937
ORA-06512: at line 1
IMP-00017: following statement failed with ORACLE error 20005:
 "DECLARE  SREC DBMS_STATS.STATREC; BEGIN SREC.MINVAL := 'C10B'; SREC.MAXVAL "
 ":= 'C129'; SREC.EAVS := 0; SREC.CHVALS := NULL; SREC.NOVALS := DBMS_STATS.N"
 "UMARRAY(10,40); SREC.BKVALS := DBMS_STATS.NUMARRAY(0,1); SREC.EPC := 2; DBM"
 "S_STATS.SET_COLUMN_STATS(NULL,'"DEPTX"','"DEPTNO"', NULL ,NULL,NULL,4,.25,0"
 ",srec,3,6); END;"
IMP-00003: ORACLE error 20005 encountered
ORA-20005: object statistics are locked (stattype = ALL)
ORA-06512: at "SYS.DBMS_STATS", line 7581
ORA-06512: at "SYS.DBMS_STATS", line 8505
ORA-06512: at "SYS.DBMS_STATS", line 13489
ORA-06512: at line 1
IMP-00017: following statement failed with ORACLE error 20005:
 "DECLARE  SREC DBMS_STATS.STATREC; BEGIN SREC.MINVAL := '4143434F554E54494E4"
 "7'; SREC.MAXVAL := '53414C4553'; SREC.EAVS := 0; SREC.CHVALS := NULL; SREC."
 "NOVALS := DBMS_STATS.NUMARRAY(338863550087541000000000000000000000,43228503"
 "8677786000000000000000000000); SREC.BKVALS := DBMS_STATS.NUMARRAY(0,1); SRE"
 "C.EPC := 2; DBMS_STATS.SET_COLUMN_STATS(NULL,'"DEPTX"','"DNAME"', NULL ,NUL"
 "L,NULL,4,.25,0,srec,10,6); END;"
IMP-00003: ORACLE error 20005 encountered
ORA-20005: object statistics are locked (stattype = ALL)
ORA-06512: at "SYS.DBMS_STATS", line 7581
ORA-06512: at "SYS.DBMS_STATS", line 8505
ORA-06512: at "SYS.DBMS_STATS", line 13489
ORA-06512: at line 1
IMP-00017: following statement failed with ORACLE error 20005:
 "DECLARE  SREC DBMS_STATS.STATREC; BEGIN SREC.MINVAL := '4348494341474F'; SR"
 "EC.MAXVAL := '4E455720594F524B'; SREC.EAVS := 0; SREC.CHVALS := NULL; SREC."
 "NOVALS := DBMS_STATS.NUMARRAY(349350027483572000000000000000000000,40640554"
 "4089997000000000000000000000); SREC.BKVALS := DBMS_STATS.NUMARRAY(0,1); SRE"
 "C.EPC := 2; DBMS_STATS.SET_COLUMN_STATS(NULL,'"DEPTX"','"LOC"', NULL ,NULL,"
 "NULL,3,.333333333333333,0,srec,8,6); END;"
IMP-00003: ORACLE error 20005 encountered
ORA-20005: object statistics are locked (stattype = ALL)
ORA-06512: at "SYS.DBMS_STATS", line 7581
ORA-06512: at "SYS.DBMS_STATS", line 8505
ORA-06512: at "SYS.DBMS_STATS", line 13489
ORA-06512: at line 1
Import terminated successfully with warnings.

--//可以发现再次导入时导入统计信息时报错。

D:\tools\rlwrap>imp scott/btbtms@test01p file=deptx tables=deptx rows=Y ignore=y STATISTICS=NONE
imp scott/btbtms@test01p file=deptx tables=deptx rows=Y ignore=y STATISTICS=NONE
Import: Release 12.1.0.1.0 - Production on Sun Sep 4 20:55:21 2016
Copyright (c) 1982, 2013, Oracle and/or its affiliates.  All rights reserved.
Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

Export file created by EXPORT:V12.01.00 via conventional path
import done in ZHS16GBK character set and AL16UTF16 NCHAR character set
. importing SCOTT's objects into SCOTT
. importing SCOTT's objects into SCOTT
. . importing table                        "DEPTX"          4 rows imported
Import terminated successfully without warnings.

SCOTT@test01p> exec dbms_stats.gather_table_stats ( OwnName => 'scott',TabName => 'deptx');
BEGIN dbms_stats.gather_table_stats ( OwnName => 'scott',TabName => 'deptx'); END;

*
ERROR at line 1:
ORA-20005: object statistics are locked (stattype = ALL)
ORA-06512: at "SYS.DBMS_STATS", line 33859
ORA-06512: at line 1

--解锁再分析就ok了。
SCOTT@test01p> execute sys.dbms_stats.unlock_table_stats (ownname => user,tabname  => 'deptx')
PL/SQL procedure successfully completed.

SCOTT@test01p> exec dbms_stats.gather_table_stats ( OwnName => 'scott',TabName => 'deptx');
PL/SQL procedure successfully completed.

--总结:
--可以发现使用这种方式(exp/imp)导入数据要注意统计信息时lock的。

时间: 2024-09-20 17:46:04

[20160904]表统计信息lock.txt的相关文章

[20151202]表统计信息stale百分比.txt

[20151202]表统计信息stale百分比.txt --昨天被别人问及一个问题缺省如果某个表修改信息超过10%,oracle即认为这个表需要重新统计分析. --这个百分比如何计算的,实际上只要自己仔细观察就可以确定oracle如何算的. 1.环境: SCOTT@book> @ &r/ver1 PORT_STRING                    VERSION        BANNER ------------------------------ --------------

[20150705]11G表统计信息与PUBLISH.txt

[20150705]11G表统计信息与PUBLISH.txt --11G表统计信息可以先不发布(在PUBLISH参数的控制下),等检测合适再发布. --确实参数optimizer_use_pending_statistics为false,可以在session级别打开为true,检测统计是否有用. SYS@test> @hide optimizer_use_pending_statistics NAME                              DESCRIPTION       

[20130918]12C表统计信息的在线收集.txt

[20130918]12C表统计信息的在线收集.txt 在12c以前,如果使用ctas建立表,并不会自动收集表的统计信息,12c开始CTAS和IAS操作会收集统计信息.但是不收集直方图信息.以及索引统计. 摘要:twp-bp-for-stats-gather-12c-1967354.pdfBest Practices for Gathering Optimizer Statistics with Oracle Database 12c P16-17页: Online statistics gat

[20160713]impdp与统计信息导入.txt

[20160713]impdp与统计信息导入.txt --许多做迁移使用导入imdp加入EXCLUDE=STATISTICS参数,避免统计信息导入.具体原因我觉得可能人为重新组织数据后,统计信息不准确. --希望系统自己重新分析,实际上加入这个参数还导致另外的一种情况出现,测试看看. 1.环境: SCOTT@book> @ &r/ver1 PORT_STRING         VERSION        BANNER ------------------- --------------

更新SQL Server实例所有数据库表统计信息

引出问题 自从上次菜鸟为老鸟解决了<RDS SQL SERVER 解决中文乱码问题>问题,老鸟意犹未尽,决定再想个招来刁难刁难菜鸟:"我最近做T-SQL性能调优的时候,经常发现执行计划中的统计信息不准确,导致SQL Server查询性能低下,想个办法帮我一次性更新实例所有数据库下所有表统计信息吧?" 分析问题 "要一次性更新实例级别所有数据库下所有表统计信息啊,这个还真的有点犯难",菜鸟一边小声嘀咕,一边不停的问G哥,终于功夫不负有心人,发现了两个非常有

藏在表分区统计信息背后的小秘密

曾令军 云和恩墨技术专家,8年数据库运维经验.思维敏捷,擅长于数据库开发.解决棘手的数据库故障和性能问题,在数据库故障诊断.运维监控.性能优化方面积累了丰富的经验. 本文由一个表分区统计信息没有按预期更新的问题,逐步深入设疑.探因.求实,解开关于表分区统计信息收集的秘密.曲径通幽处,禅房花木深.让我们打开数据库知识的那扇窗,去看到花木浓茂幽静自然的美好. 案例背景 客户的业务系统中,做了AB表设计.A代表日间业务表,只存放一天的交易数据:B代表历史数据表,每天一个分区.每天晚上A表的所有数据会转

【DB2学习】使用reorgchk 收集表的信息

D:\DB2\BIN>db2 reorgchk update statistics on table yang.bd_corp 正在执行 RUNSTATS .... 表统计信息: F1: 100 * OVERFLOW / CARD < 5 F2: 100 * (数据页的有效空间使用率) > 70 F3: 100 * (需要页数 / 总页数) > 80 SCHEMA.NAME  CARD     OV     NP     FP ACTBLK    TSIZE  F1  F2  F3

简述oracle的统计信息自动收集机制

统计信息对于Oracle数据库来说至关重要,尤其是在使用CBO(基于成本的优化器)模式的时候,统计信息包括表的使用块数,空闲块数,平均行长度,统计信息收集时间等.在Oracle9i数据库中,两种优化器模式RBO(基于规则的优化器)和CBO(基于成本的优化器)并存,默认情况下,optimizer_mode参数的值是choose,choose不是优化器模式,它表示,在分析数据库当中的语句时,如果在对象上有统计信息,就是用cbo的方法生成执行计划,如果对象上没有统计信息,就使用rbo的方法. 总体来看

MySQL · 性能优化· CloudDBA SQL优化建议之统计信息获取

阿里云CloudDBA具有SQL优化建议功能,包括SQL重写建议和索引建议.SQL索引建议是帮助数据库优化器创造最佳执行路径,需要遵循数据库优化器的一系列规则来实现.CloudDBA需要首先计算表统计信息,是因为: 数据库优化器通常是基于代价寻找执行路径: SQL优化建议所针对的数据库不限于MySQL数据库,也不局限于某一个特定版本: 1. 基本原则 数据库统计信息在SQL优化起到重要作用.用来估算查询条件选择度的常见统计信息包括表统计信息和字段统计信息.DBA计算查询条件选择度或代价时经常通过