oracle12c 新特性 CDB与PDB

时间:2021-01-23 16:48:54

12C的安装过程与11G的安装没有多大区别:

----------------
1.检查硬件条件
2.检查软件条件
3.系统相关配置
4.用户,组,安装目录创建
5.安装
-------------------

系统相关配置
1./etc/selinux/config
2.防火墙
3./etc/security/limits.conf
4./etc/sysctl.conf

关闭防火墙:

iptables -F
service iptables stop


4.用户,组,安装目录创建
groupadd -g 1000 oinstall
useradd -u 1000 oracle -g oinstall


mkdir -p /u01/app/oracle
mkdir -p /u01/app/oraInventory


chown -R oracle:oinstall /u01/app/oracle
chmod -R 775 /u01/app/oracle
chown -R oracle:oinstall /u01/app/oraInventory
chmod -R 775 /u01/app/oraInventory

环境变量:

export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/12.1.0/dbhome_1
export ORACLE_SID=orcl12c
export PATH=$ORACLE_HOME/bin:$PATH


centos-6.5依赖包安装:

rpm -q --queryformat "%{NAME}-%{VERSION}-%{RELEASE} (%{ARCH})\n" binutils \
compat-libcap1 \
compat-libstdc++ \
gcc \
gcc-c++ \
glibc \
glibc-devel \
ksh \
libgcc \
libstdc++ \
libstdc++-devel \
libaio \
libaio-devel \
libXext \
libXtst \
libX11 \
libXau \
libxcb \
libXi \
make \
sysstat


------------------------------------------------

以上简单的介绍了12C的安装,下面介绍下新特性(网上参考而来):

首先我们先看下概念:

CDB组件(Components of a CDB)

一个CDB数据库容器包含了下面一些组件:

ROOT组件

ROOT又叫CDB$ROOT, 存储着ORACLE提供的元数据和Common User,元数据的一个例子是ORACLE提供的PL/SQL包的源代码,Common User 是指在每个容器中都存在的用户。

SEED组件

  Seed又叫PDB$SEED,这个是你创建PDBS数据库的模板,你不能在Seed中添加或修改一个对象。一个CDB中有且只能有一个Seed. 这个感念,个人感觉非常类似SQL SERVER中的model数据库。

PDBS

    CDB中可以有一个或多个PDBS,PDBS向后兼容,可以像以前在数据库中那样操作PDBS,这里指大多数常规操作。

这些组件中的每一个都可以被称为一个容器。因此,ROOT(根)是一个容器,Seed(种子)是一个容器,每个PDB是一个容器。每个容器在CDB中都有一个独一无二的的ID和名称。

很显然:12C可以创建一个与以前版本一样的数据库,但如果你建了一个空的cdb的话,那是没法用的,因为CDB中包括ROOT组件、SEED组件、PDBS组件,PDBS就是我们最终要用的数据库。


12C使用dbca 来创建并管理PDBS:

oracle12c 新特性  CDB与PDB

oracle12c 新特性  CDB与PDB

oracle12c 新特性  CDB与PDB

oracle12c 新特性  CDB与PDB

oracle12c 新特性  CDB与PDB

oracle12c 新特性  CDB与PDBPDB安装成功了,下面进入到数据库:


[oracle@orcl12c ~]$ sqlplus / as sysdba

SQL*Plus: Release 12.1.0.1.0 Production on Fri Sep 30 03:45:46 2016

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


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

SQL>
SQL>

查看数据库是否为CDB

SQL> select name,cdb ,open_mode ,con_id from v$database;

NAME CDB OPEN_MODE CON_ID
--------- --- -------------------- ----------
ORCL12C YES READ WRITE 0

SQL>

YES表示该数据库是CDB,如果是NO表示是NO-CDB(普通数据库)

查看当前容器(Container):

SQL> show con_name;

CON_NAME
------------------------------
CDB$ROOT
SQL>

&

SQL> select sys_context('userenv','con_name') "container DB" from dual;

container DB
--------------------------------------------------------------------------------
CDB$ROOT

SQL>
查看CDB容器中的PDBS信息:

SQL> select con_id,dbid,guid,name,open_mode from v$pdbs;

CON_ID DBID GUIDNAME OPEN_MODE
-------- ------------- -------------------------------- ---------- ----------
2 4166529792 3DB521B3D18E17AEE053C938A8C02EFF PDB$SEED READ ONLY
3 3985361781 3DB59EF2EF6B22F7E053C938A8C07EE2 PDB01 READ WRITE

SQL> <span style="font-weight: bold;">
</span>

启动与关闭PDB数据库:

方式1:

SQL> alter pluggable database pdb01 open;
alter pluggable database pdb01 open
*
ERROR at line 1:
ORA-65019: pluggable database PDB01 already open


SQL> alter pluggable database pdb01 down;
alter pluggable database pdb01 down
*
ERROR at line 1:
ORA-00922: missing or invalid option


SQL> alter pluggable database pdb01 shutdown;
alter pluggable database pdb01 shutdown
*
ERROR at line 1:
ORA-00922: missing or invalid option


SQL> alter pluggable database pdb01 close;

Pluggable database altered.

SQL> alter pluggable database pdb01 open;

Pluggable database altered.

SQL> <strong>
</strong>
方式2:

SQL> alter session set container=pdb01;

Session altered.

SQL> startup
ORA-65019: pluggable database PDB01 already open


SQL> shutdown
Pluggable Database closed.
SQL> <strong>
</strong>

在容器间切换
SQL> alter session set container=pdb01;

Session altered.

SQL> show con_name;

CON_NAME
------------------------------
PDB01
SQL> show con_id;

CON_ID
------------------------------
3
SQL> alter session set container=CDB$ROOT;

Session altered.

SQL> show con_name;

CON_NAME
------------------------------
CDB$ROOT
SQL> show con_id;

CON_ID
------------------------------
1
SQL>


关于pdb用户连接数据库:

主要配置两个文件:listener.ora和tnsnames.ora

listener.ora文件配置示例:

LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = orcl12c)(PORT = 1531))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1531))
)
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = orcl12c) #该服务是我配置的cdb信息
(SID_NAME = orcl12c)
)
(SID_DESC =
(GLOBAL_DBNAME = pdb01)#该服务是我配置的pdb信息
(SID_NAME = orcl12c)
)
)
ADR_BASE_LISTENER=/u01/app/oracle/product/12.1.0/dbhome_1

tnsnames.ora配置示例:

ORCL12C =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.201)(PORT = 1531))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl12c)
)
)

PDB01 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.201)(PORT = 1531))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = pdb01)
)

连接测试:

[oracle@orcl12c admin]$ sqlplus test/test@pdb01

SQL*Plus: Release 12.1.0.1.0 Production on Fri Sep 30 05:17:30 2016

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

Last Successful login time: Fri Sep 30 2016 05:10:55 -04:00

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

SQL> show user
USER is "TEST"
SQL> show con_name

CON_NAME
------------------------------
PDB01
SQL>