All technological notes.

CDB common user
local user across all the PDBs.All Oracle-supplied administrative user accounts are CDB common users
Parameter common_user_prefix:
common users, roles, and profiles in a multitenant container database (CDB) must start with.
Common User creation:
C##
C##KHALEDCON / as sysdba;
CREATE USER C##user_name IDENTIFIED BY pwd CONTAINER=ALL;
-- CONTAINER=ALL: optional.
Local user
vs Common User:
Local user cannot create common user or grant them privileges.
common user can create and modify common user or local user. 通用修改: 横向+纵向local user can create and modify local user. 本地修改: 横向common user can grant and revoke privileges, commonly or locally. 通用授权+褫夺: 横向+纵向local user can grant privileges to common users or local users locally in a given PDB. 本地授权: 通用+本地local user the common roles. 本地可以有通用角色.
local user account must be unique only within its PDB. 本地名:本地唯一local user can access objects in a common user’s schema. 本地可以访问通用的对象.
Private Privileges:
To grant a common privilege, statement must contain CONTAIN=ALL.

Common Role Creation:
Grant a role commonly:
grant in the rootError report - ORA-01917: user or role 'T1' does not exist01917. 00000 - "user or role '%s' does not exist"*Cause: There is not a user or role by that name.*Action: Re-specify the name.conn / as sysdba;
GRANT common_role TO common_user/common_role CONTAINER=ALL;
grant in a pdb.common user is granted a common role locally, the privileges of the granted role available **only in the PDB.本地授权角色, 但权限仅在当前 PDB.即使用户和角色都是通用的.**conn sys@pdb as sysdba;
GRANT common_role/local_role TO common_user/local_user;
| SQL | Description |
|---|---|
select * from cdb_roles WHERE common='YES'; |
Query all Common role |
select * from cdb_roles WHERE common='NO'; |
Query all Local role |
show con_name
--make sure that all pluggable is opned
select con_id,name,open_mode from v$pdbs;
alter pluggable database all open;
# show all users in container and pdbs
select username,common,con_id from cdb_users
order by username;
# show all users in the current container, it has no con_id
select username, common
from dba_users;
# all common are yes, because current container is CDB, only returnt the common users.

note: sys and sysbackup are database administrate account. The result shows they have both in root and pdb.

Common Usersselect username,common,con_id from cdb_users
where common='YES'
order by username;
select distinct(username) from cdb_users
where common='YES';

Local Usersselect username,common,con_id from cdb_users
where common='NO'
order by username;

Common UserCommon UserSHOW PARAMETER common_user_prefix
#NAME TYPE VALUE
#------------------ ------ -----
#common_user_prefix string C##
show con_name;
#CON_NAME
#------------------------------
#CDB$ROOT
CREATE USER t1 IDentified by t1;

CREATE USER C##t1 IDentified by welcome;
select distinct(username) from cdb_users
where common='YES';

Common User PrivilegesTry to connect as c##t1 using developer
Status : Failure -Test failed: ORA-01045: user C##T1 lacks CREATE SESSION privilege; logon deniedGrant privilege without CONTAINER=ALL;
GRANT create session TO C##t1;


grant create session to c##t1 container=all;

Common User Privilegesrevoke create session from c##t1 container=all;
Local UserLocal User
alter session set container=orclpdb;
show con_name;
#CON_NAME
#------------------------------
#ORCLPDB
create user t1 identified by t1;
select username,common,con_id from cdb_users
where common='NO'
order by username;

Local User Privileges
grant create session to t1;

Common Rolesconnect / as sysdba;
show con_name;
# query all common roles
select * from dba_roles;
Common Role-- in root
-- cannot create local role in the root
-- common role must have common prefix
create role test_role;
/* ORA-65096: invalid common user or role name
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 consist only of ASCII characters, and must contain the prefix
specified in common_user_prefix parameter.
*Action: Specify a valid common user or role name. */
show parameter common_user_prefix;
-- NAME TYPE VALUE
-- ------------------ ------ -----
-- common_user_prefix string C##
# create a common role
create role c##test_role container=all;
# grant privileges
grant create session to c##test_role container=all ;
grant create table to c##test_role container=all ;
common user a common role-- now the session is in the root
create user c##dark identified by dark;
grant c##test_role to c##dark container=all;

common user a common rolecreate user c##kim identified by kim;
alter session set container=orclpdb
show con_name
# locally grant a common user a common role
grant c##test_role to c##kim

