oracle 12c连接pdb

Posted 会飞的板儿

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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:

[[email protected] ~]$ 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:

[[email protected] 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进行连接:

[[email protected] 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:

[[email protected] bin]$ srvctl add service -d cpdb -s das -pdb pdb01 -preferred cpdb1 -available cpdb2

  查看创建的service:

[[email protected] 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:

[[email protected] 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. 使用命令进行切换:

[[email protected] 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。

以上是关于oracle 12c连接pdb的主要内容,如果未能解决你的问题,请参考以下文章

Oracle 12C 创建用户连接pdb

oracle12C安装完成后,尝试用PLSQL连接PDB数据库,发现个问题PDB有没有SID?使用服务名来连接还是用SID?

oracle 12c jdbc连接pdb报错的问题

12c通过service 连接pdb

12c连接pdb的两种方法

Oracle 12c 多租户家族(12c 18c 19c)如何在 PDB 中添加 HR 模式