Don’t the users SYS and SYSTEM share the table dba_users

oracleoracle-12c

While being logged in as SYS, I created a new user. I ran

 select username from dba_users order by username;

and I was able to see the user that i just created;

Then, I logged as SYSTEM, I ran the same query, but the user was missing this time. This leads me to the question: don't all users have the same instance of the table DBA_USERS? I thought that this was a system related table, and all users get the same instance (as long as they have the right privileges to access this table).

Best Answer

Local users created in a pluggable database are not visible in other containers through DBA_USERS. You can query all users from all open pluggable databases in the root container through CDB_USERS.

Overview of Commonality in a CDB

SQL> show con_name pdbs

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

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 SAMPLE                         READ WRITE NO
         5 BENCHMARK                      READ WRITE NO

SQL>  conn sys/Oracle123@o7ca1-vip/SAMPLE as sysdba
Connected.
SQL> create user user_created_by_sys identified by 1;

User created.

SQL> conn system/Oracle123@o7ca1-vip/BENCHMARK
Connected.
SQL> create user user_created_by_system identified by 1;

User created.

SQL> select username from dba_users where username like 'USER_CREATED%';

USERNAME
--------------------------------------------------------------------------------------------------------------------------------
USER_CREATED_BY_SYSTEM

SQL> conn sys/Oracle123@o7ca1-vip/SAMPLE as sysdba
Connected.
SQL> select username from dba_users where username like 'USER_CREATED%';

USERNAME
--------------------------------------------------------------------------------------------------------------------------------
USER_CREATED_BY_SYS

SQL> conn / as sysdba
Connected.
SQL> select username from dba_users where username like 'USER_CREATED%';

no rows selected

SQL> select con_id, username from cdb_users where username like 'USER_CREATED%';

    CON_ID USERNAME
---------- --------------------------------------------------------------------------------------------------------------------------------
         3 USER_CREATED_BY_SYS
         5 USER_CREATED_BY_SYSTEM