ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

oracle19c修改字符集_pdb修改成与cdb不一样得字符集

2021-01-10 19:02:32  阅读:554  来源: 互联网

标签:oracle19c set CDB character CHARACTERSET 字符集 NLS 修改 PDB


cdb得字符集是utf8,新建默认字符集pdb1,再修改pdb1字符集为16gbk,印证一下19c上cdb支持不同字符集pdb得特性。

[oracle@vm3 ~]$ export ORACLE_SID=orcl
[oracle@vm3 ~]$ dbca
[oracle@vm3 ~]$ sqlplus / as sysdba
SQL> select userenv('language') from dual;
USERENV('LANGUAGE')
----------------------------------------------------
AMERICAN_AMERICA.AL32UTF8
SQL> show pdbs;
    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
SQL> show pdbs;
    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
SQL> alter session set container=pdb$seed;
Session altered.
SQL> select name from v$datafile;
NAME
---------------------------------------------------------------------------
/app/oracle/db/oradata/ORCL/pdbseed/system01.dbf
SQL> !mkdir -p /app/oracle/db/oradata/ORCL/pdb1
SQL> alter session set container=cdb$root;
Session altered.
SQL> create pluggable database pdb1 admin user pdb1 identified by pdb1 create_file_dest='/app/oracle/db/oradata/ORCL/pdb1';
Pluggable database created.
SQL> show pdbs;
    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 PDB1                           MOUNTED
SQL> alter pluggable database pdb1 open;
Pluggable database altered.
SQL> show pdbs;
    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 PDB1                           READ WRITE NO
SQL> select userenv('language') from dual;
USERENV('LANGUAGE')
----------------------------------------------------
AMERICAN_AMERICA.AL32UTF8
SQL> alter pluggable database close immediate;
Pluggable database altered.
SQL> alter pluggable database open read write restricted;
Pluggable database altered.
SQL> alter session set container=pdb1;
Session altered.
SQL> select userenv('language') from dual;
USERENV('LANGUAGE')
----------------------------------------------------
AMERICAN_AMERICA.AL32UTF8
SQL> alter database character set internal_use zhs16gbk;
Database altered.
SQL> alter pluggable database pdb1 close;
Pluggable database altered.
SQL> alter pluggable database pdb1 open;
Pluggable database altered.
SQL> alter session set container=pdb1;
Session altered.
SQL> select userenv('language') from dual;
USERENV('LANGUAGE')
----------------------------------------------------
AMERICAN_AMERICA.ZHS16GBK
SQL>

===============================================================================

12c Multitenant Container Databases (CDB) and Pluggable Databases (PDB) Character set restrictions / ORA-65116/65119: incompatible database/national character set ( Character set mismatch: PDB character set CDB character set ) (Doc ID 1968706.1) 

SYMPTOMS

After plugged a pluggable database (PDB) into a container database (CDB) , The following Warning is in the alert log file :

***************************************************************
WARNING: Pluggable Database PDB1 with pdb id - 4 is
altered with errors or warnings. Please look into
PDB_PLUG_IN_VIOLATIONS view for more details.
***************************************************************

 

SQL> select NAME,CAUSE,TYPE,ERROR_NUMBER,MESSAGE,STATUS,ACTION from PDB_PLUG_IN_VIOLATIONS;

NAME CAUSE TYPE ERROR_NUMBER
------------------------------ ---------------------------------------------------------------- --------- ------------
MESSAGE
-----------------------------------------------------------------------------------------------------------------------
STATUS
---------
ACTION
-----------------------------------------------------------------------------------------------------------------------
PDB1 Database CHARACTER SET ERROR 65116
Character set mismatch: PDB character set WE8MSWIN1252. CDB character set AL32UTF8.
PENDING
Convert the character set of the PDB to match the CDB or plug the PDB in a CDB with compatible character set

 
If the NLS_NCHAR_CHARACTERSET differs between PDB and CDB you will see

National character set mismatch: PDB national character set UTF8. CDB national character set AL16UTF16.
or
National character set mismatch: PDB national character set AL16UTF16. CDB national character set UTF8.

 

CAUSE

The pluggable database (PDB) and the container database (CDB) character sets/national character sets are not binary subsets ,

