postgresql database system table

postgresql database system table

System tables are where the relational database stores schema metadata, such as table and column information, and internal statistics. The system tables of PostgreSQL are ordinary tables. You can delete and rebuild these tables, add columns, insert and update values, and then completely destroy your system. Under normal circumstances, we should not manually modify the system tables, usually there are SQL commands to do these things. (For example, CREATE DATABASE inserts a row into the pg_database table — and actually creates the database on disk.). There are several exceptions for particularly esoteric operations, but many of them can also be done with SQL commands over time, so the need for direct modification of system tables is getting smaller and smaller.

An overview of system tables

System table name use
pg_aggregate Aggregate function
pg_am Index access method
pg_amop Access method operator
pg_amproc Access method support process
pg_attrdef Column default
pg_attribute Table column ("attribute")
pg_authid Authentication identifier (role)
pg_auth_members Authentication identifier membership
pg_cast Conversion (data type conversion)
pg_class Tables, indexes, sequences, views ("relationships")
pg_collation Sorting rules (locale information)
pg_constraint Check constraints, unique constraints, primary key constraints, foreign key constraints
pg_conversion Encoding conversion information
pg_database The databases in this database cluster
pg_db_role_setting Per role and per database settings
pg_default_acl Default permissions for object types
pg_depend Dependency between database objects
pg_description Description or comment on database objects
pg_enum Enumeration label and value definition
pg_event_trigger Event trigger
pg_extension Extension installed
pg_foreign_data_wrapper Foreign data wrapper definition
pg_foreign_server External server definition
pg_foreign_table External table information
pg_index Index information
pg_inherits Table inheritance hierarchy
pg_init_privs Object initial privilege
pg_language Language for writing functions
pg_largeobjec Data page of large object
pg_largeobject _metadata Large object metadata
pg_namespace mode
pg_opclass Access method operator class
pg_operator Operator
pg_opfamily Access method operator family
pg_partitioned_table Information about the partition key of the table
pg_pltemplate Template data for process language
pg_policy Security policy
pg_proc Functions and procedures
pg_publication Logical replication release
pg_publication_rel Relationship with release mapping
pg_range Range type information
pg_replication_origin Registered copy source
pg_rewrite Query rewrite rules
pg_seclabel Security labels on database objects
pg_sequence Information about the sequence
pg_shdepend Dependency on shared objects
pg_shdescription Comments on shared objects
pg_shseclabel Security labels on shared database objects
pg_statistic Planner statistics
pg_statistic_ext Expanded planner statistics
pg_subscription Logical replication subscription
pg_subscription_rel Subscription relationship status
pg_tablespace Table space in this database cluster
pg_transform Conversion (convert the data type to the form required by the procedural language)
pg_trigger trigger
pg_ts_config Text search configuration
pg_ts_config_map Token mapping for text search configuration
pg_ts_dict Text search dictionary
pg_ts_parser Text search analyzer
pg_ts_template Text search template
pg_type type of data
pg_user_mapping Map users to external servers

Two commonly used system tables

1.pg_class

pg_class records tables and almost everything that has columns or looks like tables. This includes indexes (but also see pg_index), sequences (pg_sequence), views, materialized views, composite types, and TOAST tables

