查看所有CDB、PDB的用户
SQL> col username format a20
SQL> select username,common,con_id from cdb_users;
USERNAME COMMON CON_ID
-------------------- --------- ----------
SYS YES 3
SYSTEM YES 3
XS$NULL YES 3
LBACSYS YES 3
OUTLN YES 3
DBSNMP YES 3
APPQOSSYS YES 3
DBSFWUSER YES 3
GGSYS YES 3
ANONYMOUS YES 3
CTXSYS YES 3
USERNAME COMMON CON_ID
-------------------- --------- ----------
DVSYS YES 3
DVF YES 3
GSMADMIN_INTERNAL YES 3
MDSYS YES 3
OLAPSYS YES 3
XDB YES 3
WMSYS YES 3
GSMCATUSER YES 3
MDDATA YES 3
SYSBACKUP YES 3
REMOTE_SCHEDULER_AGE YES 3
USERNAME COMMON CON_ID
-------------------- --------- ----------
NT
PDBADMIN NO 3
GSMUSER YES 3
SYSRAC YES 3
OJVMSYS YES 3
SI_INFORMTN_SCHEMA YES 3
AUDSYS YES 3
DIP YES 3
ORDPLUGINS YES 3
SYSKM YES 3
USERNAME COMMON CON_ID
-------------------- --------- ----------
ORDDATA YES 3
ORACLE_OCM YES 3
SYS$UMF YES 3
SYSDG YES 3
ORDSYS YES 3
SYS YES 1
SYSTEM YES 1
XS$NULL YES 1
OJVMSYS YES 1
LBACSYS YES 1
OUTLN YES 1
USERNAME COMMON CON_ID
-------------------- --------- ----------
SYS$UMF YES 1
DBSNMP YES 1
APPQOSSYS YES 1
DBSFWUSER YES 1
GGSYS YES 1
ANONYMOUS YES 1
CTXSYS YES 1
DVSYS YES 1
DVF YES 1
GSMADMIN_INTERNAL YES 1
MDSYS YES 1
USERNAME COMMON CON_ID
-------------------- --------- ----------
OLAPSYS YES 1
XDB YES 1
WMSYS YES 1
GSMCATUSER YES 1
MDDATA YES 1
SYSBACKUP YES 1
REMOTE_SCHEDULER_AGE YES 1
NT
GSMUSER YES 1
SYSRAC YES 1
USERNAME COMMON CON_ID
-------------------- --------- ----------
GSMROOTUSER YES 1
SI_INFORMTN_SCHEMA YES 1
AUDSYS YES 1
DIP YES 1
ORDPLUGINS YES 1
SYSKM YES 1
ORDDATA YES 1
ORACLE_OCM YES 1
SYSDG YES 1
ORDSYS YES 1
SYS YES 5
USERNAME COMMON CON_ID
-------------------- --------- ----------
SYSTEM YES 5
XS$NULL YES 5
OJVMSYS YES 5
LBACSYS YES 5
OUTLN YES 5
SYS$UMF YES 5
DBSNMP YES 5
APPQOSSYS YES 5
DBSFWUSER YES 5
GGSYS YES 5
ANONYMOUS YES 5
USERNAME COMMON CON_ID
-------------------- --------- ----------
CTXSYS YES 5
DVF YES 5
DVSYS YES 5
GSMADMIN_INTERNAL YES 5
MDSYS YES 5
OLAPSYS YES 5
XDB YES 5
WMSYS YES 5
GSMCATUSER YES 5
MDDATA YES 5
REMOTE_SCHEDULER_AGE YES 5
USERNAME COMMON CON_ID
-------------------- --------- ----------
NT
SYSBACKUP YES 5
GSMUSER YES 5
GSMROOTUSER YES 5
SYSRAC YES 5
SI_INFORMTN_SCHEMA YES 5
AUDSYS YES 5
DIP YES 5
ORDPLUGINS YES 5
ORDDATA YES 5
USERNAME COMMON CON_ID
-------------------- --------- ----------
SYSKM YES 5
ORACLE_OCM YES 5
ORDSYS YES 5
SYSDG YES 5
108 rows selected.
在CDB创建用户并赋权
SQL> create user c##test identified by test;
User created.
SQL> grant dba to c##test;
Grant succeeded.
在PDB创建用户并赋权
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDB1_WHS READ WRITE NO
4 PDB2_WHS MOUNTED
5 PDB3_WHS READ WRITE NO
SQL> alter session set container=PDB1_WHS;
Session altered.
SQL> create user test identified by test;
User created.
SQL> grant dba to test;
Grant succeeded.
在CDB查询:
SQL> col username format a20
SQL> select username,common,con_id from cdb_users where username in ('TEST','C##TEST');
USERNAME COMMON CON_ID
-------------------- --------- ----------
C##TEST YES 1
C##TEST YES 3
TEST NO 3
C##TEST YES 5
在PDB下创建的用户,只会在本PDB创建,CDB创建的用户会同步到各个PDB,由于PDB2_WHS是关闭状态,所以没有。
开启PDB2_WHS,验证是否会同步:
SQL> alter pluggable database PDB2_WHS open;
Pluggable database altered.
SQL> select username,common,con_id from cdb_users where username in ('TEST','C##TEST');
USERNAME COMMON CON_ID
-------------------- --------- ----------
C##TEST YES 1
C##TEST YES 4 <--数据库开启后就有了
C##TEST YES 5
C##TEST YES 3
TEST NO 3