You can check the multitenant container database (CDB) character sets (NLS_CHARACTERSET) and national character set (NLS_NCHAR_CHARACTERSET) set by :

SQL> show con_name

CON_NAME
------------------------------
CDB$ROOT

SQL> select value,parameter from NLS_DATABASE_PARAMETERS where PARAMETER like '%CHARACTERSET';

VALUE PARAMETER
--------------- ----------------------
AL16UTF16 NLS_NCHAR_CHARACTERSET
AL32UTF8 NLS_CHARACTERSET

You can check the pluggable database (PDB) character sets (NLS_CHARACTERSET) and national character set (NLS_NCHAR_CHARACTERSET) set by :

SQL> alter session set container=pdb1;

Session altered.

SQL> select value,parameter from NLS_DATABASE_PARAMETERS where PARAMETER like '%CHARACTERSET';

VALUE PARAMETER
--------------- ----------------------
AL16UTF16 NLS_NCHAR_CHARACTERSET
WE8MSWIN1252 NLS_CHARACTERSET

 

SOLUTION

 

In Oracle Database 12c, all pluggable databases (PDBs) in a container database (CDB) must have 
* the same Database character set (NLS_CHARACTERSET) or the NLS_CHARACTERSET need to be a (Plug-in compatible) binary subset of the CDB NLS_CHARACTERSET 
* the same National character set (NLS_NCHAR_CHARACTERSET)
  as the CDB's root container 
in order to be able to plug in.

If PDB NLS_CHARACTERSET is a (Plug-in compatible) binary subset of the CDB's NLS_CHARACTERSET the NLS_CHARACTERSET of the PDB is automatically changed to the NLS_CHARACTERSET of the CDB at the first open.

The character sets of the root container are considered the character sets of the whole CDB.

You can consolidate multiple databases by plugging them into a single CDB. These databases can be traditional, non-CDBs or PDBs unplugged from other CDBs.

A) The Database character set (NLS_CHARACTERSET)

Three situations may happen depending on the Database character set (NLS_CHARACTERSET) of a database being plugged in, that is, a new PDB:

1- The PDB NLS_CHARACTERSET is the same as the NLS_CHARACTERSET of the CDB. In this case, the plugging operation succeeds (as far as the database character set is concerned).

2- The PDB NLS_CHARACTERSET is (Plug-in compatible) binary subset of the CDB's NLS_CHARACTERSET and both are single-byte or both are multibyte. 
In this case, the NLS_CHARACTERSET of the new PDB is automatically changed to the NLS_CHARACTERSET of the CDB at the first open and the plugging operation succeeds.

examples: 
CDB is WE8MSWIN1252 NLS_CHARACTERSET, PDB is US7ASCII or WE8ISO8859P1 NLS_CHARACTERSET 
CDB is TR8MSWIN1254 NLS_CHARACTERSET, PDB is US7ASCII or WE8ISO8859P9 NLS_CHARACTERSET
CDB is any xx8xxxxx characterset NLS_CHARACTERSET , PDB is US7ASCII NLS_CHARACTERSET
CDB is AL32UTF8 NLS_CHARACTERSET, PDB is UTF8 NLS_CHARACTERSET

3- The PDB NLS_CHARACTERSET is not plug-in compatible with the NLS_CHARACTERSET of the CDB. In this case, the new PDB can only be opened in restricted mode for administrative tasks and cannot be used for production and ORA-65116 is Raised. Unless you have a tool that can migrate the NLS_CHARACTERSET of the new PDB to NLS_CHARACTERSET of the CDB, the new PDB is unusable.

examples of common NOT plug-in compatible situations:
CDB is AL32UTF8 or UTF8 NLS_CHARACTERSET, PDB is US7ASCII or any xx8xxxxx NLS_CHARACTERSET. 
CDB is WE8MSWIN1252 NLS_CHARACTERSET, PDB is WE8ISO8859P15 NLS_CHARACTERSET
CDB is AR8MSWIN1256 NLS_CHARACTERSET , PDB is AR8ISO8859P6 NLS_CHARACTERSET

See Also:
http://docs.oracle.com/database/121/NLSPG/applocaledata.htm#NLSPG591
Table Binary Subset-Superset Pairs 

