oracle 12c連接pdb


12c中,如何連接pluggable database:

  1. 使用默認的service連接pdb,創建pdb之后,在監聽中自動添加以pdb為名的service;
  2. 用戶在cluster中創建service,用戶使用srvctl命令創建一個service並且關系到pdb上;
  3. 使用命令alter session set container=pdb;
  4. 使用Enterprise Manager Express。

 1. 使用默認service連接pdb:

  當創建pdb之后,使用lsnrctl status命令可以看到多了一個以pdb為名的service,如下的pdb01:

[oracle@ora12c ~]$ lsnrctl status

LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 12-MAY-2017 15:33:43

Copyright (c) 1991, 2016, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=ora12c)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 12.2.0.1.0 - Production
Start Date                12-MAY-2017 15:32:16
Uptime                    0 days 0 hr. 1 min. 26 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/12.2.0/db_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/ora12c/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ora12c)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Services Summary...
Service "4d852a2714024610e0537838a8c07c53" has 1 instance(s).
  Instance "db12g", status READY, has 1 handler(s) for this service...
Service "db12g" has 1 instance(s).
  Instance "db12g", status READY, has 1 handler(s) for this service...
Service "db12gXDB" has 1 instance(s).
  Instance "db12g", status READY, has 1 handler(s) for this service...
Service "pdb01" has 1 instance(s). Instance "db12g", status READY, has 1 handler(s) for this service...
The command completed successfully

  這里修改tnsname.ora這個文件,添加一個pdb的記錄,就可以連接pdb:

[oracle@ora12c admin]$ vi tnsnames.ora 
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/12.2.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.

LISTENER_DB12G =
  (ADDRESS = (PROTOCOL = TCP)(HOST = ora12c)(PORT = 1521))


DB12G =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = ora12c)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = db12g)
    )
  )

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

  使用該service進行連接:

[oracle@ora12c admin]$ sqlplus scott/tiger@pdb01

SQL*Plus: Release 12.2.0.1.0 Production on Fri May 12 15:47:26 2017

Copyright (c) 1982, 2016, Oracle.  All rights reserved.


Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

SQL> show con_name

CON_NAME
------------------------------
PDB01

2. 使用srvctl命令在群集中添加服務連接pdb(這種方式應用於RAC環境):

  創建service,其中cdb名稱為cpdb,pdb名稱為pdb01,service為das,首選節點實例名稱為cpdb1,次選節點實例名稱為cpdb2:

[oracle@node1 bin]$ srvctl add service -d cpdb -s das -pdb pdb01 -preferred cpdb1 -available cpdb2

  查看創建的service:

[oracle@node1 bin]$ srvctl config service –d <databasename> -s <servicename>

  同樣添加tnsname.ora記錄:

das =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = scan-ip)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = das)
    )
  )

  啟動service:

[oracle@nsnode1 bin]$ srvctl start service -d cpdb -service das

  測試連接:

SQL> connect sys/oracle@das AS SYSDBA

Connected.

SQL> SHOW CON_ID;

CON_ID

3

SQL> SHOW CON_NAME;

CON_NAME

PDB01

3. 使用命令進行切換:

[oracle@node1 bin]$ sqlplus / as sysdba

SQL*Plus: Release 12.1.0.1.0 Production on Wed May 12 14:56:27 2017

Copyright (c) 1982, 2017, Oracle. All rights reserved. 

Connected to:

Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production

With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,

Advanced Analytics and Real Application Testing options
SQL> show con_name;

CON_NAME

CDB$ROOT

SQL> ALTER SESSION SET CONTAINER = PDB01;

Session altered.

SQL> SHOW CON_NAME;

CON_NAME

PDB01

4.使用Enterprise Manager Express進行連接:

  在使用之前檢查是否為EM配置了端口,需要為EM配置端口:

SQL> select dbms_xdb_config.gethttpsport from dual;

GETHTTPSPORT
------------
           0

SQL> exec dbms_xdb_config.sethttpsport(5500);

PL/SQL procedure successfully completed.

SQL> select dbms_xdb_config.gethttpsport from dual;

GETHTTPSPORT
------------
        5500

  切換到pdb,為pdb配置EM端口:

SQL> alter session set container = pdb01;

Session altered.

SQL> select dbms_xdb_config.gethttpport from dual;

 GETHTTPPORT

       5051

  然后使用EM和配置的端口連接pdb。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM