Oracle Database 12c cdb/pdb用户的创建

时间:2021-05-20 21:31:00
Release:Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production


在cdb的模式下:

SQL> show con_name

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


SQL> create user hr identified by hr;
create user hr identified by hr
            *
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.
//

当加上C##或c##的时候就可以创建用户了:
SQL> create user c##hr identified by hr;

User created.

在pdb模式下:

SQL> alter session set container=pdb1;

SQL> create user hr1 identified by hr1;

User created.

总结:

官方文档:

In Oracle Database 12c Release 1 (12.1.0.1), the name of acommonuser must begin with C## or c## and the name of a localuser mustnot begin with C## or c##.

而且,在cdb创建的用户是通用用户(common user),会在cdb和pdb中创建该用户。直接在pdb创建的是本地用户(local user),如果想要在cdb用户访问,需要授权。

SQL>grantconnect
to
cdb用户;

可以看一下在dba_users表里查看创建后的用户:

SQL> select username from dba_users;

并且,pdb中的DEMO、HR、OE、SH、IX、PM、BI、PDBADMIN、SCOTT默认创建的本地用户在cdb是无法查看到的。