ORACLE 12C PDB 维护基础介绍

简介: 发表于 2013 年 05 月 23 日 由 惜分飞 联系:手机(13429648788) QQ(107644445) 链接:http://www.


联系:手机(13429648788) QQ(107644445)

链接:http://www.xifenfei.com/4432.html

标题:ORACLE 12C PDB 维护基础介绍

作者:惜分飞©版权所有[文章允许转载,但必须以链接方式注明源地址,否则追究法律责任.]

CDB和PDB是ORACLE 12C一个很亮的新特性,由于他们的引入导致传统的ORACLE数据库管理理念不少发生了改变,这里列举了部分最基本的cdb和pdb管理方式
cdb和pdb关系图

ORACLE 12C版本

SQL> select * from v$version;
 
BANNER                                                                               CON_ID
-------------------------------------------------------------------------------- ----------
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production              0
PL/SQL Release 12.1.0.1.0 - Production                                                    0
CORE    12.1.0.1.0      Production                                                        0
TNS for Linux: Version 12.1.0.1.0 - Production                                            0
NLSRTL Version 12.1.0.1.0 - Production                                                    0

启动关闭pdb

SQL> startup
ORACLE instance started.
 
Total System Global Area  597098496 bytes
Fixed Size                  2291072 bytes
Variable Size             272632448 bytes
Database Buffers          314572800 bytes
Redo Buffers                7602176 bytes
Database mounted.
Database opened.
SQL> select con_id,dbid, NAME ,OPEN_MODE from v$pdbs;
 
     CON_ID       DBID NAME                           OPEN_MODE
---------- ---------- ------------------------------ ----------
          2 4048821679 PDB$SEED                       READ ONLY
          3 3313918585 PDB1                           MOUNTED
          4 3872456618 PDB2                           MOUNTED
 
SQL> alter PLUGGABLE database pdb1 open ;
 
Pluggable database altered.
 
SQL> select con_id,dbid, NAME ,OPEN_MODE from v$pdbs;
 
     CON_ID       DBID NAME                           OPEN_MODE
---------- ---------- ------------------------------ ----------
          2 4048821679 PDB$SEED                       READ ONLY
          3 3313918585 PDB1                           READ WRITE
          4 3872456618 PDB2                           MOUNTED
 
SQL> alter PLUGGABLE database pdb1 close ;
 
Pluggable database altered.
 
SQL> select con_id,dbid, NAME ,OPEN_MODE from v$pdbs;
 
     CON_ID       DBID NAME                           OPEN_MODE
---------- ---------- ------------------------------ ----------
          2 4048821679 PDB$SEED                       READ ONLY
          3 3313918585 PDB1                           MOUNTED
          4 3872456618 PDB2                           MOUNTED
 
SQL> alter PLUGGABLE database all open ;
 
Pluggable database altered.
 
SQL> select con_id,dbid, NAME ,OPEN_MODE from v$pdbs;
 
     CON_ID       DBID NAME                           OPEN_MODE
---------- ---------- ------------------------------ ----------
          2 4048821679 PDB$SEED                       READ ONLY
          3 3313918585 PDB1                           READ WRITE
          4 3872456618 PDB2                           READ WRITE
 
SQL> alter PLUGGABLE database all close ;
 
Pluggable database altered.
 
SQL> select con_id,dbid, NAME ,OPEN_MODE from v$pdbs;
 
     CON_ID       DBID NAME                           OPEN_MODE
---------- ---------- ------------------------------ ----------
          2 4048821679 PDB$SEED                       READ ONLY
          3 3313918585 PDB1                           MOUNTED
          4 3872456618 PDB2                           MOUNTED
 
SQL> alter session set container=pdb1;
 
Session altered.
 
SQL> startup
Pluggable Database opened.
SQL>  select con_id,dbid, NAME ,OPEN_MODE from v$pdbs;
 
     CON_ID       DBID NAME                           OPEN_MODE
