ORACLE 12C PDB 维护基础知识介绍

先说基本用法:
先按11G之前进行
conn / as sysdba;
create user test identifed by test;

ORA-65096: 公用用户名或角色名无效.

查官方文档得知“试图创建一个通用用户,必需要用C##或者c##开头”,这时候心里会有疑问,什么是common user?不管先建成功了再说
create C##user test identifed by test;
创建成功

SQL>show con_name;

CON_NAME
------------------------------
CDB$ROOT

selectcon_id,dbid,NAME,OPEN_MODEfromv$pdbs;

CON_ID DBID NAME OPEN_MODE

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

2 4066409480 PDB$SEED READ ONLY

3 2270995695 PDBORCL MOUNTED

SQL>alter session set container=PDBORCL;
这时再用create user test identifed by test;建立用户就可以了。

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中继承的参数含义

(0)

相关推荐

  • oracle 12c创建可插拔数据库(PDB)与用户详解

    前言 由于oracle 12c使用了CDB-PDB架构,类似于docker,在container-db内可以加载多个pluggable-db,因此安装后需要额外配置才能使用. 一.修改listener.ora , tnsnames.ora ###listener.ora### LISTENER = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) (CONNECT_DATA = (SERVICE_

  • oracle 12c因误删pdb数据文件导致整个数据库打不开的解决方法

    前言 最近因为一位同事误删了某个插件数据库(PDB)的数据文件,结果整个数据库,包括容器数据库(CDB),以及其他插件数据库都用不了了.无奈...通过尝试各种方法最终解决了,觉着有必要将解决的过程分享出来,方法大家参考学习,下面话不多说了,来一起看看详细的介绍吧. 方法如下: 1.用sys账号进入实例,可见容器数据库处于mounted状态:插在上面的所有PDB当然也都是mounted. sqlplus sys/pwd@orcl12c as sysdba; 2.试图打开CDB,提示有数据库文件未能

  • ORACLE 12C PDB 维护基础知识介绍

    先说基本用法: 先按11G之前进行 conn / as sysdba; create user test identifed by test; ORA-65096: 公用用户名或角色名无效. 查官方文档得知"试图创建一个通用用户,必需要用C##或者c##开头",这时候心里会有疑问,什么是common user?不管先建成功了再说 create C##user test identifed by test; 创建成功 SQL>show con_name; CON_NAME ----

  • java网络编程基础知识介绍

    网络基础知识 1.OSI分层模型和TCP/IP分层模型的对应关系 这里对于7层模型不展开来讲,只选择跟这次系列主题相关的知识点介绍. 2.七层模型与协议的对应关系 网络层 ------------ IP(网络之间的互联协议) 传输层 ------------ TCP(传输控制协议).UDP(用户数据报协议) 应用层 ------------ Telnet(Internet远程登录服务的标准协议和主要方式).FTP(文本传输协议).HTTP(超文本传送协议) 3.IP地址和端口号 1.ip地址用于

  • C# 最基础知识介绍--多态

    目录 一.C# 多态性 二.静态多态性 三.函数重载 四.C# 运算符重载 1.运算符重载的实现 2.可重载和不可重载运算符 五.动态多态性 前言:

  • ES6基础知识介绍

    目录 一.ECMAScript和JavaScript关系 二.let命令 三.const命令 四.变量的解构赋值 1.数组的解构赋值 2.对象的解构赋值 一.ECMAScript和JavaScript关系 JavaScript 的创造者 Netscape 公司,决定将 JavaScript 提交给标准化组织 ECMA,希望这种语言能够成为国际标准,但是JavaScript本身也已经被 Netscape 公司注册为商标,后面的标准都由ECMA制定,取名ECMAScript. 那么ES6这个版本引入

  • ASP.NET母版页基础知识介绍

    模板页是做什么的? 利用模板页可以方便快捷的创建统一风格的ASP.NET网站,并且容易管理和维护,提高了效率. 模板页为网页定义所需要的外观和标准,在母版的基础上创建包含显示内容的各个内容页.当用户请求内容页时,这些内容页与母版页合并,这样,模板页的布局与内容页的布局就可以组合在一起输出了. 模板页一般用来: 1.通过修改模板页来处理网页的通用功能. 2.可以方便的创建一组控件和代码,并应用于一组网页. 3.通过允许控制占位符控件的呈现方式,模板页可以在细节上控制最终页的布局. 模板页与普通页

  • PowerShell中的变量基础知识介绍

    本文介绍在PowerShell中,如何使用变量.变量可以存储程序中的数量,比如开发者的赋值.命令的执行结果等. 变量拿来干嘛的,不用我多说了,写过程序的兄弟们都知道:如果程序中没有变量,那真的就不能让程序了!连批处理里面都有变量了,那PowerShell中自然就更不能没有. 1.PowerShell中的变量都是对象 PowerShell中的变量是基于.NET Framework的,所以PowerShell中的变量跟.NET中的变量一样:都是对象,通通都是对象! 复制代码 代码如下: $i=1 $

  • PHP基础知识介绍

    php中的整形数是有符号的,不能表示无符号整数,当整形数超出范围时,会自动从整形数转化成float数,可以用php_int_size常量来查看php整数类型所占字节,一般为4个字节,所以可以估算出整形数的范围,最高位数符号位.也可以用php_int_max常量来查看int的最大值. 小知识点: 1.   当变量为0.0或"0"在布尔变量中均表示false: 2.   字符串变量用双引号时其中变量和转义字符可以按照其定义正常输出,而用单引号输出内容时它会原样输出其内容,即转义字符或变量不

  • 正则表达式模式匹配字符串基础知识

     介绍 在实际项目中有个功能的实现需要解析一些特定模式的字符串.而在已有的代码库中,在已实现的部分功能中,都是使用检测特定的字符,使用这种方法的缺点是: 逻辑上很容易出错 很容易漏掉对一些边界条件的检查 代码复杂难以理解.维护 性能差 看到代码库中有一个cpp,整个cpp两千多行代码,有个方法里,光解析字符串的就有400余行!一个个字符对比过去,真是不堪入目.而且上面很多注释都已经过期,很多代码的书写风格也各不相同,基本可以判断是过了很多人手的. 在这种情况下,基本没办法还沿着这条老路走下去,自

  • 详解oracle分页查询的基础原理

    本文从数据查询原理,以及分页实现的方法详细分析了oracle分页查询的基础知识,以下是本文内容: 原因一 oracle默认为每个表生成rowmun,rowid字段,这些字段我们称之为伪列 1 创建测试表 CREATE TABLE TEST( ID NUMBER, NAME VARCHAR2(20) ) 2 插入测试数据 INSERT INTO TEST VALUES (1,'张三'); INSERT INTO TEST VALUES (2,'李四'); INSERT INTO TEST VALU

随机推荐