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

張衝andy發表於2017-05-06
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實用程式顯示可用的服務。
[oracle@12c01 ~]$ 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)
連線到資料庫的根容器和連線以前版本的單個資料庫例項相同。在資料庫伺服器上,您可以使用作業系統身份驗證。

方法一:

[oracle@12c01 ~]$ 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 sys/oracle@10.100.25.16: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 sys/oracle@10.100.25.16: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

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

相關文章