微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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版本

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

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,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,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,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,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,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,OPEN_MODE from v$pdbs;

CON_ID DBID NAME OPEN_MODE


 3 3313918585 PDB1              READ WRITE</pre>

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

登录pdb

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",has 1 handler(s) for this service...
Service "cdbXDB" has 1 instance(s).
Instance "cdb",has 1 handler(s) for this service...
Service "pdb1" has 1 instance(s).
Instance "cdb",has 1 handler(s) for this service...
Service "pdb2" has 1 instance(s).
Instance "cdb",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,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,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,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方式登录

创建用户

show con_name;

CON_NAME

CDB$ROOT

sql> select con_id,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中只能创建的用户为本地用户

用户授权

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且存在该用户都进行授权

修改参数

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