12c 可擴充套件的字元型別MAX_STRING_SIZE與常見錯誤

snowdba發表於2015-03-12
12c推出了varchar2的可擴充套件特性,從4000B增加到了32727B。許多超過4000B的文字內容除了使用CLOb欄位,現在可以考慮使用擴充套件後的varchar2。但是擴充套件操作不是Oracle12c預設支援的,需要手工開啟才能生效。傳統方式建立的資料庫操作相對簡單,可插拔庫過程複雜些。我們從簡單的入手,先看看傳統資料庫時如何開啟擴充套件的。

1. 關閉資料庫
$ shutdown immediate;

2. 啟動資料庫到升級模式
SYS@OCM12C >startup upgrade;

3. 修改max_string_size為EXTENDED,預設是standard
SYS@OCM12C >alter system set max_string_size=EXTENDED scope=both;

4. 使用SYS使用者執行指令碼
SYS@OCM12C >@?/rdbms/admin/utl32k.sql

5. 重新啟動資料庫
SYS@OCM12C >shutdown immediate;
SYS@OCM12C >startup

6. 在users表空間下建立表,varchar2欄位可超過4000。在12c之前是做不到這一點的。
SYS@OCM12C >create table t3(blog varchar2(4001)) tablespace users;

7. 擴充套件後欄位最大可支援到32727B大小
SYS@OCM12C >create table t4(blog varchar2(32727)) tablespace users;

下面看看可插拔資料庫PDB是如何操作的,注意所有操作只針對PDB,不要去操作CDB。

1. 關閉PDB資料庫
[oracle@snow ~]$ sqlplus / as sysdba

SYS@cdb > show pdbs;

CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDB1 READ WRITE NO

SYS@cdb > alter pluggable database pdb1 close;

Pluggable database altered.

2. 重新啟動PDB到migrate模式
SYS@cdb > alter pluggable database pdb1 open upgrade;

Pluggable database altered.

3. 修改max_string_size引數為extended
SYS@cdb > alter system set max_string_size=extended scope=both;

System altered.

4. 使用SYS使用者執行指令碼
SYS@cdb > @?/rdbms/admin/utl32k.sql

省去部分內容
...Database user "SYS", database schema "APEX_040200", user# "98" 10:49:54
...Compiled 0 out of 2998 objects considered, 0 failed compilation 10:49:54
...263 packages
...255 package bodies
...453 tables
...11 functions
...16 procedures
...3 sequences
...458 triggers
...1322 indexes
...207 views
...0 libraries
...6 types
...0 type bodies
...0 operators
...0 index types
...Begin key object existence check 10:49:54
...Completed key object existence check 10:49:54
...Setting DBMS Registry 10:49:54
...Setting DBMS Registry Complete 10:49:54
...Exiting validate 10:49:54

PL/SQL procedure successfully completed.

5. 重新啟動PDB資料庫
SYS@cdb > alter pluggable database pdb1 close;

Pluggable database altered.

SYS@cdb > alter pluggable database open;

Pluggable database altered.

6. 建立擴充套件列的varchar2表
SYS@cdb > create table t1(blog varchar2(32727)) tablespace users;

Table created.




常見錯誤:ORA-14696: MAX_STRING_SIZE migration is incomplete for pluggable database

注意:擴充套件操作是在PDB層面,而不是在CDB層面。

如果將CDB執行以上操作,會在執行完指令碼rdbms/admin/utl32k.sql後重新啟動資料庫報錯。

SYS@cdb > startup;  
ORACLE instance started.

Total System Global Area 1553305600 bytes
Fixed Size 2288728 bytes
Variable Size 939525032 bytes
Database Buffers 603979776 bytes
Redo Buffers 7512064 bytes
Database mounted.
ORA-01092: ORACLE instance terminated. Disconnection forced
ORA-14696: MAX_STRING_SIZE migration is incomplete for pluggable database
PDB$SEED
Process ID: 20105
Session ID: 237 Serial number: 5

這段報錯的意識是說CDB資料庫已經是migrate狀態了(startup upgrade),但是PDB$SEED還不是。需要對PDB$SEED做寫操作。

SYS@cdb > shutdown immediate;
SYS@cdb > startup mount;
SYS@cdb > alter database open migrate;

我們需要PDB$SEED處於MIGRATE狀態
SYS@cdb > select con_id,name,open_mode from v$pdbs;

CON_ID     NAME                           OPEN_MODE
---------- ------------------------------ ----------
2          PDB$SEED                       MIGRATE
3          PDB1                           MOUNTED


SYS@cdb > alter session set container=pdb$seed;

SYS@cdb > show con_name

SYS@cdb > alter system set max_string_size = extended scope=both;

SYS@cdb > @?/rdbms/admin/utl32k.sql

當PDB$SEED處理結束後,接下來可以繼續做PBD的擴充套件
SYS@cdb > alter pluggable database pdb1 close;

SYS@cdb > alter pluggable database pdb1 open upgrade;

SYS@cdb > alter system set max_string_size=extended scope=both;

SYS@cdb > @?/rdbms/admin/utl32k.sql

SYS@cdb > alter pluggable database pdb1 close;

SYS@cdb > alter pluggable database open;

SYS@cdb > create table t1(blog varchar2(32727)) tablespace users;


全文完

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29047826/viewspace-1457479/,如需轉載,請註明出處,否則將追究法律責任。

相關文章