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。

时间: 2024-10-05 19:38:05

oracle 12c连接pdb的相关文章

oracle 12c 创建PDB用户即Local User (PDB与CDB)

Oracle 12C用户创建与表空间分配 数据库安装完成后,首先用系统用户链接数据库容器(CDB), 在数据库容器(CDB)中创建表空间‘imei’ SQL>create tablespace iemi datafile'E:\Oracle_DB\ cdb_iemi.dbf'size 10240m autoextend on next 200m; 表空间已创建. 接下来在Oracle 12C数据库中创建用户时会报ORA-65096错误. SQL> create user imei identi

12c连接pdb的两种方法

连接可插拔数据库的两种方法 <roidb01:cdb:/home/oracle>$sqlplus / as sysdba SQL*Plus: Release 12.1.0.2.0 Production on Sat Jan 20 17:59:56 2018 Copyright (c) 1982, 2014, Oracle. All rights reserved. Connected to: Oracle Database 12c Enterprise Edition Release 12.1

Oracle 12c创建PDB用户并设置默认表空间

Oracle12c 中,增加了可插接数据库的概念,即PDB,允许一个数据库容器(CDB)承载多个可插拔数据库(PDB).CDB全称为 ContainerDatabase,中文翻译为数据库容器,PDB全称为PluggableDatabase,即可插拔数据库.下面是官方文档关于CDB与PDB的关系图. 在CDB中,只能创建以c##或C##开头的用户,如果不加c##,则会提示错误“ORA-65096:公用用户名或角色名无效”,只有在PDB数据库中才能创建我们习惯性命名的用户,oracle称之为Loca

Oracle 12c 用户创建、角色、权限

一.创建用户 创建用户默认的是container=all,在cdb中只能创建全局用户(c##开头),会在cdb和所有的pdb中创建该用户(但是pdb中的全局用户需要另外授权才能够在pdb中访问).在pdb中只能创建的用户为本地用户 SQL> show con_name; CON_NAME ------------------------------ CDB$ROOT SQL> create user user1 identified by user1; create user user1 id

Oracle 12c在SQL Devolper中添加cdb和pdb连接

Oracle 12c如果按默认流程安装的话会有一个叫orcl的cdb容器和一个叫pdborcld的pdb容器 一.连接名为orcl的cdb容器 连接名:localorcl 用户名:SYS 口令:Oracle12csys 连接类型:基本 角色:DBA 主机名:localhost 端口:1521 SID:orcl 点击测试,状态为成功即可连接 二.连接名为pdborcld的pdb容器(预先配置好了L/H这个用户) 连接名:localpdb 用户名:L 口令:H 连接类型:基本 角色:默认 主机名:l

Oracle 12C 创建用户连接pdb

测试环境: C:\ora12c\product\12.1.0\dbhome_1\BIN>sqlplus.exe /nolog SQL*Plus: Release 12.1.0.1.0 Production on 星期二 9月 20 03:50:23 2016 Copyright (c) 1982, 2013, Oracle. All rights reserved. SQL> conn /as sysdba 已连接. SQL> show pdbs; CON_ID CON_NAME OPE

Oracle 12c JDBC方式连接PDB数据库

1.配置监听 这里假定CDB数据库名为ORCL,PDB在CDB下面名称为PDBORCLlistener.ora添加(#后面为注释,不要添加进去) SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = ORCL) (SID_NAME = ORCL) #这里是SID名 ) (SID_DESC = (GLOBAL_DBNAME = PDBORCL)#这里是PDB数据库名 (SID_NAME = ORCL) #这里是SID名 ) ) t

Kettle连接Oracle 12c

安装Oracle我用的是Win10 64位,官网下载64位 Oracle 12c,两个文件.解压第一个文件之后安装,但是安装到一半错误,提示缺失文件.后来发现原来两个文件要单独解压,解压后根据目录合并在一起.再次安装,安装到88%卡住不动了.我以为安装又失败了,就关了,但是发现可以用,就这么用吧. 创建用户Oracle数据库分为CDB和PDB,他们之间的关系,想了解可以查相关资料,不在此详述.简单来说CDB是一个数据库容器,PDB是可插拔数据库.默认登陆为CDB,只能创建COMMON用户.COM

浅谈oracle 12C的新特性-CDB和PDB

最近看到好多人都在尝试oracle中的12C新特性-容器数据库,今年3月orcle退出了Release2版本,可以算是一个稳定版本了.下午着手尝试了一下,还是蛮不错得 1.前言 CDB与PDB是Oracle 12C引入的新特性,在ORACLE 12C数据库引入的多租用户环境(Multitenant Environment)中,允许一个数据库容器(CDB)承载多个可插拔数据库(PDB).CDB全称为ContainerDatabase,中文翻译为数据库容器,PDB全称为Pluggable Datab