database - 需要授予哪些权限才能访问 sys.dba_systems

标签 database oracle schema sql-grant system-tables

我正在开发适用于 Oracle 的应用程序。对于某种逻辑,我需要从给定的数据库用户获取具有指定模式的表列表。就我而言,我有一个已授予给定模式访问权限的用户。因此,当我的代码使用给定的凭据创建连接并尝试从以下查询中获取表时,它返回表列表。

SELECT * FROM dba_objects,其中owner ='schema'且object_type ='TABLE'

上述查询适用于具有授予所有权限的用户 但是当我尝试使用有限的权限时,它会抛出错误消息。

ORA-00942: table or view does not exist
00942. 00000 -  "table or view does not exist"

对于我们的代码从中创建连接的辅助用户,已通过以下查询授予权限

create user johnsmith identified by Passw0rd;;
grant connect to johnsmith ;
grant select any table to johnsmith ;
grant UPDATE any table to johnsmith ;
grant DELETE any table to johnsmith ;
grant INSERT any table to johnsmith ;

我应该授予用户哪种权限才能访问以下系统表...?

  • dba_objects
  • 用户约束
  • user_cons_columns
  • USER_TABLES
  • 所有选项卡列 并且还允许访问 dbms_metadata.get_dependent_ddl() 方法

最佳答案

the O7_DICTIONARY_ACCESSIBILITY initialisation parameter set to false ,这是默认值,那么:

System privileges that provide access to objects in other schemas do not give other users access to objects in the SYS schema. For example, the SELECT ANY TABLE privilege allows users to access views and tables in other schemas, but does not enable them to select dictionary objects (base tables of dynamic performance views, regular views, packages, and synonyms). You can, however, grant these users explicit object privileges to access objects in the SYS schema.

因此,您可以授予您所需的特定 View 的选择权限:

grant select on sys.dba_objects to johnsmith;

其他 View 也是如此;或者如果您需要他们有 wider access to the SYS schema objects您可以为他们提供一个角色:

grant select_catalog_role to johnsmith;

虽然principle of least privilege应始终适用,因此这可能有点过分,并且可能会暴露您不希望用户看到的内容。

您无需授予用户任何权限即可查询 user_* View 。如果您指的是 DBA 等价物 - 例如dba_tables - 然后按照上面的 dba_objects 授予它们;或者它们将包含在 select_catalog_role 中。但再次强调,只授予实际需要的东西。

无论哪种方式,对于dbms_metadata,您也可以只授予该程序包的权限(您不能授予程序包中各个过程的权限):

grant execute on dbms_metadata to johnsmith;

或者 - 可能比实际需要的要多得多,并且可能比选择角色更危险:

grant execute_catalog_role to johnsmith

关于database - 需要授予哪些权限才能访问 sys.dba_systems,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44545654/

相关文章:

oracle - 如何获取 Oracle 同义词的创建/最后 DDL 时间?

mysql - 如何在 MySQL 数据库中显示表的架构?

sql - JOIN 跨两个表

php - Model::create 是否创建数据库事务

java - Centos 7 + Oracle 12c 驱动程序无法连接

java - 如何在 XSD 中定义 CDATA 类型,以便用户不必转义字符或使用 "<![CDATA"标记?

templates - 我可以在 Tridion GUI 中插入组件模板链接吗?

database - JPA - 左连接 2 个没有关联的表

ruby-on-rails - 如何仅将 csv 中的几列插入表中

regex - Oracle - PCRE 到 Oracle REGEX