[Oracle] - Connect to a PDB of Oracle12c

Story about CDB and PDB

Oracle12c has a new feature and definition of CDB and PDB. If you first use 12c you will get confused like me. So that is necessary to know some basic definitions before you start. Oracle's official document is always the best material.

What is CBD and PDB and why introduce them?


Login a CBD

[oracle@ol65 ~]$ <strong>sqlplus /nolog</strong>

SQL*Plus: Release 12.1.0.2.0 Production on Mon Oct 27 23:07:56 2014

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

SQL> conn sys@orcl as sysdba
Enter password: 
Connected.
SQL> sho con_name

CON_NAME
------------------------------
CDB$ROOT
SQL> 
** sho con_name - show current container name. Root container is always called CDB#ROOT.

How many PDBs in your root container now?

SQL> sho pdbs

    CON_ID CON_NAME			  OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
	 2 PDB$SEED			  READ ONLY  NO
	 3 PDBORCL			  MOUNTED
SQL> 

** PDB$SEED is a seed PDB, as its name Oracle12c will take is
    Default status of a new PDB is mounted. It's not running, you have to 'open' it before you start using it.

Open a PDB

You must have sysdba privilege.
SQL> alter pluggable database PDBORCL open;

Pluggable database altered.

SQL> sho pdbs

    CON_ID CON_NAME			  OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
	 2 PDB$SEED			  READ ONLY  NO
	 3 PDBORCL			  READ WRITE NO
SQL> 

Login a PDB

SQL> sho con_name

CON_NAME
------------------------------
CDB$ROOT
SQL> alter session set container=PDBORCL;

Session altered.

SQL> sho con_name

CON_NAME
------------------------------
PDBORCL
SQL> 
Now you login a PDB. Now you can create a new user as you operate a Oracle DB before 12c. This user is not common user. It's a user for this PDB. You also can understand PDB as a general DB of the version before 12c.

Login Root Container again and Stop a PDB

SQL> conn sys as sysdba
Enter password: 
Connected.
SQL> alter pluggable database PDBORCL close immediate;

Pluggable database altered.

SQL> 

Register a Entry of a PDB

Edit config file /$ORACLE_HOME/network/admin/tnsnames.ora.
ORCL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl.localdomain)
    )
  )

PDBORCL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = pdborcl.localdomain)
    )
  )
Save and quit. Go to open this PDB again. Now you can access PDBORCL by service name.
[oracle@ol65 admin]$ sqlplus sys@pdborcl as sysdba

SQL*Plus: Release 12.1.0.2.0 Production on Tue Oct 28 00:08:52 2014

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

Enter password: 

Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

SQL> 
And the most importance is that now you are able to remotely connect this PDB!

Now you application can use this DB as well.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值