Friday, October 11, 2013

12c CDB PDB views. (Metadata link and Object links )


One of the key feature of 12c container architecture is isolating the data dictionary tables and views specific to the application separate from the data dictionary tables specific to manage the Database ( now called the container) .  

However, the Oracle has some internal ways to talk to each other and populate the views required for management and monitoring.
  The views can work both ways. 
1) From CDB to PDBs :AWR is run at CDB level and internal object links populate the PDB's tables with information only specific to that PDB.
2) From PDBs to CDBs: Dictionary views like DBA_USERS, DBA_TABLES and DBA_SOURCE on the other hand is local to PDBs and has a superset view with a Prefix of CDB which will add the data from each of these PDBS through a mechanism called metadata link.

The following graphic shows the relationship among the different categories of dictionary views: 



One important point to note is these CDB_views are populated ONLY when the PDBs ARE OPEN.

Below is a test to prove this.
-- from CDB, close all PDBs and select count(*) from CDB_USERS.

SQL> alter pluggable database all close immediate;

Pluggable database altered.

SQL> show pdbs;

    CON_ID CON_NAME                 OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
     2 PDB$SEED                 READ ONLY  NO
     3 PDB1                  MOUNTED
     4 PDB2                  MOUNTED
     5 PDB_2                 MOUNTED
     6 PDB_1                 MOUNTED
     7 PDB_4                 MOUNTED
     8 PDB_3                 MOUNTED
     9 PDB_5                 MOUNTED
     10 PDB_1_DUP                 MOUNTED
SQL> select count(*) from cdb_users;

  COUNT(*)
----------
     70

-- from CDB, OPEN all PDBs and select count(*) from CDB_USERS.

SQL> alter pluggable database all open;

Pluggable database altered.

SQL> show pdbs

    CON_ID CON_NAME                 OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
     2 PDB$SEED                 READ ONLY  NO
     3 PDB1                  READ WRITE NO
     4 PDB2                  READ WRITE NO
     5 PDB_2                 READ WRITE NO
     6 PDB_1                 READ WRITE NO
     7 PDB_4                 READ WRITE NO
     8 PDB_3                 READ WRITE NO
     9 PDB_5                 READ WRITE NO
     10 PDB_1_DUP            READ WRITE NO
SQL> select count(*) from cdb_users;

  COUNT(*)
----------
       372


SQL> 


The count of users increased when we open all the PDBs. Thus prooving that CDB Views are populated  through metadata link only when the PDBs are OPEN.

To see tests on object links views ( Link from CDB to PDBs) click here.

Update:
 To see a list of all objects that are local to PDB and have a metadata link to CDB, you can run the below query.

select distinct object_name from dba_objects where sharing ='METADATA LINK';

When you clone from a seed PDB, I observer about 84,206 objects that have metadata link. This might change in future versions of 12c.

No comments:

Post a Comment

Feedback welcome