ORACLE 12C PDB 维护基础介绍


CDBPDBORACLE 12C一个很亮的新特性,因为他们的引入致使传统的ORACLE数据库管理理念很多发生了改变,这里列举了部分最基本的cdbpdb管理方式html


cdbpdb关系图sql

wKiom1MtfwryFTSQAADs7IGRMhs669.jpg



ORACLE 12C版本数据库

SQL>select*fromv$version;
                                                          
BANNER                                                                               CON_ID
-------------------------------------------------------------------------------- ----------
OracleDatabase12c 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
TNSforLinux: Version 12.1.0.1.0 - Production                                            0
NLSRTL Version 12.1.0.1.0 - Production


启动关闭pdbc#


SQL> startup
ORACLE instance started.
                                                     
Total SystemGlobalArea  597098496 bytes
FixedSize                  2291072 bytes
VariableSize             272632448 bytes
DatabaseBuffers          314572800 bytes
Redo Buffers                7602176 bytes
Databasemounted.
Databaseopened.
SQL>selectcon_id,dbid,NAME,OPEN_MODEfromv$pdbs;
                                                     
    CON_ID       DBIDNAME                           OPEN_MODE
---------- ---------- ------------------------------ ----------
         2 4048821679 PDB$SEED                      READONLY
         3 3313918585 PDB1                           MOUNTED
         4 3872456618 PDB2                           MOUNTED
                                                     
SQL>alterPLUGGABLEdatabasepdb1open;
                                                     
Pluggabledatabasealtered.
                                                     
SQL>selectcon_id,dbid,NAME,OPEN_MODEfromv$pdbs;
                                                     
    CON_ID       DBIDNAME                           OPEN_MODE
---------- ---------- ------------------------------ ----------
         2 4048821679 PDB$SEED                      READONLY
         3 3313918585 PDB1                          READWRITE
         4 3872456618 PDB2                           MOUNTED
                                                     
SQL>alterPLUGGABLEdatabasepdb1close;
                                                     
Pluggabledatabasealtered.
                                                     
SQL>selectcon_id,dbid,NAME,OPEN_MODEfromv$pdbs;
                                                     
    CON_ID       DBIDNAME                           OPEN_MODE
---------- ---------- ------------------------------ ----------
         2 4048821679 PDB$SEED                      READONLY
         3 3313918585 PDB1                           MOUNTED
         4 3872456618 PDB2                           MOUNTED
                                                     
SQL>alterPLUGGABLEdatabaseallopen;
                                                     
Pluggabledatabasealtered.
                                                     
SQL>selectcon_id,dbid,NAME,OPEN_MODEfromv$pdbs;
                                                     
    CON_ID       DBIDNAME                           OPEN_MODE
---------- ---------- ------------------------------ ----------
         2 4048821679 PDB$SEED                      READONLY
         3 3313918585 PDB1                          READWRITE
         4 3872456618 PDB2                          READWRITE
                                                     
SQL>alterPLUGGABLEdatabaseallclose;
                                                     
Pluggabledatabasealtered.
                                                     
SQL>selectcon_id,dbid,NAME,OPEN_MODEfromv$pdbs;
                                                     
    CON_ID       DBIDNAME                           OPEN_MODE
---------- ---------- ------------------------------ ----------
         2 4048821679 PDB$SEED                      READONLY
         3 3313918585 PDB1                           MOUNTED
         4 3872456618 PDB2                           MOUNTED
                                                     
SQL>altersessionsetcontainer=pdb1;
                                                     
Session altered.
                                                     
SQL> startup
PluggableDatabaseopened.
SQL> selectcon_id,dbid,NAME,OPEN_MODEfromv$pdbs;
                                                     
    CON_ID       DBIDNAME                           OPEN_MODE
---------- ---------- ------------------------------ ----------
         3 3313918585 PDB1                          READWRITE

pdb的管理能够在cdb中进行也能够在pdb中进行,若是是cdb中进行,须要PLUGGABLE关键字,若是是pdb中直接和普通数据库同样session



登陆pdboracle

[oracle@xifenfei ~]$ lsnrctl status
                                           
LSNRCTLforLinux: Version 12.1.0.1.0 - Productionon12-MAY-2013 08:07:02
                                           
Copyright (c) 1991, 2013, Oracle. Allrights reserved.
                                           
Connectingto(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=xifenfei)(PORT=1521)))
STATUSofthe LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNRforLinux: Version 12.1.0.1.0 - Production
StartDate                11-MAY-2013 18:30:54
Uptime                    0 days 13 hr. 36min. 8 sec
TraceLevel               off
Security                 ON:LocalOS 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)forthis service...
Service"cdb"has 1 instance(s).
  Instance"cdb", status READY, has 1 handler(s)forthis service...
Service"cdbXDB"has 1 instance(s).
  Instance"cdb", status READY, has 1 handler(s)forthis service...
Service"pdb1"has 1 instance(s).
  Instance"cdb", status READY, has 1 handler(s)forthis service...
Service"pdb2"has 1 instance(s).
  Instance"cdb", status READY, has 1 handler(s)forthis service...
The command completed successfully
[oracle@xifenfei ~]$ tnsping pdb1
                                           
TNS Ping UtilityforLinux: Version 12.1.0.1.0 - Productionon12-MAY-2013 08:07:09
                                           
Copyright (c) 1997, 2013, Oracle. Allrights reserved.
                                           
