教学文章
Technology Exchange
热门课程
400电话

免费咨询热线
400-090-9964

教学文章

PostgreSQL基础教程:对象标识符类型oid与relfilenode数据文件

时间:2020-06-08 来源:

PostgreSQL数据中,oid和relfilenode是比较容易混淆,但又是很重要的,这里就来简单介绍一下oid和relfilenode

oid:对象标识符类型Object Identifier Types ,内部使用,并作为系统表的主键

别名类型对查找一个对象的OID非常方便

可以在用户定义的表中使用,不推荐使用

oid不会添加到 用户自己创建的表里,除非指定 WITH OIDS 或者 default_with_oids 打开,oid是给内部表做标识用的,不推荐使用。

建议将 default_with_oids 设置为off。 建表的时候,如果想使用主键,请自行建立。

oid本身大小固定的,万一 行数超过了oid 的最大限制数(4 byte int),那就无法插入新行了。

oid2name可以获取数据库、对象的OID

Oid2name示例:

[postgres@hgdb01 data]$ oid2name
All databases:
    Oid  Database Name  Tablespace
----------------------------------
  73780          bench  pg_default
  41002           jwdb  pg_default
  13295       postgres  pg_default
  13290      template0  pg_default
      1      template1  pg_default
  16384         testdb  pg_default
[postgres@hgdb01 data]$ oid2name testdb
All databases:
    Oid  Database Name  Tablespace
----------------------------------
  73780          bench  pg_default
  41002           jwdb  pg_default
  13295       postgres  pg_default
  13290      template0  pg_default
      1      template1  pg_default

16384         testdb  pg_default


relfilenode

表或索引对象被创建后会生成以relfilenode编号命名的数据文件

并且改文件有1G的大小限制,超过1G或生成新的文件(文件名后边加数字编号)

relfilenode标识对象物理位置的数字标号,会随数据存放的变化位置变化而变化

函数pg_relation_filenode() 可以获得对象的relfilenode

testdb=# select pg_relation_filenode('sampletbl');
 pg_relation_filenode 
----------------------
                81993
(1 row)


以下表对象'sampletbl'所在的物理路径会包含relfilenode的编号

testdb=# select pg_relation_filepath('sampletbl'); 
 pg_relation_filepath 
----------------------
 base/16384/81993
(1 row)


OID 与relfilenode的关系

oid 类似于 身份证号,

relfilenode 类似于 户口本上户号,只要人的住址变了,户号就会变

知识点:

When the file size of tables and indexes exceeds 1GB, PostgreSQL creates a new file named like relfilenode.1 and uses it. If the new file has been filled up, next new file named like relfilenode.2 will be created, and so on.

补充说明:

The maximum file size of tables and indexes can be changed using the configuration, option --with-segsize when building PostgreSQL

版权所有@北京神脑资讯技术有限公司(CUUG,中国UNIX用户协会) Copyright ALL Rights Reserved 京ICP备11008061号-1

CUUG旗下网站:www.cuug.com.cn www.cuug.com oracle.cuug.com bbs.cuug.com www.cuug.net

电话:010-59426307 010-59426319 邮政编码:100089

地址:北京市海淀区北清路164号28-38号院