---------- ---------- ------------------------------ ----------
          3 3313918585 PDB1                           READ WRITE

pdb的管理可以在cdb中进行也可以在pdb中进行,如果是cdb中进行,需要PLUGGABLE关键字,如果是pdb中直接和普通数据库一样

登录pdb

[oracle@xifenfei ~]$ lsnrctl status
 
LSNRCTL for Linux: Version 12.1.0.1.0 - Production on 12-MAY-2013 08:07:02
 
Copyright (c) 1991, 2013, Oracle.  All rights reserved.
 
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=xifenfei)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 12.1.0.1.0 - Production
Start Date                11-MAY-2013 18:30:54
Uptime                    0 days 13 hr. 36 min . 8 sec
Trace Level               off
Security                  ON : Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/grid/product/12.1/network/admin/listener.ora
Listener Log File         /u01/app/grid/diag/tnslsnr/xifenfei/listener/alert/log.xml
Listening Endpoints Summary...
   (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)( KEY =EXTPROC1521)))
   (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=xifenfei)(PORT=1521)))
   (DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=xifenfei)(PORT=5500))
(Security=(my_wallet_directory=/u01/oracle/12.1/db_1/admin/cdb/xdb_wallet))(Presentation=HTTP)(Session=RAW))
Services Summary...
Service "+ASM" has 1 instance(s).
   Instance "+ASM" , status READY, has 1 handler(s) for this service...
Service "cdb" has 1 instance(s).
   Instance "cdb" , status READY, has 1 handler(s) for this service...
Service "cdbXDB" has 1 instance(s).
   Instance "cdb" , status READY, has 1 handler(s) for this service...
Service "pdb1" has 1 instance(s).
   Instance "cdb" , status READY, has 1 handler(s) for this service...
Service "pdb2" has 1 instance(s).
   Instance "cdb" , status READY, has 1 handler(s) for this service...
The command completed successfully
[oracle@xifenfei ~]$ tnsping pdb1
 
TNS Ping Utility for Linux: Version 12.1.0.1.0 - Production on 12-MAY-2013 08:07:09
 
Copyright (c) 1997, 2013, Oracle.  All rights reserved.
 
Used parameter files:
 
 
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = xifenfei)
(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = pdb1)))
OK (20 msec)
[oracle@xifenfei ~]$ sqlplus sys/xifenfei@pdb1 as sysdba
 
SQL*Plus: Release 12.1.0.1.0 Production on Sun May 12 08:08:02 2013
 
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, Automatic Storage Management, OLAP, Advanced Analytics
and Real Application Testing options
 
SQL> show con_name;
 
CON_NAME
------------------------------
PDB1
 
 
[oracle@xifenfei ~]$ sqlplus / as sysdba
 
SQL*Plus: Release 12.1.0.1.0 Production on Sun May 12 08:09:14 2013
 
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, Automatic Storage Management, OLAP, Advanced Analytics
and Real Application Testing options
 
SQL> alter session set container=pdb1;
 
Session altered.
 
SQL> show con_name;
 
CON_NAME
------------------------------
PDB1

pdb可以通过alter session container进入也可以直接通过tns方式登录

创建用户

SQL> show con_name;
 
CON_NAME
------------------------------
CDB$ROOT
 
SQL> select con_id,dbid, NAME ,OPEN_MODE from v$pdbs;
 
     CON_ID       DBID NAME                           OPEN_MODE
---------- ---------- ------------------------------ ----------
          2 4048821679 PDB$SEED                       READ ONLY
          3 3313918585 PDB1                           READ WRITE
          4 3872456618 PDB2                           MOUNTED
 
SQL> create user xff identified by xifenfei;
create user xff identified by xifenfei
             *
ERROR at line 1:
ORA-65096: invalid common user or role name
 
 
SQL> !oerr ora 65096
65096, 00000, "invalid common user or role name"
// *Cause:  An attempt was made to create a common user or role with a name
//          that wass not valid for common users or roles.  In addition to
//          the usual rules for user and role names, common user and role
//          names must start with C## or c## and consist only of ASCII
//          characters.
// * Action : Specify a valid common user or role name .
//
 