Used parameter files:
                                           
                                           
Used TNSNAMES adaptertoresolve the alias
Attemptingtocontact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = xifenfei)
(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = pdb1)))
OK (20 msec)
[oracle@xifenfei ~]$ sqlplus sys/xifenfei@pdb1assysdba
                                           
SQL*Plus: Release 12.1.0.1.0 ProductiononSun May 12 08:08:02 2013
                                           
Copyright (c) 1982, 2013, Oracle. Allrights reserved.
                                           
                                           
Connectedto:
OracleDatabase12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
Withthe Partitioning, Automatic Storage Management, OLAP, Advanced Analytics
andRealApplication Testing options
                                           
SQL> show con_name;
                                           
CON_NAME
------------------------------
PDB1
                                           
                                           
[oracle@xifenfei ~]$ sqlplus /assysdba
                                           
SQL*Plus: Release 12.1.0.1.0 ProductiononSun May 12 08:09:14 2013
                                           
Copyright (c) 1982, 2013, Oracle. Allrights reserved.
                                           
                                           
Connectedto:
OracleDatabase12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
Withthe Partitioning, Automatic Storage Management, OLAP, Advanced Analytics
andRealApplication Testing options
                                           
SQL>altersessionsetcontainer=pdb1;
                                           
Session altered.
                                           
SQL> show con_name;
                                           
CON_NAME
------------------------------
PDB1

pdb能够经过alter session container进入也能够直接经过tns方式登陆app



建立用户tcp


SQL> show con_name;
                                 
CON_NAME
------------------------------
CDB$ROOT
                                 
SQL>selectcon_id,dbid,NAME,OPEN_MODEfromv$pdbs;
                                 
    CON_ID       DBIDNAME                           OPEN_MODE
---------- ---------- ------------------------------ ----------
         2 4048821679 PDB$SEED                      READONLY
         3 3313918585 PDB1                          READWRITE
         4 3872456618 PDB2                           MOUNTED
                                 
SQL>createuserxff identifiedbyxifenfei;
createuserxff identifiedbyxifenfei
            *
ERRORatline 1:
ORA-65096: invalid commonuserorrolename
                                 
                                 
SQL> !oerr ora 65096
65096, 00000,"invalid common user or role name"
// *Cause:  An attempt was madetocreatea commonuserorrolewithaname
//          that wassnotvalidforcommon usersorroles. Inadditionto
//          the usual rulesforuserandrole names, commonuserandrole
//          names must startwithC##orc##andconsistonlyofASCII
//          characters.
// *Action: Specify a valid commonuserorrolename.
//
                                 
SQL>createuserc##xff identifiedbyxifenfei;
                                 
Usercreated.
                                 
SQL>SELECTUSERNAME,CON_ID,USER_IDFROMCDB_USERSWHEREUSERNAME='C##XFF';
                                 
USERNAME       CON_ID    USER_ID
---------- ---------- ----------
C##XFF              1        103
C##XFF              3        104
                                 
SQL>altersessionsetcontainer=pdb1;
                                 
Session altered.
                                 
SQL> show con_name
                                 
CON_NAME
------------------------------
PDB1
SQL>createuserxff identifiedbyxifenfei;
                                 
Usercreated.
                                 
SQL>createuserc##abc identifiedbyxifenfei;
createuserc##abc identifiedbyxifenfei
            *
ERRORatline 1:
ORA-65094: invalidlocaluserorrolename

建立用户默认的是container=all,cdb中只能建立全局用户(c##开头),会在cdb和全部的pdb中建立该用户(可是pdb中的全局用户须要另外受权才可以在pdb中访问)。在pdb中只能建立的用户为本地用户ide


用户受权this


SQL>grantconnecttoc##xff;
                         
Grantsucceeded.
                         
SQL>selectGRANTEE,con_idfromcdb_ROLE_PRIVSwhereGRANTED_ROLE='CONNECT'ANDGRANTEE='C##XFF';
                         
GRANTEE                            CON_ID
------------------------------ ----------
C##XFF                                  1
                         
SQL>grantresourcetoc##xff container=all;
                         
Grantsucceeded.
                         
SQL> selectGRANTEE,con_idfromcdb_ROLE_PRIVSwhereGRANTED_ROLE='RESOURCE'AND  GRANTEE='C##XFF';
                         
GRANTEE                            CON_ID
------------------------------ ----------
C##XFF                                  1
C##XFF                                  3

用户受权默认状况下是只会给当前container,cdb中也能够指定container=all,对全部openpdb且存在该用户都进行受权

修改参数

SQL>altersystemsetopen_cursors=500 container=all;
                   
System altered.
                   
SQL> conn sys/xifenfei@pdb1assysdba
Connected.
SQL> show parameter open_cursors;
                   
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
open_cursors                        integer     500
SQL> altersystemsetopen_cursors=100;
 altersystemsetopen_cursors=100
*
ERRORatline 1:
ORA-01219:databaseorpluggabledatabasenotopen: queries allowedonfixed
tablesorviewsonly
                   
                   
SQL>alterdatabaseopen;
                   
Databasealtered.
                   
SQL>altersystemsetopen_cursors=100;
                   
System altered.
                   
SQL>  show parameter open_cursors;
                   
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
open_cursors                        integer     100
SQL> conn /assysdba
Connected.
SQL> show parameter open_cursors;
                   
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
open_cursors                        integer     500

这里能够看到在cdb中修改,pdb会继承进去;若是在pdb中修改会覆盖pdbcdb中继承的参数含义


原文网址:http://www.xifenfei.com/4432.html