选择 打开 改范围 完整检索页

pgsql.cc 提供对 postgresql.org 官网内容的中文翻译,由 Pigsty 团队维护。

文档 / 系统目录 / 系统目录表

SYSTEM CATALOG系统目录表

pg_attribute

表列(“属性”)

系统目录表 引入 9.0(基线) 现存至 20 devel 9 次结构变更

关系 OID
1249
关系类型
r(普通表)
字段数
25
引入版本
9.0(收录基线)
版本状态
当前稳定版
结构变更
9 次

PostgreSQL 18 手册 官方文档 源码定义

版本轨迹

相对 PostgreSQL 17:移除 1 个,描述更新 2 处。

目录pg_attribute存储关于表列的信息。数据库中每个表的每一列,在pg_attribute中都恰好有一行。 (其中也包括索引的属性项,实际上,凡是在pg_class中有项的对象,都有对应的属性项。)

术语属性等同于列,这里使用它只是出于历史原因。

字段

PostgreSQL 18 的 25 个字段,按定义顺序排列。说明默认用本站手册的译文,没有译文的按英文原文显示。

字段 类型 说明
attrelid oidNOT NULL pg_class.oid 此列所属的表
attname nameNOT NULL 列名称
atttypid oidNOT NULL pg_type.oid 此列的数据类型(删除的列为零)
attlen smallintNOT NULL 该列数据类型的pg_type.typlen副本
attnum smallintNOT NULL 列的编号。一般列从1开始向上编号。系统列,如ctid,则拥有(任意)负值编号。
atttypmod integerNOT NULL atttypmod记录了在表创建时提供的类型相关数据(例如一个varchar列的最大长度)。 它会被传递给类型相关的输入函数和长度强制函数。对于那些不需要atttypmod的类型,这个值通常总是为-1。
attndims smallintNOT NULL 如果该列是数组类型,则为维数;否则为 0。 (目前并不会强制检查数组维数,因此任何非零值实际上都只意味着“这是一个数组”。)
attbyval booleanNOT NULL 该列类型的pg_type.typbyval的一个拷贝
attalign "char"NOT NULL 该列类型的 pg_type.typalign 的一个拷贝
attstorage "char"NOT NULL 通常是该列类型的pg_type.typstorage的一个拷贝。 对于可TOAST的数据类型,这可以在列创建后被修改以控制存储策略。
attcompression "char"NOT NULL 该列当前的压缩方法。 通常为'\0',表示使用当前默认设置(见 default_toast_compression)。 否则,'p' 选择 pglz 压缩,而'l' 选择 LZ4 压缩。 但是,当attstorage不允许压缩时,该字段会被忽略。
attnotnull booleanNOT NULL 此列具有一个非空约束(可能尚未验证)
atthasdef booleanNOT NULL 该列有一个默认表达式或生成的表达式,在此情况下在pg_attrdef目录中会有一个对应项来真正定义该表达式。 (检查attgenerated以确定是默认还是生成的表达式。)
atthasmissing booleanNOT NULL 该列在行中完全缺失时会用到这个列的值,如果在行创建之后增加一个有非易失DEFAULT值的列,就会发生这种情况。 实际使用的值被存放在attmissingval列中。
attidentity "char"NOT NULL 如果是一个零字节(''),则不是一个标识列。 否则,a = 总是生成,d = 默认生成。
attgenerated "char"NOT NULL 如果是零字节(''),则不是生成列。 否则,s = 存储式(stored),v = 虚拟(virtual)。 存储式生成列会像普通列一样实际存储;虚拟生成列则在物理上存储为空值,实际值在运行时计算。
attisdropped booleanNOT NULL 该列被删除且不再有效。一个删除的列仍然物理存在于表中,但是会被分析器忽略并因此无法通过SQL访问。
attislocal booleanNOT NULL 该列是由关系本地定义的。注意一个列可以同时是本地定义和继承的。
attinhcount smallintNOT NULL 该列直接祖先的数量。祖先数量非零的列不能被删除,也不能被重命名。
attcollation oidNOT NULL pg_collation.oid 该列被定义的排序规则,如果该列不是一个可排序数据类型则为0。
attstattarget smallint attstattarget 控制 ANALYZE 为该列收集统计信息时的细节级别。 零值表示不应收集统计信息。 空值表示使用系统默认统计目标。 正值的确切含义依赖于数据类型。 对于标量数据类型,attstattarget 既是要收集的“高频值”目标个数,也是要创建的直方图桶目标个数。
attacl aclitem[] 列级访问权限, 如果此列上已有特别授予的权限
attoptions text[] 属性级选项,以“keyword=value”形式的字符串
attfdwoptions text[] 属性级的外部数据包装器选项,以“keyword=value”形式的字符串
attmissingval anyarray 这个列中是一个含有一个元素的数组,其中的值被用于该列在行中完全缺失时,如果在行创建之后增加一个有非易失DEFAULT值的列,就会发生这种情况。 只有当atthasmissing为真时才使用这个值。如果没有值则该列为空。

