GaussDB(DWS)常见的三种公共模式

举报
Sprother 发表于 2021/03/02 08:53:47 2021/03/02
【摘要】 GaussDB(DWS)基于postgreSQL进行的开发,在公共模式方面两者基本一致;常见的公共模式有以下三种:PUBLIC模式,Catalog模式,information_Schema模式。

GaussDB(DWS)基于postgreSQL进行的开发,在公共模式方面两者基本一致;常见的公共模式有以下三种:PUBLIC模式,Catalog模式,information_Schema模式。

1Public模式

缺省时,创建的表(以及其它对象)都自动放到一个叫做"public"的模式中去了。每个新数据库都包含一个这样的模式。搜索路径中第一个存在的模式是创建新对象的缺省位置。这就是为什么缺省的对象都会创建在 public 模式里的原因。如果在其它环境中引用对象且没有模式修饰,那么系统会遍历搜索路径,直到找到一个匹配的对象。因此,在缺省的配置里,任何未修饰的访问只能引用 public 模式。

public 模式没有任何特殊之处,只不过它缺省时就存在。我们也可以删除它。请注意,缺省时每个人都在public模式上有CREATEUSAGE权限。这样就允许所有可以连接到指定数据库上的用户在这里创建对象。

2、Catalog模式

除了public和用户创建的模式之外,每个数据库都包含一个pg_catalog模式,它包含系统表和所有内置数据类型、函数、操作符。pg_catalog总是搜索路径中的一部分。如果它没有明确出现在路径中,那么它隐含地在所有路径之前搜索。这样就保证了内置名字总是可以被搜索。自从系统表名以pg_开头开始,最好避免使用这样的名字,以保证自己将来不会和新版本冲突:那些版本也许会定义一些和你的表同名的表(在缺省搜索路径中,一个对你的表的无修饰引用将解析为系统表)。系统表将继续遵循以pg_开头的传统,因此,只要你的表不是以pg_开头,就不会和无修饰的用户表名字冲突。

3、information_schema模式
 Information_schema自动的存在于每个database中,里面包含了数据库中所有对象的定义信息。 
Information_schema默认不存在于任何用户的search_path中,所以对所有用户都是隐藏的。\dn看不到,通过pgAdmin等客户端工具也不会自动显示。因此访问这个schema的任何视图都需要加上schema名。当然也可以通过修改search_path参数来访问。但不推荐这样做,因为里面的视图名称可能会跟用户应用程序中的对象名冲突。

information_schema模式下几个重要的视图:

  • 表信息: information_schema.tables ,相当于Oracle中的all_tables
  • 字段信息: information_schema.columns,相当于Oracle中的all_tab_cloumns 
  • 权限信息:
    1.  table_privileges中记录了表权限;
    2. column_privileges中记录了列上的权限;
    3. routine_privileges上记录了function/procedure的权限
    4. role_usage_grants记录了sequence/domain等类型的对象的usage权限,跟usage_privileges类似
  • 视图信息:
    1. Views中记录视图基础信息;
    2. view_table_usage记录视图所依赖的表;
    3. view_routine_usage记录所依赖的function;
    4. view_column_usage记录所涉及的字段 

PostgreSQL有两个系统架构调用information_schema和pg_catalog,这可能会让大家感到困惑。
下面是一些区别,标了一些关键字,请大家自行理解。

Catalog:The system catalogs are the place where a relational database management system stores schema metadata, such as information about tables and columns, and internal bookkeeping information. PostgreSQL's system catalogs are regular tables. You can drop and recreate the tables, add columns, insert and update values, and severely mess up your system that way. Normally, one should not change the system catalogs by hand, there are always SQL commands to do that. (For example, CREATE DATABASE inserts a row into the pg_database catalog — and actually creates the database on disk.) There are some exceptions for particularly esoteric operations, such as adding index access methods.

Information_schema: The information schema consists of a set of views that contain information about the objects defined in the current database. The information schema is defined in the SQL standard and can therefore be expected to be portable and remain stable — unlike the system catalogs, which are specific to PostgreSQL and are modeled after implementation concerns. The information schema views do not, however, contain information about PostgreSQL-specific features; to inquire about those you need to query the system catalogs or other PostgreSQL-specific views. 

【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

举报
请填写举报理由
0/200