
Common vs Local Users
A 12c Multitenant Database is designed to make consolidation easier. The PDBs have not only their application data in separate tablespaces, they also have their application metadata in separate SYSTEM tablespaces. That’s what makes it so easy and fast to unplug a PDB.
The SYSTEM tablespace of the CDB contains the internal metadata that is shared by all PDBs. Internal metadata (the dictionary tables) and internal objects (like the DBMS* packages) belong to Common Users, most prominently to SYS. We don’t have to install all that internal stuff inside of the PDBs, they can just refer to it.
The point is that Common Users are what enables the Multitenant Architecture in the first place. You as a DBA may also create them as a side aspect of the matter. Now what does that mean in practice?
[oracle@uhesse ~]$ sqlplus / as sysdba SQL*Plus: Release 12.2.0.1.0 Production on Mon Feb 6 11:34:20 2017 Copyright (c) 1982, 2016, Oracle. All rights reserved. Connected to: Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production SQL> select name,open_mode,con_id from v$pdbs; NAME OPEN_MODE CON_ID ---------- ---------- ---------- PDB$SEED READ ONLY 2 PDB1 READ WRITE 3 PDB2 READ WRITE 4
My demo system looks like the picture above with two PDBs apart from the seed. Let’s try to clarify the difference between SYS as a common user and SCOTT as two local users.
SQL> connect sys/oracle@pdb1 as sysdba Connected. SQL> select common from dba_users where username='SCOTT'; COM --- NO SQL> select common from dba_users where username='SYS'; COM --- YES SQL> delete from scott.dept where deptno=40; 1 row deleted. SQL> commit; Commit complete. SQL> select * from scott.dept; DEPTNO DNAME LOC ---------- -------------- ------------- 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO SQL> connect sys/oracle@pdb2 as sysdba Connected. SQL> select common from dba_users where username='SCOTT'; COM --- NO SQL> select common from dba_users where username='SYS'; COM --- YES SQL> select * from scott.dept; DEPTNO DNAME LOC ---------- -------------- ------------- 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON
There are two local users with incidentally the same name SCOTT in the two PDBs. The common user SYS is almighty in both PDBs. What common users do we have else visible in the PDBs?
SQL> select username from dba_users where common='YES'; USERNAME ------------------------------------------------------- SYS SYSTEM SYSRAC SYS$UMF OUTLN DBSNMP APPQOSSYS CTXSYS SI_INFORMTN_SCHEMA GSMADMIN_INTERNAL ORDPLUGINS MDSYS ORDDATA XDB WMSYS ORDSYS GGSYS ANONYMOUS GSMCATUSER SYSBACKUP GSMUSER DIP SYSKM ORACLE_OCM SYSDG REMOTE_SCHEDULER_AGENT DBSFWUSER XS$NULL OJVMSYS AUDSYS 30 rows selected.
Apart from SYS and SYSTEM, you see some more internal users on display here. Most of them are related to certain options. This is how these options become available throughout all PDBs. Notice that DBA_USERS shows only what is visible to that PDB. The second SCOTT from PDB2 is not listed, because that user is relevant only for PDB2. It is in other words a local user inside PDB2. CDB_USERS confirms that there are two SCOTT users:
SQL> connect / as sysdba Connected. SQL> select con_id,common from cdb_users where username='SCOTT'; CON_ID COM ---------- --- 3 NO 4 NO
If you want to create a common user yourself, it must be prefixed with C##. A common user is immediately visible in all PDBs. That doesn’t mean that user has any rights, though.
SQL> connect / as sysdba Connected. SQL> create user c##adam identified by oracle container=all; User created. SQL> connect sys/oracle@pdb1 as sysdba Connected. SQL> select username,common from dba_users where username like 'C##%'; USERNAME COM ---------- --- C##ADAM YES SQL> connect sys/oracle@pdb2 as sysdba Connected. SQL> select username,common from dba_users where username like 'C##%'; USERNAME COM ---------- --- C##ADAM YES SQL> connect c##adam/oracle@pdb1 ERROR: ORA-01045: user C##ADAM lacks CREATE SESSION privilege; logon denied Warning: You are no longer connected to ORACLE. SQL> connect c##adam/oracle@pdb2 ERROR: ORA-01045: user C##ADAM lacks CREATE SESSION privilege; logon denied
Common users can get privileges granted as common or as local privileges:
SQL> grant create session to c##adam container=all; Grant succeeded. SQL> connect c##adam/oracle@pdb1 Connected. SQL> connect c##adam/oracle@pdb2 Connected. SQL> connect / as sysdba Connected. SQL> revoke create session from c##adam; revoke create session from c##adam * ERROR at line 1: ORA-65092: system privilege granted with a different scope to 'C##ADAM' SQL> revoke create session from c##adam container=all; Revoke succeeded.
Notice that container=all must be specified upon the revoke as well. That was a common privilege. Now for the local privilege:
SQL> connect sys/oracle@pdb1 as sysdba Connected. SQL> grant create session to c##adam container=current; Grant succeeded. SQL> connect c##adam/oracle@pdb1 Connected. SQL> connect c##adam/oracle@pdb2 ERROR: ORA-01045: user C##ADAM lacks CREATE SESSION privilege; logon denied Warning: You are no longer connected to ORACLE.
C##ADAM has the create session privilege only for PDB1, not for PDB2. It is in other words local to PDB1. The clause container=current is optional here and can be left out to achieve the same effect:
SQL> connect sys/oracle@pdb1 as sysdba Connected. SQL> revoke create session from c##adam container=current; Revoke succeeded. SQL> grant create session to c##adam; Grant succeeded. SQL> revoke create session from c##adam; Revoke succeeded. SQL> grant create session to c##adam container=current; Grant succeeded.
The two revokes and the two grants have had the same effect. A typical use case for the creation of common users would be to get less powerful superusers like in this example. I would recommend to implement those with some reservation, not to speak about common roles, granting a mixture of local and common privileges to roles and roles to (common) roles. Much is possible but that doesn’t necessarily mean it is a good idea to do it 🙂
This article is pretty close to what I have presented in Mainz last week during the very well run DOAG Noon2Noon event:
Only that I was talking in German, which made it a bit easier 🙂
#1 von Arun.S.Sudhakaran am Februar 7, 2017 - 10:35
Thank you so much for a wonderful and simple to understand article on Oracle 12c Common users.
#2 von Peter am November 9, 2017 - 19:30
Hi Uwe, currently I‘ve installed Default Lexer, Stoplist … in the CTXSYS schema of a PDB. The CTXSYS is a common user. Does that mean the Default Lexer installed in a PDB is visible in cdb$root and other potential new PDBs, too. Or is this separated from cdb$root, altough it is common user. That would be my understand for true multitenant. I know I could check this. But I’m not at work and I’ve got that question while reading your article. What is the right way to install Lexer? At PDB or ROOT Level? Thank you!
Cheers Peter
#3 von Peter am November 10, 2017 - 10:58
Hi Uwe,
regarding my comment from 9.11. I’ve checked this: the installed Lexer in PDB is only visible there (View CTX_PREFERENCES) and not in cdb$root. Good to know.
Cheers Peter