SQL> create user c##xff identified by xifenfei;
 
User created.
 
SQL> SELECT USERNAME,CON_ID,USER_ID FROM CDB_USERS WHERE USERNAME= 'C##XFF' ;
 
USERNAME       CON_ID    USER_ID
---------- ---------- ----------
C##XFF              1        103
C##XFF              3        104
 
SQL> alter session set container=pdb1;
 
Session altered.
 
SQL> show con_name
 
CON_NAME
------------------------------
PDB1
SQL> create user xff identified by xifenfei;
 
User created.
 
SQL> create user c##abc identified by xifenfei;
create user c##abc identified by xifenfei
             *
ERROR at line 1:
ORA-65094: invalid local user or role name

创建用户默认的是container=all,在cdb中只能创建全局用户(c##开头),会在cdb和所有的pdb中创建该用户(但是pdb中的全局用户需要另外授权才能够在pdb中访问)。在pdb中只能创建的用户为本地用户

用户授权

SQL> grant connect to c##xff;
 
Grant succeeded.
 
SQL> select GRANTEE,con_id from cdb_ROLE_PRIVS where GRANTED_ROLE= 'CONNECT' AND GRANTEE= 'C##XFF' ;
 
GRANTEE                            CON_ID
------------------------------ ----------
C##XFF                                  1
 
SQL> grant resource to c##xff container= all ;
 
Grant succeeded.
 
SQL>  select GRANTEE,con_id from cdb_ROLE_PRIVS where GRANTED_ROLE= 'RESOURCE' AND  GRANTEE= 'C##XFF' ;
 
GRANTEE                            CON_ID
------------------------------ ----------
C##XFF                                  1
C##XFF                                  3

用户授权默认情况下是只会给当前container,在cdb中也可以指定container=all,对所有open的pdb且存在该用户都进行授权

修改参数

SQL> alter system set open_cursors=500 container= all ;
 
System altered.
 
SQL> conn sys/xifenfei@pdb1 as sysdba
Connected.
SQL> show parameter open_cursors;
 
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
open_cursors                         integer     500
SQL>  alter system set open_cursors=100;
  alter system set open_cursors=100
*
ERROR at line 1:
ORA-01219: database or pluggable database not open : queries allowed on fixed
tables or views only
 
 
SQL> alter database open ;
 
Database altered.
 
SQL> alter system set open_cursors=100;
 
System altered.
 
SQL>  show parameter open_cursors;
 
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
open_cursors                         integer     100
SQL> conn / as sysdba
Connected.
SQL> show parameter open_cursors;
 
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
open_cursors                         integer     500

这里可以看到在cdb中修改,pdb会继承进去;如果在pdb中修改会覆盖pdb从cdb中继承的参数含义

转载自http://www.xifenfei.com/4482.html

目录
相关文章
|
Oracle 关系型数据库 数据库
百度搜索:蓝易云【docker部署并配置oracle12c的cdb和pdb教程!】
以上是使用Docker部署和配置Oracle 12c CDB和PDB的简要教程。请注意,这只是一个概述,并且可能需要根据你的实际情况进行适当的调整和配置。建议参考Oracle官方文档和相关资源,以获得更详细和全面的指导。
142 2
|
5月前
|
存储 Oracle 关系型数据库
Oracle 12c支持哪些数据类型?
【7月更文挑战第20天】Oracle 12c支持哪些数据类型?
102 2
|
5月前
|
SQL Oracle 关系型数据库
Oracle 12c有哪些新特性?
【7月更文挑战第20天】Oracle 12c有哪些新特性?
77 2
|
7月前
|
监控 Oracle 关系型数据库
Oracle 12c的Adaptive执行计划:数据的“聪明导航员”
【4月更文挑战第19天】Oracle 12c的Adaptive执行计划是数据库查询的智能优化工具,能根据实际运行情况动态调整执行策略。它像一个聪明的导航系统,不仅生成初始执行计划,还能实时监控并适应统计信息和资源变化,例如自动切换索引或调整并行度。此外,它支持自适应连接和统计信息收集,提升处理复杂查询和变化数据环境的能力。数据管理员应充分利用这一特性来优化查询性能和用户体验。
|
7月前
|
存储 NoSQL Oracle
Oracle 12c的内存列存储:数据的“闪电侠”
【4月更文挑战第19天】Oracle 12c的内存列存储以超高速度革新数据处理,结合列存储与内存技术,实现快速查询与压缩。它支持向量化查询和并行处理,提升效率,但需合理配置以平衡系统资源。作为数据管理员,应善用此功能,适应业务需求和技术发展。
|
7月前
|
存储 Oracle 关系型数据库
Oracle 12c的多重索引:数据的“多维导航仪”
【4月更文挑战第19天】Oracle 12c的多重索引提升数据查询效率,如同多维导航仪。在同一表上创建针对不同列的多个索引,加速检索过程。虽然过多索引会增加存储和维护成本,但合理选择和使用索引策略,结合位图、函数索引等高级特性,能优化查询,应对复杂场景。数据管理员应善用这些工具,根据需求进行索引管理,支持企业数据分析。
|
7月前
|
存储 Oracle 安全
Oracle 12c的不可见字段:数据的“隐形斗篷”
【4月更文挑战第19天】Oracle 12c引入了不可见字段,这是一种隐藏数据列的特性,用于增强数据安全性和实现业务逻辑。不可见字段在常规查询中不显示,但参与数据操作,适合存储敏感信息或内部元数据。创建时只需在列定义中指定“INVISIBLE”属性。虽然有其限制,如特定查询可能暴露,但正确使用能有效提升数据安全性。了解和利用这一功能对数据管理员至关重要。
|
7月前
|
SQL Oracle 关系型数据库
Oracle 12c的TOP N语句:数据排名的“快速通道”
【4月更文挑战第19天】Oracle 12c的TOP N语句是用于快速获取数据集排名前N的记录的SQL查询方法,特别适合寻找最具代表性的数据。通过指定排序条件和数量,TOP N能高效筛选出所需信息,例如最高销售额产品或最大访问量网页。在Oracle 12c中,查询优化器对TOP N查询进行了优化,保证快速返回结果,并提供丰富的排序和过滤选项。基本用法如`SELECT ... ORDER BY ... FETCH FIRST N ROWS ONLY`,还可结合`OFFSET`进行分页查询或用`WITH TIES`保持结果完整性。掌握TOP N语句能提升数据分析效率,助力企业决策。
|
7月前
|
存储 Oracle 关系型数据库
Oracle 12c的临时UNDO:数据的“临时保镖”
【4月更文挑战第19天】Oracle 12c引入的临时UNDO为数据安全提供新保障。它为临时操作和特定事务提供独立UNDO空间,避免共享UNDO带来的性能瓶颈和管理复杂性。临时UNDO随事务开始分配,记录修改历史,事务结束后自动释放。优点包括提高性能、简化管理及保证数据一致性。但需注意手动配置、监控和优化,以防长时间占用资源。了解其工作原理和最佳实践是提升数据库性能的关键。
|
7月前
|
存储 Oracle 数据管理
Oracle 12c的自动数据优化(ADO)与热图:数据管理的“瘦身”与“透视”艺术
【4月更文挑战第19天】Oracle 12c的ADO和热图技术革新数据管理。ADO智能清理无用数据,优化存储,提升查询速度,实现数据"瘦身";热图则以直观的视觉表示展示数据分布和状态,助力识别性能瓶颈,犹如数据的"透视"工具。这两项技术结合,强化数据管理,为企业业务发展保驾护航。