Note_Tech

All technological notes.


Project maintained by simonangel-fong Hosted on GitHub Pages — Theme by mattgraham

DBA - Users: Common users VS Local users

Back


Common User VS Local User

common_local_user_diagram01


CDB Common User

common_user_prefix

CON / as sysdba;
CREATE USER C##user_name IDENTIFIED BY pwd CONTAINER=ALL;
-- CONTAINER=ALL: optional.

Local User


Common Privilege VS Local Privilege

common_local_user_privilege_diagram01.png


Common Role vs Local Role

lab_common_role_diagram

conn / as sysdba;
GRANT common_role TO common_user/common_role CONTAINER=ALL;
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

Lab: Query Users

show con_name

--make sure that all pluggable is opned
select con_id,name,open_mode from v$pdbs;

alter pluggable database all open;

Query ALL Users

# 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.

lab_common_user01

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

lab_common_user01


Query Common Users

select username,common,con_id from cdb_users
where common='YES'
order by username;

select distinct(username) from cdb_users
where common='YES';

lab_common_user


Query Local Users

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

lab_local_user01.png


Lab: Common User

Create a Common User

SHOW 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;

lab_common_user



CREATE USER C##t1 IDentified by welcome;

select distinct(username) from cdb_users
where common='YES';

lab_common_user


Grant Common User Privileges

GRANT create session TO C##t1;

lab_common_privs01

lab_common_privs01

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

lab_common_privs01


Revoke Common User Privileges

revoke create session from c##t1 container=all;

Lab: Local User

Create a Local 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;

lab_local_user


Grant Local User Privileges

lab_local_privs01.png

grant create session to t1;

lab_local_privs01.png


Lab: Role

Query all Common Roles

connect / as sysdba;
show con_name;
# query all common roles
select * from dba_roles;

Create 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 ;

Commonly grant a 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;

lab_common_role01 lab_common_role01


Locally grant a common user a common role

create 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

lab_common_role03

lab_common_role03


TOP