客服微信
本文为云贝教育 刘峰 原创,请尊重知识产权,转发请注明出处,不接受任何抄袭、演绎和未经注明出处的转载。
如果我们在 PDB 中创建服务,这些服务将在基于原始 PDB 的任何新 PDB 中重新创建。如果共享同一侦听器的多个 PDB 尝试使用相同的服务名称,则可能会出现问题。
为了演示这一点,请在现有 PDB 中创建一些新服务。
CONN / AS SYSDBA ALTER SESSION SET CONTAINER=pdb1; BEGIN DBMS_SERVICE.create_service('my_new_service_1','my_new_service_1'); DBMS_SERVICE.start_service('my_new_service_1'); DBMS_SERVICE.create_service('my_new_service_2','my_new_service_2'); DBMS_SERVICE.start_service('my_new_service_2'); END; / SELECT name FROM dba_services ORDER BY name; NAME ---------------------------------------------------------------- PDB1 my_new_service_1 my_new_service_2
现在在现有 PDB 的基础上创建一个新的 PDB。请注意,当我们切换到 PDB 时,服务名称已重复。
CONN / AS SYSDBA CREATE PLUGGABLE DATABASE pdb2 FROM pdb1; ALTER PLUGGABLE DATABASE pdb2 OPEN; ALTER SESSION SET CONTAINER=pdb2; SELECT name FROM dba_services ORDER BY name; NAME ---------------------------------------------------------------- PDB2 my_new_service_1 my_new_service_2
连接到服务总是将我们连接到原来的PDB,而我们无法切换到新PDB中的服务。
CONN sys/SysPassword1@//localhost:1521/my_new_service_1 AS SYSDBA SHOW CON_NAME CON_NAME ------------------------------ PDB1 SQL> CONN sys/SysPassword1@//localhost:1521/my_new_service_2 AS SYSDBA SHOW CON_NAME CON_NAME ------------------------------ PDB1 SQL> ALTER SESSION SET CONTAINER=pdb2 SERVICE=my_new_service_1; ERROR: ORA-44787: Service cannot be switched into.
解决方案是在 PDB 创建期间重命名服务,我们通过使用 CREATE PLUGGABLE DATABASE 语句的SERVICE_NAME_CONVERT 子句来完成此操作。与大多数转换参数一样,我们提供了一个以逗号分隔的列表,表示“from”和“to”转换值。
重新创建可插入数据库,但这次重命名服务。
CONN / AS SYSDBA -- Remove the PDB. ALTER PLUGGABLE DATABASE pdb2 CLOSE; DROP PLUGGABLE DATABASE pdb2 INCLUDING DATAFILES; -- Create the PDB, renaming the services. CREATE PLUGGABLE DATABASE pdb2 FROM pdb1 SERVICE_NAME_CONVERT=('my_new_service_1','my_new_service_1b','my_new_service_2','my_new_service_2b'); ALTER PLUGGABLE DATABASE pdb2 OPEN; -- Check the services. ALTER SESSION SET CONTAINER=pdb2; SELECT name FROM dba_services ORDER BY name; NAME ---------------------------------------------------------------- PDB2 my_new_service_1b my_new_service_2b SQL> -- Start the services. BEGIN DBMS_SERVICE.start_service('my_new_service_1b'); DBMS_SERVICE.start_service('my_new_service_2b'); END; /
新服务到位后,我们可以根据服务决定连接到哪个 PDB。
CONN sys/SysPassword1@//localhost:1521/my_new_service_1 AS SYSDBA SHOW CON_NAME CON_NAME ------------------------------ PDB1 SQL> CONN sys/SysPassword1@//localhost:1521/my_new_service_1b AS SYSDBA SHOW CON_NAME CON_NAME ------------------------------ PDB2 SQL> ALTER SESSION SET CONTAINER=pdb2 SERVICE=my_new_service_1b; Session altered. SQL>