oracle 12c多租户下的日常操作变化
Oracle 12c创建用户时出现“ORA-65096: invalid common user or role name”的错误
在oracle中,引入了多租户概念,以前是一个instance对应一个database(单实例),或者多个instance对应一个database(RAC),现在一个实例可以对应多个database了,除了这个CDB(Container Database):数据库容器之外,还可以有很多个PD(Pluggable Database):可插拔数据库(一般来说大部分都是一个居多,测试环境除外),所有的操作都必须在特定的database之下,CDB只是维护了instance全局的数据字典。所以,需要切换到特定的上下文才能操作。
查看当前session所在的上下文:
查看所有的pdb也可以通过show pdbs:
Connected to:
Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 - Production
Version 18.3.0.0.0
SQL> show pdbs;
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 ORCLPDB READ WRITE NO
SQL>
切换PDB:
登录的时候指定PDB:
查看当前pdb:
SQL> show con_name;
CON_NAME
------------------------------
ORCLPDB
连接到PDB
当创建pdb之后,使用lsnrctl status命令可以看到多了一个以pdb为名的service,如下:
对于连接到PDB,只要指定service_name即可。
JDBC连接注意:
jdbc:oracle:thin:@//<host>:<port>/ServiceName,连接PDB就要使用这种。
或
jdbc:oracle:thin:@<host>:<port>:<SID>
可插接式数据库(PDB) 自动启动(这很重要,否则每次还要切换很麻烦)
默认情况下,在CDB 启动的时候,all 的PDB 都是mount状态。我们可以通过触发器来实现pdbs随cdb自动启动
[oracle@12c01 ~]$ sqlplus / as sysdba
SQL> show con_name
CON_NAME
------------------------------
CDB$ROOT
SQL>
CREATE OR REPLACE TRIGGER open_pdbs
AFTER STARTUP ON DATABASE
BEGIN
EXECUTE IMMEDIATE 'ALTER PLUGGABLE DATABASE ALL OPEN';
END open_pdbs;
/
Trigger created.
验证 PDB 自动启动:
SQL> startup;
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDB01 READ WRITE NO
12C cdb/pdb 配置监听
有时候动态注册不上,可以考虑静态注册:
接下来使用SID_LIST_LISTENER来进行静态注册服务。 SID_LIST_LISTENER= (SID_LIST= (SID_DESC = (GLOBAL_DBNAME = ora12c) #该服务是我配置的cdb信息 (SID_NAME = ora12c) ) (SID_DESC = (GLOBAL_DBNAME = pdborcl)#该服务是我配置的pdb信息 (SID_NAME = ora12c) ) )
pl/sql developer连接Oracle 12c R2 PDB报错ORA-28040/ORA-01017 invalid username/password; logon denied
今日测试升到18c之后出现,我本机没有问题,经查只有11.2.0.3及以上的版本的客户端才能连接12.2版本的服务端。
Client Version |
Server Version | ||||||
12.2.0#10 | 12.1.0 | 11.2.0 | 11.1.0 | 10.2.0 | 10.1.0 | 9.2.0 | |
12.2.0 | Yes | Yes | Yes | No | No | No#3 | No#3 |
12.1.0 | Yes | Yes | Yes | Was | MDS #7 | No#3 | No#3 |
11.2.0 | Yes#9 | Yes | Yes | Was | MDS #7 | No | Was #5 |
11.1.0 | No | Was | Was | Was | Was #7 | Was #6 | Was #5 |
10.2.0 | No | MDS #7 | MDS #7 | Was #7 | MDS | Was | Was #5 |
10.1.0#4 | No | No | Was #6 | Was #6 | Was | Was | Was |
9.2.0 | No | No#8 | Was #5 | Was #5 | Was #5 | Was | Was |
Key:
Yes Supported ES Supported but fixes only possible for customers with Extended Support . LES or MDS Supported but fixes only possible for customer with a valid Limited Extended Support or Market-Driven Support contract respectively. Was Was a supported combination but one of the releases is no longer covered by any of Premier Support, Primary Error Correct support, Extended Support, nor Extended Maintenance Support. Fixes are no longer possible. No Has never been Supported
Specific Notes:
#1 - See Note:207319.1#2 - An ORA-3134 error is incorrectly reported if a 10g client tries to connect to an 8.1.7.3 or lower server. See Note:3437884.8 .#3 - An ORA-3134 error is correctly reported when attempting to connect to this version.#4 - There are problems connecting from a 10g client to 8i/9i where one is EBCDIC based. See Note:3564573.8#5 - For connections between 10.2 (or higher) and 9.2 the 9.2 end MUST be at 9.2.0.4 or higher. Connections between 10.2 (or higher) and 9.2.0.1, 9.2.0.2 or 9.2.0.3 have never been supported.#6 - For connections between 11.1 (or higher) database server and 10.1 / 10.2 database server across a database link the 10g end MUST be at 10.1.0.5 / 10.2.0.2 (or higher) respectively in order to use PLSQL between those versions. (This does not apply to normal 11g clients to 10g database server only server to server and a few very specific client products, such as Oracle Forms). See Note:4511371.8 for more details.#7 - For database link connections between 11.1 (or higher) and 10.2 the 10g end MUST be at 10.2.0.2 (or higher) in order to use PLSQL between those versions. See Note:4511371.8 for more details.#8 - Attempting to connect from 9.2 to 12.1 will fail with an "ORA-28040: No matching authentication protocol" error.#9 - 11.2.0.3 or 11.2.0.4 only. We do not support any 11.2 client interoperability with Oracle Database Exadata Express Cloud Service#10 - Includes Oracle Database Exadata Express Cloud Service - see Note:2183770.1 for additional details
General Notes:
-
For database links between different Oracle versions connections must be supported in BOTH directions in the matrix above.
eg: As 11.2 -> 10.1 is not supported then database links between these version are not supported in either direction. -
Unsupported combinations may appear to work but can encounter errors for particular operations. The fact that they appear to work should not be relied upon - issues on unsupported combinations will not be investigated.
-
Since new database servers are compatible with a limited set of older OCI clients, it may not be necessary to upgrade the client software when upgrading the database. However, some new features may not work without upgrading the client software. For example, an Oracle 10.2 client is able to connect to an 11.2 database, but is not able to take advantage of newer features such as Client Result Cache (introduced in 11.1).
-
Oracle Applications , or other Oracle products, may have supported configurations not listed in the matrix above.
-
The matrix above also applies between different platforms and between 32/64 bit releases of Oracle client / server except where any Oracle platform desupport notice indicates otherwise .
-
Unix BEQUEATH (BEQ) connections are NOT supported between different releases. eg: Client 10.2 is not supported to make an Oracle Net connection to a 11.2 server using the BEQ protocol adapter regardless of the interoperability support listed above. See Note:364252.1 for more details.