DBMS_REDEFINITION(線上重定義一個重要bug)
線上重定義後會發現列not null沒有copy過來,
執行sql alter table modify column not null
報如下錯誤
ORA-01442: column to be modified to NOT NULL is already NOT NULL透過sql查詢發現
select constraint_name,constraint_type,status,validated
from user_constraints
where constraint_name in (select constraint_name from user_cons_columns where table_name='TEST' and column_name='TEST');
列都是NOT VALIDATED 狀態
查詢MOS發現時一個bug mos 詳細資訊如下:ID 1089860.1
APPLIES TO:
Oracle Server - Enterprise Edition - Version 10.2.0.1 and laterInformation in this document applies to any platform.
Reviewed for relevance 24 April 2012
SYMPTOMS
After redefining a table using DBMS_REDEFINITION it is found that a describe of the table no longer shows the NOT NULL constraints
CAUSE
The cause of this condition is two fold
1) The constraint really was not copied ... due to COMPATIBLE not being 10.2 or higher
2) The constraint was copied ... but appears to not have been ... (ie a describe shows a
These are discussed in the INTERNAL ONLY bug
ET10.2OREDEF: NULLABLE COL OF *_TAB_COLUMNS TABLE NOT UPDATED AFTER ONLINE REDEF
"In order to copy Not Null constraints, COMPATIBLE must be set to 10.2 or higher. "
"Not null/Primary key constraints are copied in NOVALIDATE mode in order to speed up the redefinition process."
SOLUTION
1) If COMPATIBLE < 10.2 then NOT NULL constraints must be manually copied or the redefinition restarted with compatible set to 10.2 or higher
2) If COMPATIBLE => 10.2 the constraints will be copied ... but will be in NOVALIDATE mode
The not null constraint CAN be reenabled for VALIDATE using the ALTER TABLE ... ENABLE VALIDATE CONSTRAINT ... command
CASE STUDY
create user test identified by test;
grant dba to test;
alter user test default tablespace users;
connect test/test;
SHOW PARAMETER COMPATIBLE
-- NAME TYPE VALUE
-- ------------------------------------ ----------- ------------------------------
-- compatible string 11.2.0.0.0
-- CREATE THE TABLE TO BE REDEFINED
CREATE TABLE ORIGINAL (COL1 VARCHAR2(10) NOT NULL);
-- Table created.
-- CREATE THE INTERIM TABLE FOR THE REDEFINITION
CREATE TABLE INTERIM (COL1 VARCHAR2(20));
-- Table created.
-- DESCRIBE THE TWO TABLES JUST CREATED
DESC ORIGINAL
-- ---------------- -------- ----------------------------
-- COL1 NOT NULL VARCHAR2(10)
DESC INTERIM
-- ---------------- -------- ----------------------------
-- COL1 VARCHAR2(20)
-- PROVE THAT THE REDEFINITION CAN WORK
exec dbms_redefinition.can_redef_table('TEST','ORIGINAL', dbms_redefinition.cons_use_rowid);
-- PL/SQL procedure successfully completed.
-- START THE REDEFINITION
exec dbms_redefinition.start_redef_table('TEST','ORIGINAL','INTERIM','COL1 COL1',dbms_redefinition.cons_use_rowid);
-- PL/SQL procedure successfully completed.
-- COPY THE CONSTRIANTS FROM THE ORIGINAL TABLE TO THE INTERIM TABLE
SET SERVEROUTPUT ON
DECLARE
error_count pls_integer := 0;
BEGIN
DBMS_REDEFINITION.COPY_TABLE_DEPENDENTS('TEST',
'ORIGINAL',
'INTERIM',
dbms_redefinition.cons_orig_params ,
TRUE,
TRUE,
TRUE,
FALSE,
error_count);
DBMS_OUTPUT.PUT_LINE('errors := ' || TO_CHAR(error_count));
END;
/
-- PL/SQL procedure successfully completed.
-- FINISH THE REDEFINITION (THIS IS WHERE THE ROWS GET COPIED)
exec dbms_redefinition.finish_redef_table('TEST','ORIGINAL','INTERIM');
-- PL/SQL procedure successfully completed.
--LOOK AT THE DESCRIPTION OF THE NEWLY REDFINED TABLE
DESC ORIGINAL
-- Name Null? Type
-- ----------------------------------------- -------- ----------------------------
-- COL1 VARCHAR2(20)
-- ---------------- -------- ----------------------------
-- COL1 VARCHAR2(20)
-- NOTICE THAT OUR 'Null?' column no longer says 'NOT NULL'
-- this would imply that our constraint is gone
-- PROVE THAT THE CONSTRAINT STILL EXISTS
SELECT CONSTRAINT_NAME, VALIDATED FROM USER_CONSTRAINTS WHERE TABLE_NAME = 'ORIGINAL';
-- ------------------------------ -------------
-- SYS_C0011548 NOT VALIDATED
-- THE CONSTRAINT EXISTS BUT IS 'NOT VALIDATED'
-- ALTER THE TABLE SO THAT THE NOT NULL CONSTRAINT IS NOW VALIDATED
ALTER TABLE ORIGINAL ENABLE VALIDATE CONSTRAINT SYS_C0011548;
-- Table altered.
-- REEXAMINE THE TABLE
DESC ORIGINAL
-- ---------------- -------- ----------------------------
-- COL1 NOT NULL VARCHAR2(20)
SELECT CONSTRAINT_NAME, VALIDATED FROM USER_CONSTRAINTS WHERE TABLE_NAME = 'ORIGINAL';
-- CONSTRAINT_NAME VALIDATED
-- ------------------------------ -------------
-- SYS_C0011548 VALIDATED
-- ------------------------------ -------------
-- SYS_C0011548 VALIDATED
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/15747463/viewspace-1184339/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 在oracle 9i下線上重定義表Oracle
- 線上重定義與普通表改為分割槽表
- 壓縮錶轉非壓縮表(線上重定義)
- 線上重定義方式將普通表修改為分割槽表
- 指令碼:線上重定義,從普通表到分割槽表,redefinition_table.sh指令碼
- 前端如何定義一個常量前端
- 論線上 Bug,測試、產品、開發的定責比例
- 一個人情緒穩定的重要性
- 記php-fpm重啟導致的一個bugPHP
- Python如何定義一個函式Python函式
- 線上重定義的操作步驟__普通錶轉換為分割槽表的實驗案例
- mysql 原生 線上DDL 的bug .MySql
- qt之函式重定義QT函式
- 簡單-定義一個小程式元件元件
- Oracle EBR 基於版本重定義Oracle
- 重學java之類的定義Java
- 我做了一個線上白板!!!
- 定義一個單例型別的Qml單例型別
- 策略模式-定義一個演算法族模式演算法
- 線上BUG:MySQL死鎖分析實戰MySql
- 線上出現bug解決用例
- oracle的一個bugOracle
- TestHome 的一個 Bug
- Snakeyaml的一個bugYAML
- 一個奇怪的 Bug
- MySQL8.0.32版本一個嚴重Bug及解決方案MySql
- SDSec重定義 華為如何讓安全“耳目一新”?
- 記錄阿里巴巴連線池DruidDataSource的一個bug阿里UI
- c++繼承,隱藏(重定義)C++繼承
- C++中過載、重寫、重定義的區別C++
- 直播系統定製開發中流媒體傳輸最重要的三個重點
- [BUG反饋]AdminController類的一個小bugController
- 線上出bug了?別怕,這麼定位!
- SAP Spartacus 如何重定義登入 Login Component
- 解Bug之路-記一次線上請求偶爾變慢的排查
- 定義一個求n的階乘的函式函式
- 一個線上全文索引BUG的排查:關於類阿拉件數字的分詞與檢索索引分詞
- 一個好用的線上測評工具——線上測評H5H5
- LNK1169 找到一個或多個衝定義的符號符號