本文介绍了MaxCompute的元数据服务Information Schema服务的基本概念、操作使用以及使用限制。

MaxCompute的Information Schema提供了项目元数据及使用历史数据等信息。在ANSI SQL-92的Information Schema基础上,添加了面向MaxCompute服务特有的字段及视图。MaxCompute提供了名称为Information Schema的公共项目,通过访问该公共项目提供的只读视图,可以查询到用户项目的元数据信息及使用历史信息。

使用限制

  • Information Schema提供的是当前项目的元数据视图,不支持跨项目的元数据访问。如果需要对多个项目的元数据进行统一查询、分析,需要分别获取各个项目中的元数据并整合在一起进行跨项目元数据分析。
  • 元数据系统表目前提供准实时视图,对元数据时效性要求较高的应用,建议使用SDK/CLI直接获取指定对象的元数据。
  • 元数据及作业历史数据保存在Information Schema空间下,如果需要对历史数据进行快照备份或获得超过14天的作业历史,您可以定期将Information Schema的数据备份到指定项目。

获取Information Schema服务

自2020年12月1日起,对于新创建的MaxCompute项目,MaxCompute默认提供Information Schema相关的元数据视图,您无需手工安装Information Schema权限包。

对于存量MaxCompute项目,在您开始使用Information Schema服务前,需要以项目所有者(Project Owner)或具备Super_Administrato管理角色的RAM用户身份安装Information Schema权限包,获得访问项目元数据的权限。更多为用户授权管理角色操作信息,请参见将角色赋予用户。安装方式有如下两种:

Package安装成功后,当前操作所在项目即获得了通过Information Schema查询本项目相关元数据的权限。数据保存在Information Schema项目内,无需为元数据存储付费。

执行如下命令,可以查看Information Schema所提供的视图列表。

odps@myproject1> describe package Information_Schema.systables;
查询结果如下图。information_schema 截图返回结果

查询元数据视图

查询元数据视图时,需要在视图名称前指定项目Information Schema,即Information Schema.view_name

例如,您登录访问的当前项目为myproject1,在myproject1中,执行如下命令查询当前myproject1中所有表的元数据信息。
odps@myproject1>select * from Information_Schema.tables;
Information Schema同时也包含了作业历史视图,可以查询到当前项目内的作业历史信息。使用时可添加日期分区进行过滤,请参见如下命令。
odps@myproject1>select * from Information_Schema.tasks_history where ds='yyyymmdd' limit 100;

访问授权

Information Schema的视图包含了项目级别的所有用户数据,默认项目所有者可以查看。如果项目内其他用户或角色需要查看,需要进行授权,请参见基于Package跨项目访问资源

授权语法如下。
grant <actions> on package Information_Schema.systables to user <user_name>;
grant <actions> on package Information_Schema.systables to role <role_name>;
  • actions:待授予的操作权限,取值为Read。
  • user_name:已添加至项目中的阿里云账号或RAM用户。

    您可以通过MaxCompute客户端执行list users;命令获取用户账号。

  • role_name:已添加至项目中的角色。

    您可以通过MaxCompute客户端执行list roles;命令获取角色名称。

授权示例如下。
grant read on package Information_Schema.systables to user RAM$Bob@aliyun.com:user01;