English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
First let's talk about the basic usage:
First, follow11G before doing
conn / as sysdba;
create user test identified by test;
ORA-65096: Invalid public username or role name.
Looking at the official documentation, it says 'To create a common user, you must use C## or c## at the beginning'. At this point, you may have doubts, what is a common user? Let's just try and see if it works first.
create C##user test identified by test;
Created successfully
SQL> show con_name;
CON_NAME
------------------------------
CDB$ROOT
select con_id, dbid, NAME, OPEN_MODE from v$pdbs;
CON_ID DBID NAME OPEN_MODE
---------- ---------- ------------------------------ ----------
2 4066409480 PDB$SEED READ ONLY
3 2270995695 PDBORCL MOUNTED
SQL> alter session set container=PDBORCL;
Now you can create a user with the command 'create user test identified by test;'.
CDB and PDB are ORACLE 12C is a very bright new feature, due to their introduction, many traditional ORACLE database management concepts have changed. Here are some of the most basic cdb and pdb management methods listed.
cdb and pdb relationship diagram
ORACLE 12C version
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
Start and stop 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
The management of pdb can be done in cdb as well as in pdb. If it is done in cdb, the PLUGGABLE keyword is required, and if it is done in pdb, it is treated just like a regular database
Login to 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 can be accessed by entering alter session container or directly by tns method
Create user
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 was 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
By default, users are created with container=all, in cdb only global users (starting with c##) can be created, which will create the user in cdb and all pdb (but the global users in pdb need to be authorized separately to access pdb). Only local users can be created in pdb
User authorization
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
By default, user authorization will only grant the current container. In cdb, you can also specify container=all to authorize all open pdbs where the user exists.
Modify parameter
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
You can see that when modifying in cdb, pdb will inherit it; if modifying in pdb, it will override the parameter meanings inherited from cdb.
Declaration: The content of this article is from the Internet, and the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, has not been manually edited, and does not assume any relevant legal liability. If you find any content suspected of copyright infringement, please send an email to: notice#w3Please report via email to codebox.com (replace # with @ when sending email) and provide relevant evidence. Once verified, this site will immediately delete the content suspected of infringement.