Technology Exchange
免费咨询热线
400-090-9964
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示例:
16384 testdb pg_default
relfilenode
表或索引对象被创建后会生成以relfilenode编号命名的数据文件
并且改文件有1G的大小限制,超过1G或生成新的文件(文件名后边加数字编号)
relfilenode标识对象物理位置的数字标号,会随数据存放的变化位置变化而变化
函数pg_relation_filenode() 可以获得对象的relfilenode
以下表对象'sampletbl'所在的物理路径会包含relfilenode的编号
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