1. 程式人生 > >Oracle12c多租戶如何連接到CDB或PDB、CDB與PDB容器切換

Oracle12c多租戶如何連接到CDB或PDB、CDB與PDB容器切換

說明 sel ica 顯示數據 protoc oracl pro 其他 order by

Oracle 數據庫 12 c 多租戶選項允許單個容器數據庫 (CDB) 來承載多個單獨的可插拔數據庫 (PDB)。
那麽我們如何連接到容器數據庫 (CDB) 和可插拔數據庫 (PDB)。

1. V$SERVICES視圖可以顯示數據庫中的可用服務。
SQL> col pdb for a40
SQL> col name for a30;
SELECT name, pdb FROM v$services ORDER BY name;SQL>
NAME PDB
------------------------------ ----------------------------------------
SYS$BACKGROUND CDB$ROOT
SYS$USERS CDB$ROOT
andycdb CDB$ROOT
andycdbXDB CDB$ROOT
pdb01 PDB01

-- lsnrctl實用程序顯示可用的服務。
[[email protected]

/* */ ~]$ lsnrctl status
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=12c01)(PORT=1521)))
Services Summary...
Service "4ecf8621e3da38eee0531019640aa598" has 1 instance(s).
Instance "andycdb", status READY, has 1 handler(s) for this service...
Service "andycdb" has 1 instance(s).
Instance "andycdb", status READY, has 1 handler(s) for this service...
Service "andycdbXDB" has 1 instance(s).
Instance "andycdb", status READY, has 1 handler(s) for this service...
Service "pdb01" has 1 instance(s).
Instance "andycdb", status READY, has 1 handler(s) for this service...
The command completed successfully

2.直接連接到一個容器數據庫 (CDB)
連接到數據庫的根容器和連接以前版本的單個數據庫實例相同。在數據庫服務器上,您可以使用操作系統身份驗證。

方法一:

[[email protected] ~]$ sqlplus / as sysdba

方法二:

或者 tnsnames.ora 文件配置

ANDYCDB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 12c01)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = andycdb)
)
)

C:\Users\andy>sqlplus [email protected]

*/:1521/andycdb as sysdba

3.直接連接到一個可插拔的數據庫 (PDB)

tnsnames.ora 文件配置:

PDB01 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.100.25.16)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = pdb01)
)
)

C:\Users\andy>sqlplus [email protected]:1521/pdb01 as sysdba
SQL> show con_name
CON_NAME
------------------------------
PDB01
說明:PDB 具有 SYSDBA、 SYSOPER、 SYSBACKUP 或 SYSDG 特權的用戶可以連接到已關閉的 PDB。
PDB 的所有其他用戶(CONNECT SESSION權限的用戶)僅可以連接已經打開的PDB。


4. 容器之間切換

SQL> ALTER SESSION SET container=pdb01;
Session altered.
SQL> show con_name
CON_NAME
------------------------------
PDB01
SQL> alter session set container=cdb$root;
Session altered.
SQL> show con_name
CON_NAME
------------------------------
CDB$ROOT

Oracle12c多租戶如何連接到CDB或PDB、CDB與PDB容器切換