pg_tblspc 错误消息中的 oid 在哪里

Where is oid in pg_tblspc error message

最近我遇到 could not read block 错误,显示以下消息:

pg_tblspc/16010/PG_9.3_201306121/16301/689225.365

发生此错误后,我尝试通过假设少数数字为 oid 来尝试以下查询,但我的查询结果是空行。

select oid,relname from pg_class where oid=16010 or oid=16301;

现在我的问题是,pg_tablspc 上的数字是多少?我已经完成了 link,我相信我也可能错过了那里的要点!

更新:很多更详细的文章在http://blog.2ndquadrant.com/postgresql-filename-to-table/

以下信息不考虑由于 vacuum full 等原因导致的 relfilenode 更改


在:

pg_tblspc/16010/PG_9.3_201306121/16301/689225.365

我们有:

  • pg_tblspc:表示它是默认表空间或全局表空间以外的表空间中的关系
  • 16010:来自 pg_tablespace.oid
  • 的表空间 oid
  • PG_9.3_201306121: version-specific, catversion-specific string 允许不同的Pg版本在一个表空间中共存,
  • 16301: 来自pg_database.oid
  • 的数据库oid
  • 689225:来自pg_class.oid
  • 的关系oid
  • 365:段号。 PostgreSQL 将大表拆分为每个 1GB 的范围(段)。

可能也有分叉号,但这条路没有。


我花了相当多的源代码来确定这一点。您想要的宏是 src/include/common/relpath.h 中的 relpathbackend,供其他人查看,它在 src/common/relpath.c 中调用 GetRelationPath