If the CDB NLS_CHARACTERSET is AL32UTF8 then use the DMU tool Note 1272374.1 The Database Migration Assistant for Unicode (DMU) Tool

Note that the DMU tool cannot convert a non-Unicode CDB to AL32UTF8 as this is not needed. 
You will receive the following error upon connecting to CDB using the DMU : Encountered an error while checking database's compatibility: Migration of container databases (CDB) is not supported.

To go from a non-Unicode CDB with (also non-Unicode) PDB's the steps are:
* Create a new Unicode (AL32UTF8) CDB if needed
* Use the DMU to scan the non-Unicode PDB's and resolve any reported convertibility issues while it is still plugged into the original non-Unicode CDB.
* Unplug the PDB to be migrated and plug it into the target Unicode AL32UTF8 CDB (this will put the PDB into restricted mode due to the character set incompatibility).
* Use the DMU tool to convert the non-Unicode PDB to Unicode once plugged in the target Unicode AL32UTF8 CDB (= finish the conversion).

To consolidate non-Unicode non-pluggable/non-container databases in one Unicode (AL32UTF8) container CDB Oracle suggest to migrate each one to AL32UTF8 before doing the consolidation (= before trying to make them pluggable) .


B) The National character set (NLS_NCHAR_CHARACTERSET)

Two situations may happen depending on the National character set of the new PDB:

1- The PDB NLS_NCHAR_CHARACTERSET set is the same as the NLS_NCHAR_CHARACTERSET of the CDB. In this case, the plugging operation succeeds (as far as the national character set is concerned).

2- The PDB NLS_NCHAR_CHARACTERSET is not the same as the NLS_NCHAR_CHARACTERSET of the CDB. In this case, the new PDB can only be opened in restricted mode for administrative tasks and cannot be used for production and ORA-65119 is raised . Unless you have a tool that can migrate the NLS_NCHAR_CHARACTERSET of the new PDB to the NLS_NCHAR_CHARACTERSET of the CDB, the new PDB is unusable.

Note that difference between NLS_CHARACTERSET and NLS_NCHAR_CHARACTERSET Note 276914.1 The National Character Set ( NLS_NCHAR_CHARACTERSET ) in Oracle 9i, 10g , 11g and 12c
The NLS_NCHAR_CHARACTERSET can have only 2 values: UTF8 and AL16UTF16 , AL16UTF16 is the recommended value.
There is currently no tool , besides full export/import into a new PDB, to change the NLS_NCHAR_CHARACTERSET once a database is 12c.


C) What CDB NLS_CHARACTERSET and NLS_NCHAR_CHARACTERSET to use.

Because of these restrictions, you should consider the character sets of databases that you want to plug into a given CDB when selecting character sets for this CDB. 
In general Oracle recommends the following:

For all new deployments and if all PDBs are created empty, Oracle strongly recommends AL32UTF8 for the CDB database character set (NLS_CHARACTERSET) and AL16UTF6 for the CDB national character set ( NLS_NCHAR_CHARACTERSET ).

If you can migrate your existing databases to AL32UTF8 NLS_CHARACTERSET before consolidation, Oracle recommends that you do so and consolidate into one or more AL32UTF8 NLS_CHARACTERSET CDBs, depending on your needs. If the NLS_NCHAR_CHARACTERSET is UTF8 then Oracle suggest to change the NLS_NCHAR_CHARACTERSET to AL16UTF16 before consolidation.

You can use Oracle Database Migration Assistant for Unicode (DMU) to migrate a non-CDB NLS_CHARACTERSET to AL32UTF8. Note 1272374.1 The Database Migration Assistant for Unicode (DMU) Tool

There is a few restrictions with DMU  :

1- It does not support the migration of Oracle Database 12c Pluggable Databases (PDBs) to NLS_CHARACTERSET other than Unicode.

Oracle strongly recommends migrating the database character set to Unicode (AL32UTF8) NLS_CHARACTERSET before consolidating your databases.

2- You will receive the following error upon Initiating step 4 "convert database" using the DMU while being connected to PDB:

conversion feasibility test failed . the migration target character set is different from the CDB root character set.

