CDB的用户(c##开头的),除了sys用户,默认情况在CDB不能查看PDB的数据,例如v_$session的数据,需要通过alter user c##viewpdb set container_data进行赋权。
1、创建一个CDB的用户并赋权
SQL> conn / as sysdba
Connected.
SQL> select con_id,count(*) from sys.v_$session group by con_id;
CON_ID COUNT(*)
---------- ----------
1 5
5 1
3 1
0 89
SQL> create user c##viewpdb1 identified by test ;
User created.
SQL> grant create session, set container to c##viewpdb1 container=all;
Grant succeeded.
SQL> grant select on v_$session to c##viewpdb1 container=all;
Grant succeeded.
2、验证
默认情况下c##viewpdb1只能查看con_id in (0,1)
SQL> conn c##viewpdb1/test
Connected.
SQL> select con_id,count(*) from sys.v_$session group by con_id;
CON_ID COUNT(*)
---------- ----------
1 5
0 89
3、赋权
SQL> conn / as sysdba
Connected.
SQL> alter user c##viewpdb1 set container_data =(CDB$ROOT,PDB1_WHS,PDB3_WHS)for v_$session container=current;
User altered.
4、验证能否查看
SQL> conn c##viewpdb1/test
Connected.
SQL> select con_id,count(*) from sys.v_$session group by con_id;
CON_ID COUNT(*)
---------- ----------
1 5
5 1
3 1
0 89