连接到root时查看有关root,CDB和PDB的数据
当公用用户执行查询时,可以限制X $表和V $,GV $和CDB_ *视图的视图信息。X$表和这些视图包含有关应用程序root及其关联应用程序PDB的信息,或者如果连接到CDB root,则是整个CDB。
当不想全局其他PDB的敏感信息时,限制此信息很有用。 要启用此功能,Oracle数据库将这些表和视图提供为容器数据对象。 可以通过查询USER_ | DBA_ | ALL_VIEWS | TABLES字典视图的TABLE_NAME,VIEW_NAME和CONTAINER_DATA列来查找特定表或视图是否为容器数据对象。
要查找有关默认(用户级别)和特定于对象的CONTAINER_DATA属性的信息,请查询CDB_CONTAINER_DATA数据字典视图。
例如:
启用公用用户查看指定PDB的信息
可以通过调整用户的CONTAINER_DATA属性来启用公用用户访问与特定PDB相关的数据。(要使公用用户能够访问有关特定PDB的数据,请在root中发出ALTER USER语句。)
以下示例显示如何发出ALTER USER语句以启用通用用户c##hr_admin在V $ SESSION视图中查看与CDB $ ROOT,SALES_PDB和HRPDB容器相关的信息(假设此用户可以查询该视图)。
CONNECT SYSTEMEnter password: password Connected.ALTER USER c##hr_adminSET CONTAINER_DATA = (CDB$ROOT, SALESPDB, HRPDB) FOR V$SESSION CONTAINER=CURRENT;
在上面的示例中:
SET CONTAINER_DATA列出容器,有关用户可以访问的数据。
FOR V$SESSION指定CONTAINER_DATA动态视图,公用用户c## hr_admin将可以做select查询。
必须指定CONTAINER = CURRENT,因为当连接到根时,CONTAINER = ALL是ALTER USER语句的默认值,但CONTAINER_DATA属性的修改必须限制为root。
SET CONTAINER_DATA列出容器,有关用户可以访问的数据。
FOR V$SESSION指定CONTAINER_DATA动态视图,公用用户c## hr_admin将可以做select查询。
必须指定CONTAINER = CURRENT,因为当连接到根时,CONTAINER = ALL是ALTER USER语句的默认值,但CONTAINER_DATA属性的修改必须限制为root。
如果要启用用户c##hr_admin来查看与该用户可访问的所有CONTAINER_DATA对象中的CDB$ROOT,SALES_PDB,HR_PDB容器相关的信息,请忽略FOR V$SESSION。 例如:
ALTER USER c##hr_adminSET CONTAINER_DATA = (CDB$ROOT, SALESPDB, HRPDB) CONTAINER=CURRENT;
限制公共用户访问指定PDB的元数据信息(CONTAINER_DATA)
lk_db
于 2019-04-22 12:48:04 发布
744
收藏
分类专栏: Oracle 文章标签: 12c connect_data
版权
Oracle
专栏收录该内容
120 篇文章3 订阅
订阅专栏
如下举例:让C##TEST用户查询v$session的公共数据,但这些数据只能来自CDB(CON_ID=0)、CDB$ROOT(CON_ID=1)和orclpdb2(CON_ID=4):
SQL> show con_name
CON_NAME
------------------------------
CDB$ROOT
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 ORCLPDB1 READ WRITE NO
4 ORCLPDB2 READ WRITE NO
alter user语句可以在跟级别限制对v$session的查询,从而控制用户只能访问哪些容器的数据,如下:
SQL> conn system/oracle
Connected.
SQL> alter user c##test set container_data=(CDB$ROOT,orclpdb2) for v$session container=current;
User altered.
验证:
SQL> select * from dba_container_data where username='C##TEST';
USERNAME D OWNER OBJECT_NAME A CONTAINER_NAME
--------------- - --------------- --------------- - ---------------------
C##TEST N SYS V_$SESSION N CDB$ROOT
C##TEST N SYS V_$SESSION N ORCLPDB2
使用sys用户执行报错如下:
SQL> conn / as sysdba
Connected.
SQL> alter user c##test set container_data=(CDB$ROOT,orclpdb2) for v$session container=current;
alter user c##test set container_data=(CDB$ROOT,orclpdb2) for v$session container=current--只能是根,PDB也不能看到别人的
*
ERROR at line 1:
ORA-02030: can only select from fixed tables/views
使用sys用户需查询v_$session:
SQL> alter user c##test set container_data=(CDB$ROOT,orclpdb2) for v_$session container=current;
User altered.
使用SYSTEM连接,统计所有容器的会话连接数:
SQL> conn system/oracle
Connected.
SQL> select con_id,type,count(*) from v$session group by con_id,type;
CON_ID TYPE COUNT(*)
---------- ---------- ----------
1 USER 1
0 BACKGROUND 51
3 USER 1
使用c##test用户连接,就无法查看到orclpdb1(con_id=3)的信息,因为它不在授权列表中:
SQL> conn c##test/test
Connected.
SQL> select con_id,type,count(*) from v$session group by con_id,type;
CON_ID TYPE COUNT(*)
---------- ---------- ----------
1 USER 1
0 BACKGROUND 51
注意:这种访问限制只能作用在CDB$ROOT中执行的查询,并且当在orclpdb2中授予c##test执行set container的权限时,该用户就可以切换到orclpdb2中并执行查询会话信息:
SQL> conn / as sysdba
Connected.
SQL> alter session set container=orclpdb2;
Session altered.
SQL> select con_id,type,count(*) from v$session group by con_id,type;
CON_ID TYPE COUNT(*)
---------- ---------- ----------
4 USER 1
0 BACKGROUND 51 ---0 是后台
On 12c, in a Oracle Multitenant environment, attempting to change an Oracle common user in the PDB results in the following error
SQL> alter user SPATIAL_WFS_ADMIN_USR identified by ABC123;
alter user SPATIAL_WFS_ADMIN_USR identified by ABC123
*
ERROR at line 1: ORA-65066: The specified changes must apply to all containers
If we modify the SQL statement to include "container=all" we now get the following error
SQL> alter user SPATIAL_WFS_ADMIN_USR identified by ABC123 container=all;
alter user SPATIAL_WFS_ADMIN_USR identified by SPATIAL_WFS_ADMIN_USR container=all
*
ERROR at line 1:
ORA-65050: Common DDLs only allowed in CDB$ROOT
An Oracle common user is one that is installed with the database and is present in the CDB root (CDB$ROOT). Typical Oracle users would be CTXSYS, ORDSYS, MDSYS and SYSMAN.
Oracle common users can only be altered from the CDB and the change must be done on all containers (CONTAINER=ALL) which is the default if done from the CDB.
From the CDB (CDB$ROOT), change the Oracle common user with the following syntax
alter user SPATIAL_WFS_ADMIN_USR identified by ABS123'