To go from a non-Unicode CDB with (also non-Unicode) PDB's the steps are:
* Create a new Unicode (AL32UTF8) CDB
* Use the DMU to scan the non-Unicode PDB's and resolve any reported convertibility issues while it is still plugged into the original non-Unicode CDB.
* Unplug the PDB to be migrated and plug it into the target Unicode AL32UTF8 CDB (this will put the PDB into restricted mode due to the character set incompatibility).
* Use the DMU tool to convert the non-Unicode PDB to Unicode once plugged in the target Unicode AL32UTF8 CDB (= finish the conversion).

3- DMU does not support the migration of Oracle Database 12c container database (CDB) to any NLS_CHARACTERSET ( as this is not needed).

You will receive the following error upon connecting to CDB using the DMU :

Encountered an error while checking database's compatibility: Migration of container databases (CDB) is not supported.


The export/import migration methods could be used to overcome these limitations.

You can use Data Pump to migrate all, or portions of, a database from a non-CDB into a PDB, between PDBs within the same or different CDBs, and from a PDB into a non-CDB. 
In general, using Data Pump with PDBs is identical to using Data Pump with a non-CDB.

Note: In Oracle Database 12c Release 1 (12.1), Data Pump does not support any CDB-wide operations. Data Pump issues the following warning if you are connected to the root or seed database of a CDB:

ORA-39357: WARNING: Oracle Data Pump operations are not typically needed when connected to the root or seed of a container database.

See Also: http://docs.oracle.com/database/121/SUTIL/GUID-45B17B65-20F2-4128-9A39-B1B0F5E323BB.htm#SUTIL4334
Using Data Pump With CDBs


If you cannot migrate your existing databases prior to consolidation, then you have to partition them into sets with plug-in compatible database NLS_CHARACTERSET and plug each set into a separate CDB with the appropriate superset NLS_CHARACTERSET.

For example, if you have US7ASCII, WE8ISO8859P1, WE8MSWIN1252, WE8ISO8859P15, JA16SJISTILDE, JA16EUC, KO16KSC5601, KO16MSWIN949, UTF8 and AL32UTF8 NLS_CHARACTERSET databases that you want to consolidate, you need to consolidate as follows:

- US7ASCII, WE8ISO8859P1, and WE8MSWIN1252 into a WE8MSWIN1252 CDB
- WE8ISO8859P15 into a WE8ISO8859P15 CDB
- JA16SJISTILDE into a JA16SJISTILDE CDB 
- JA16EUC into a JA16EUC CDB  
- KO16KSC5601, KO16MSWIN949 into a KO16MSWIN949 CDB  
- UTF8 and AL32UTF8 into an AL32UTF8 CDB

Or use the DMU tool ( see Note 1272374.1 The Database Migration Assistant for Unicode (DMU) Tool ) to migrate the PDB to AL32UTF8 NLS_CHARACTERSET and use an AL32UTF8 NLS_CHARACTERSET CDB  

Note that the DMU tool cannot convert a non-Unicode CDB to AL32UTF8 as this is not needed. 
You will receive the following error upon connecting to CDB using the DMU : Encountered an error while checking database's compatibility: Migration of container databases (CDB) is not supported.

To go from a non-Unicode CDB with (also non-Unicode) PDB's the steps are:
* Create a new Unicode (AL32UTF8) CDB
* Use the DMU to scan the non-Unicode PDB's and resolve any reported convertibility issues while it is still plugged into the original non-Unicode CDB.
* Unplug the PDB to be migrated and plug it into the target Unicode AL32UTF8 CDB (this will put the PDB into restricted mode due to the character set incompatibility).
* Use the DMU tool to convert the non-Unicode PDB to Unicode once plugged in the target Unicode AL32UTF8 CDB (= finish the conversion).

 Please make sure that if the NLS_NCHAR_CHARACTERSET is UTF8 but the CDB is using AL16UTF16 NLS_NCHAR_CHARACTERSET to change the NLS_NCHAR_CHARACTERSET to AL16UTF16 before consolidation (or inverse).

 

标签:oracle19c,set,CDB,character,CHARACTERSET,字符集,NLS,修改,PDB
来源: https://blog.csdn.net/jycjyc/article/details/112437718

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有