本版移除的字段

  • attcacheoff integer 在存储中始终为 -1,但装入内存中的行描述符时,可能会更新为该属性在行内偏移量的缓存值

取值来自 PostgreSQL 17 的快照。

演化历史

相邻两个大版本之间的差异,新的在前。版本号链到该版的字段表。

  1. PostgreSQL 18 ← 17 结构变更

    attcacheoff

    2 处描述更新
    • attgenerated If a zero byte (''), then not a generated column. Otherwise, s = stored. (Other values might be added in the future.) If a zero byte (''), then not a generated column. Otherwise, s = stored, v = virtual. A stored generated column is physically stored like a normal column. A virtual generated column is physically stored as a null value, with the actual value being computed at run time.
    • attnotnull This represents a not-null constraint. This column has a (possibly invalid) not-null constraint.
  2. PostgreSQL 17 ← 16 结构变更

    attstattarget:非空 → 可空 字段顺序调整

    1 处描述更新
    • attstattarget attstattarget controls the level of detail of statistics accumulated for this column by ANALYZE. A zero value indicates that no statistics should be collected. A negative value says to use the system default statistics target. The exact meaning of positive values is data type-dependent. For scalar data types, attstattarget is both the target number of “most common values” to collect, and the target number of histogram bins to create. attstattarget controls the level of detail of statistics accumulated for this column by ANALYZE. A zero value indicates that no statistics should be collected. A null value says to use the system default statistics target. The exact meaning of positive values is data type-dependent. For scalar data types, attstattarget is both the target number of “most common values” to collect, and the target number of histogram bins to create.
  3. PostgreSQL 16 ← 15 结构变更

    attinhcount:integer → smallintattndims:integer → smallintattstattarget:integer → smallint 字段顺序调整

  4. PostgreSQL 14 ← 13 结构变更

    attcompression 字段顺序调整

    2 处描述更新
    • attcollation The defined collation of the column, or zero if the column is not of a collatable data type. The defined collation of the column, or zero if the column is not of a collatable data type
    • atttypid The data type of this column The data type of this column (zero for a dropped column)
  5. PostgreSQL 12 ← 11 结构变更

    attgenerated

    2 处描述更新
    • atthasdef This column has a default value, in which case there will be a corresponding entry in the pg_attrdef catalog that actually defines the value. This column has a default expression or generation expression, in which case there will be a corresponding entry in the pg_attrdef catalog that actually defines the expression. (Check attgenerated to determine whether this is a default or a generation expression.)
    • attnum The number of the column. Ordinary columns are numbered from 1 up. System columns, such as oid, have (arbitrary) negative numbers. The number of the column. Ordinary columns are numbered from 1 up. System columns, such as ctid, have (arbitrary) negative numbers.
  6. PostgreSQL 11 ← 10 结构变更

    atthasmissingattmissingval

  7. PostgreSQL 10 ← 9.6 结构变更

    attidentity

    4 处描述更新
    • attfdwoptions Attribute-level foreign data wrapper options, as "keyword=value" strings Attribute-level foreign data wrapper options, as “keyword=value” strings
    • attndims Number of dimensions, if the column is an array type; otherwise 0. (Presently, the number of dimensions of an array is not enforced, so any nonzero value effectively means "it's an array".) Number of dimensions, if the column is an array type; otherwise 0. (Presently, the number of dimensions of an array is not enforced, so any nonzero value effectively means “it's an array”.)
    • attoptions Attribute-level options, as "keyword=value" strings Attribute-level options, as “keyword=value” strings
    • attstattarget attstattarget controls the level of detail of statistics accumulated for this column by ANALYZE. A zero value indicates that no statistics should be collected. A negative value says to use the system default statistics target. The exact meaning of positive values is data type-dependent. For scalar data types, attstattarget is both the target number of "most common values" to collect, and the target number of histogram bins to create. attstattarget controls the level of detail of statistics accumulated for this column by ANALYZE. A zero value indicates that no statistics should be collected. A negative value says to use the system default statistics target. The exact meaning of positive values is data type-dependent. For scalar data types, attstattarget is both the target number of “most common values” to collect, and the target number of histogram bins to create.
  8. PostgreSQL 9.5 ← 9.4 仅描述更新

    1 处描述更新
    • attnotnull This represents a not-null constraint. It is possible to change this column to enable or disable the constraint. This represents a not-null constraint.
  9. PostgreSQL 9.2 ← 9.1 结构变更

    attfdwoptions

  10. PostgreSQL 9.1 ← 9.0 结构变更

    attcollation

字段矩阵

每个字段在 18 个收录版本里的存在情况;方格指向该版的字段表。「有变」指类型、可空、隐式或数组维数与上一版不同。

存在 有变 已移除 不存在

字段 9.09.19.29.39.49.59.61011121314151617181920
attrelid 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在
attname 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在
atttypid 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在
attstattarget 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 有变 有变 存在 存在 存在
attlen 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在
attnum 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在
attndims 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 有变 存在 存在 存在 存在
attcacheoff 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 已移除 不存在 不存在
atttypmod 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在
attbyval 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在
attstorage 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在
attalign 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在
attnotnull 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在
atthasdef 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在
attisdropped 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在
attislocal 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在
attinhcount 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 有变 存在 存在 存在 存在
attacl 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在
attoptions 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在
attcollation 不存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在
attfdwoptions 不存在 不存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在
attidentity 不存在 不存在 不存在 不存在 不存在 不存在 不存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在
atthasmissing 不存在 不存在 不存在 不存在 不存在 不存在 不存在 不存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在
attmissingval 不存在 不存在 不存在 不存在 不存在 不存在 不存在 不存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在
attgenerated 不存在 不存在 不存在 不存在 不存在 不存在 不存在 不存在 不存在 存在 存在 存在 存在 存在 存在 存在 存在 存在
attcompression 不存在 不存在 不存在 不存在 不存在 不存在 不存在 不存在 不存在 不存在 不存在 存在 存在 存在 存在 存在 存在 存在

系统列

每张表都有的 6 个系统列
  • tableoidoid-6
  • cmaxcid-5
  • xmaxxid-4
  • cmincid-3
  • xminxid-2
  • ctidtid-1

同类关系

关系 引入 字段 版本变动 最近变更
SYSTEM CATALOG 系统目录表 70 个
pg_aggregate 9.0基线 22 113 次
聚合函数 现存
pg_am 9.0基线 4 124 次
关系访问方法 现存
pg_amop 9.0基线 9 122 次
访问方法操作符 现存
pg_amproc 9.0基线 6 121 次
访问方法支持函数 现存
pg_attrdef 9.0基线 4 122 次
列默认值 现存
pg_attribute 9.0基线 25 189 次
表列(“属性”) 现存
pg_auth_members 9.0基线 7 161 次
授权标识符成员关系 现存
pg_authid 9.0基线 12 123 次
授权标识符(角色) 现存
pg_cast 9.0基线 6 121 次
转换(数据类型转换) 现存
pg_class 9.0基线 34 189 次
表、索引、序列、视图 (“关系”) 现存
pg_collation 9.1 12 175 次
排序规则(区域设置信息) 现存
pg_constraint 9.0基线 28 187 次
检查约束、唯一约束、主键约束、外键约束 现存
pg_conversion 9.0基线 8 121 次
编码转换信息 现存
pg_database 9.0基线 18 175 次
本数据库集簇中的数据库 现存
pg_db_role_setting 9.0基线 3
每角色和每数据库的设置 现存
pg_default_acl 9.0基线 5 121 次
对象类型的默认权限 现存
pg_depend 9.0基线 7
数据库对象间的依赖 现存
pg_description 9.0基线 4 9.51 次
数据库对象上的描述或注释 现存
pg_enum 9.0基线 4 122 次
枚举标签和值定义 现存
pg_event_trigger 9.3 7 121 次
事件触发器 现存
pg_extension 9.1 8 122 次
已安装扩展 现存
pg_foreign_data_wrapper 9.0基线 8 193 次
外部数据包装器定义 现存
pg_foreign_server 9.0基线 8 121 次
外部服务器定义 现存
pg_foreign_table 9.1 3
外部表信息 现存
pg_index 9.0基线 21 155 次
索引信息 现存
pg_inherits 9.0基线 4 141 次
表继承层次 现存
pg_init_privs 9.6 5
对象初始权限 现存
pg_language 9.0基线 9 121 次
编写函数的语言 现存
pg_largeobject 9.0基线 3 9.51 次
大对象的数据页 现存
pg_largeobject_metadata 9.0基线 3 121 次
大对象的元数据 现存
pg_namespace 9.0基线 4 121 次
模式 现存
pg_opclass 9.0基线 9 121 次
访问方法操作符类 现存
pg_operator 9.0基线 15 121 次
操作符 现存
pg_opfamily 9.0基线 5 121 次
访问方法操作符族 现存
pg_parameter_acl 15 3
已授予权限的配置参数 现存
pg_partitioned_table 10 8 111 次
表的分区键的信息 现存
pg_pltemplate 9.0基线 8 9.51 次
过程语言的模板数据 于 13 移除
pg_policy 9.5 8 122 次
行安全策略 现存
pg_proc 9.0基线 30 147 次
函数和过程 现存
pg_propgraph_element 19 14
属性图元素(顶点和边) 于 20 移除
pg_propgraph_element_label 19 3
属性图中元素与标签之间的链接 于 20 移除
pg_propgraph_label 19 3
属性图标签 于 20 移除
pg_propgraph_label_property 19 4
属性图中按标签区分的属性定义 于 20 移除
pg_propgraph_property 19 6
属性图属性 于 20 移除
pg_publication 10 11 195 次
用于逻辑复制的发布 现存
pg_publication_namespace 15 3
模式到发布映射 现存
pg_publication_rel 10 6 193 次
关系与发布的映射 现存
pg_range 9.2 12 192 次
范围类型的信息 现存
pg_replication_origin 9.5 2
已注册的复制源 现存
pg_rewrite 9.0基线 8 123 次
查询重写规则 现存
pg_seclabel 9.1 5 9.51 次
数据库对象上的安全标签 现存
pg_sequence 10 8
有关序列的信息 现存
pg_shdepend 9.0基线 7
共享对象上的依赖 现存
pg_shdescription 9.0基线 3 9.51 次
共享对象上的注释 现存
pg_shseclabel 9.2 4 9.51 次
共享数据库对象上的安全标签 现存
pg_statistic 9.0基线 31 122 次
规划器统计 现存
pg_statistic_ext 10 9 174 次
扩展的规划器统计信息(定义) 现存
pg_statistic_ext_data 12 6 152 次
扩展的规划器统计信息(已构建的统计信息) 现存
pg_subscription 10 23 197 次
逻辑复制订阅 现存
pg_subscription_rel 10 4 131 次
订阅的关系状态 现存
pg_tablespace 9.0基线 5 122 次
本数据库集簇内的表空间 现存
pg_transform 9.5 5 121 次
转换(将数据类型转换为过程语言需要的形式) 现存
pg_trigger 9.0基线 19 135 次
触发器 现存
pg_ts_config 9.0基线 5 121 次
文本搜索配置 现存
pg_ts_config_map 9.0基线 4
文本搜索配置的词元映射 现存
pg_ts_dict 9.0基线 6 121 次
文本搜索字典 现存
pg_ts_parser 9.0基线 8 121 次
文本搜索分析器 现存
pg_ts_template 9.0基线 5 121 次
文本搜索模板 现存
pg_type 9.0基线 32 144 次
数据类型 现存
pg_user_mapping 9.0基线 4 121 次
将用户映射到外部服务器 现存