name Types of Quote description
oid oid 行标识符(隐藏属性,必须被显式选择才会显示)
relname name 表、索引、视图等的名字
relnamespace oid pg_namespace.oid 包含该关系的名字空间的 OID
reltype oid pg_type.oid 可能存在的表行类型所对应数据类型的OID(对索引为0,索引没有 pg_type 项)
reloftype oid pg_type.oid 对于有类型的表,为底层组合类型的OID,对于其他所有关系为 0
relowner oid pg_authid.oid 关系的拥有者
relam oid pg_am.oid 如果这是一个索引,表示索引使用的访问方法(B树、哈希等)
relfilenode oid 该关系的磁盘文件的名字,0表示这是一个“映射”关系,其磁盘文件名取决于低层状态
reltablespace oid pg_tablespace.oid 该关系所存储的表空间。如果为0,使用数据库的默认表空间。(如果关系无磁盘文件时无意义)
relpages int4 该表磁盘表示的尺寸,以页面计(页面尺寸为
reltuples float4 表中的行数。这只是一个由规划器使用的估计值。它被VACUUM、ANALYZE以及一些DDL命令(如CREATEINDEX)所更新。
relallvisible int4 在表的可见性映射表中被标记为全可见的页数。这只是一个由规划器使用的估计值。它被VACUUM、aNALYZE以及一些DDL命令(如CREATEINDEX)所更新。
reltoastrelid oid pg_class.oid 与该表相关联的TOAST表的OID,如果没有则为0。TOAST表将大属性“线系统表外”存储在一个二级表中。
relhasindex bool 如果这是一个表并且其上建有(或最近建有)索引则为真
relisshared bool 如果该表在集簇中的所有数据库间共享则为真。只有某些系统表(如
relpersistence char p=永久表,u=无日志表,t=临时表
relkind char r=普通表,i=索引,S=序列,t=TOAST表,v=视图,m=物化视图,c=组合类型,f=外部表,p=分区表
relnatts int2 关系中用户列的数目(系统列不计算在内)。
relchecks int2 表上 CHECK 约束的数目,
relhasoids bool 如果为关系的每一行生成一个OID则为真
relhaspkey bool 如果表有(或曾有)一个主键则为真
relhasrules bool 如果表有(或曾有)规则则为真,
relhastriggers bool 如果表有(或曾有)触发器则为真,
relhassubclass bool 如果表有(或曾有)任何继承子女则为真
relrowsecurity bool 如果表上启用了行级安全性则为真,
relforcerowsecurity bool 如果行级安全性(启用时)也适用于表拥有者则为真,
relispopulated bool 如果表已被填充则为真(对于所有关系该系统表列都为真,但对于某些物化视图却不是)
relreplident char 用来为行形成“replicaidentity”的列:d=默认(主键,如果存在),n=无,f=所有列i=索引的indisreplident 被设置或者为默认
relispartition bool 如果表是分区,则为真
relfrozenxid xid 在此之前的所有事务ID在表中已经被替换为一个永久的(“冻结的” )事务ID。这用于跟踪表是否需要被清理,以便阻止事务ID回卷或者允许pg_xact被收缩。如果该关系不是一个表则为0(InvalidTransactionId)。
relminmxid xid 在此之前的多事务ID在表中已经被替换为一个事务ID。这被用于跟踪表是否需要被清理,以阻止多事务ID回卷或者允许pg_multixact被收缩。如果关系不是一个表则为0(InvalidMultiXactId)。
relacl aclitem[] 访问权限
reloptions text[] 访问方法相关的选项,以“keyword=value”字符串形式
relpartbound pg_node_tree 如果表是分区,则是分区绑定的内部表示形式

2 pg_attribute

pg_attribute 存储有关表列的信息。数据库中的每一个表的每一个列都恰好在 pg_attribute 中有一行。

名字 类型 引用 描述
attrelid oid pg_class.oid 此列所属的表。
attname name 列名。
atttypid oid pg_type.oid 列的数据类型。
attstattarget int4 attstattarget控制ANALYZE为这个列设置的统计细节的级别。零值表示不收集统计信息,负数表示使用系统缺省的统计对象。正数值的确切信息是和数据类型相关的。
attlen int2 该列所属类型的长度。(pg_type.typlen的拷贝)
attnum int2 列的编号,普通列是从1开始计数的。系统列,如oid,是任意的负数。
attndims int4 如果该列是数组,该值表示数组的维数,否则是0。
attcacheoff int4 在磁盘上总是-1,但是如果装载入内存中的行描述器中, 它可能会被更新为缓冲在行中列的偏移量。
atttypmod int4 表示数据表在创建时提供的类型相关的数据(比如,varchar列的最大长度)。其值对那些不需要atttypmod的类型而言通常为-1。
attbyval bool pg_type.typbyval列值的拷贝。
attstorage char pg_type.typstorage列值的拷贝。
attalign char pg_type.typalign列值的拷贝。
attnotnull bool 如果该列带有非空约束,则为真,否则为假。
atthasdef bool 该列是否存在缺省值,此时它对应pg_attrdef表里实际定义此值的记录。
attisdropped bool 该列是否已经被删除。如果被删除,该列在物理上仍然存在表中,但会被分析器忽略,因此不能再通过SQL访问。
attislocal bool 该列是否局部定义在对象中的。
attinhcount int4 该列所拥有的直接祖先的个数。如果一个列的祖先个数非零,那么它就不能被删除或重命名。
attcollation oid pg_collation.oid 该列被定义的排序规则,如果该列不是一个可排序数据类型则为0。
attacl aclitem[] 列级访问权限
attoptions text[] 属性级选项
attfdwoptions text[] 属性级的外部数据包装器选项

Guess you like

Origin blog.csdn.net/yang_z_1/article/details/112270447