对PostgreSQL中 pg_各表的RelationId的认识
读取普通的table或者系统表,都会调用heap_open函数:
/* ----------------
* heap_open - open a heap relation by relation OID
*
* This is essentially relation_open plus check that the relation
* is not an index nor a composite type. (The caller should also
* check that it's not a view or foreign table before assuming it has
* storage.)
* ----------------
*/
Relation
heap_open(Oid relationId, LOCKMODE lockmode)
{
//fprintf(stderr,"++++++++++++++++++++ In heap_open start by process %d....relationId is:%d\n",
getpid(),relationId);
Relation r; r = relation_open(relationId, lockmode); if (r->rd_rel->relkind == RELKIND_INDEX)
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("\"%s\" is an index",
RelationGetRelationName(r))));
else if (r->rd_rel->relkind == RELKIND_COMPOSITE_TYPE)
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("\"%s\" is a composite type",
RelationGetRelationName(r)))); //fprintf(stderr,"++++++++++++++++++++ In heap_open end by process %d\n\n",getpid()); return r;
}
对于普通表而言,RelationId就是在base目录下的某个子目录里面的文件名。
但是对于系统表而言,则不同。
比如 pg_tablespace 的RelationId为 1213(这已经写死在PostgreSQL源代码中),
但是其对应的文件的名称为 12587(对应global/12587文件)。
经过一番测试,发现其对应关系如下:
| pg_default_acl | 826 |
| pg_pltemplate | 1136 |
| pg_tablespace | 1213 |
| pg_shdepend | 1214 |
| pg_type | 1247 |
| pg_attribute | 1249 |
| pg_proc | 1255 |
| pg_class | 1259 |
| pg_authid | 1260 |
| pg_auth_members | 1261 |
| pg_database | 1262 |
| pg_foreign_server | 1417 |
| pg_user_mapping | 1418 |
| pg_foreign_data_wrapper | 2328 |
| pg_shdescription | 2396 |
| pg_aggregate | 2600 |
| pg_am | 2601 |
| pg_amop | 2602 |
| pg_ampro | 2603 |
| pg_attrdef | 2604 |
| pg_cast | 2605 |
| pg_constraint | 2606 |
| pg_conversion | 2607 |
| pg_depend | 2608 |
| pg_description | 2609 |
| pg_index | 2610 |
| pg_inherits | 2611 |
| pg_language | 2612 |
| pg_largeobject | 2613 |
| pg_namespace | 2615 |
| pg_opclass | 2616 |
| pg_operator | 2617 |
| pg_rewrite | 2618 |
| pg_stastic | 2619 |
| pg_trigger | 2620 |
| pg_opfamily | 2753 |
| pg_db_role_setting | 2964 |
| pg_largeobject_metadata | 2995 |
| pg_extension | 3079 |
| pg_foreign_table | 3118 |
| pg_collation | 3456 |
| pg_enum | 3501 |
| pg_seclabel | 3596 |
| pg_ts_dict | 3600 |
| pg_ts_parser | 3601 |
| pg_ts_config | 3602 |
| pg_ts_config_map | 3603 |
| pg_ts_template | 3764 |
然后,我还可以进一步,观察 ,把上述表格补充完整:
/* ----------------
* relation_open - open any relation by relation OID
*
* If lockmode is not "NoLock", the specified kind of lock is
* obtained on the relation. (Generally, NoLock should only be
* used if the caller knows it has some appropriate lock on the
* relation already.)
*
* An error is raised if the relation does not exist.
*
* NB: a "relation" is anything with a pg_class entry. The caller is
* expected to check whether the relkind is something it can handle.
* ----------------
*/
Relation
relation_open(Oid relationId, LOCKMODE lockmode)
{ fprintf(stderr,"___________________ In relation_open start by process %d\n",getpid()); Relation r; Assert(lockmode >= NoLock && lockmode < MAX_LOCKMODES); /* Get the lock before trying to open the relcache entry */
if (lockmode != NoLock)
LockRelationOid(relationId, lockmode); /* The relcache does all the real work... */
r = RelationIdGetRelation(relationId); fprintf(stderr,"In relation_open ,the relNode is:%d....\n\n",r->rd_node.relNode); if (!RelationIsValid(r))
elog(ERROR, "could not open relation with OID %u", relationId); /* Make note that we've accessed a temporary relation */
if (RelationUsesLocalBuffers(r))
MyXactAccessedTempRel = true; pgstat_initstats(r); fprintf(stderr,"___________________ In relation_open end by process %d\n",getpid()); return r;
}
加入了调试代码后,我可以看到,pg_tablespace 的 RelationId是 1213,而它的对应文件名是 12587。
下面,补充完整:
| system table name | RelationId | FileName |
| pg_default_acl | 826 | 12642 |
| pg_pltemplate | 1136 | 12591 |
| pg_tablespace | 1213 | 12587 |
| pg_shdepend | 1214 | 12598 |
| pg_type | 1247 | 12442 |
| pg_attribute | 1249 | 12446 |
| pg_proc | 1255 | 12458 |
| pg_class | 1259 | 12465 |
| pg_authid | 1260 | 12450 |
| pg_auth_members | 1261 | 12594 |
| pg_database | 1262 | 12692 |
| pg_foreign_server | 1417 | 12635 |
| pg_user_mapping | 1418 | 12454 |
| pg_foreign_data_wrapper | 2328 | 12631 |
| pg_shdescription | 2396 | 12602 |
| pg_aggregate | 2600 | 12525 |
| pg_am | 2601 | 12505 |
| pg_amop | 2602 | 12509 |
| pg_ampro | 2603 | 12514 |
| pg_attrdef | 2604 | 12469 |
| pg_cast | 2605 | 12549 |
| pg_constraint | 2606 | 12476 |
| pg_conversion | 2607 | 12562 |
| pg_depend | 2608 | 12567 |
| pg_description | 2609 | 12543 |
| pg_index | 2610 | 12489 |
| pg_inherits | 2611 | 12485 |
| pg_language | 2612 | 12518 |
| pg_largeobject | 2613 | 12571 |
| pg_namespace | 2615 | 12558 |
| pg_opclass | 2616 | 12501 |
| pg_operator | 2617 | 12493 |
| pg_rewrite | 2618 | 12528 |
| pg_stastic | 2619 | 12436 |
| pg_trigger | 2620 | 12535 |
| pg_opfamily | 2753 | 12497 |
| pg_db_role_setting | 2964 | 12581 |
| pg_largeobject_metadata | 2995 | 12522 |
| pg_extension | 3079 | 12627 |
| pg_foreign_table | 3118 | 12639 |
| pg_collation | 3456 | 12652 |
| pg_enum | 3501 | 12553 |
| pg_seclabel | 3596 | 12646 |
| pg_ts_dict | 3600 | 12615 |
| pg_ts_parser | 3601 | 12619 |
| pg_ts_config | 3602 | 12608 |
| pg_ts_config_map | 3603 | 12612 |
| pg_ts_template | 3764 | 12623 |
如果进一步查看,还可以发现:
只有如下几个系统表的对应文件位于 global目录,其余的系统表的对应文件则是base目录下的每个子目录中都有(一个子目录对应一个数据库):
| system table name | RelationId | FileName |
| pg_pltemplate | 1136 | 12591 |
| pg_tablespace | 1213 | 12587 |
| pg_shdepend | 1214 | 12598 |
| pg_authid | 1260 | 12450 |
| pg_auth_members | 1261 | 12594 |
| pg_database | 1262 | 12692 |
| pg_shdescription | 2396 | 12602 |
| pg_db_role_setting | 2964 | 12581 |
对PostgreSQL中 pg_各表的RelationId的认识的更多相关文章
- PostgreSQL中使用外部表
1. 安装file_fdw 需要先安装file_fdw,一般是进到PostgreSQL的源码包中的contrib/file_fdw目录下,执行: make make install 然后进入数据库中, ...
- PostgreSQL中数据库,表,等对象的oid与对象名的对应关系
-bash-4.1$ oid2name Password: All databases: Oid Database Name Tablespace--------------------------- ...
- PostgreSQL中关于关键字(保留字)在表名和字段名中的应用文件解决
标识符和关键词 受限标识符或被引号修饰的标识符.它是由双引号(")包围的一个任意字符序列.一个受限标识符总是一个标识符而不会是一个关键字.因此"select"可以用于引用 ...
- PostgreSQL 中日期类型转换与变量使用及相关问题
PostgreSQL中日期类型与字符串类型的转换方法 示例如下: postgres=# select current_date; date ------------ 2015-08-31 (1 row ...
- 在PostgreSQL中使用oracle_fdw访问Oracle
本文讲述如何在PostgreSQL中使用oracle_fdw访问Oracle上的数据. 1. 安装oracle_fdw 可以参照:oracle_fdw in github 编译安装oracle_fdw ...
- [转] PostgreSQL学习手册(数据表)
from: http://www.cnblogs.com/stephen-liu74/archive/2012/04/23/2290803.html 一.表的定义: 对于任何一种关系型数据库而言,表都 ...
- Postgresql中临时表(temporary table)的特性和用法
熟悉Oracle的人,相比对临时表(temporary table)并不陌生,很多场景对解决问题起到不错的作用,开源库Postgresql中,也有临时表的概念,虽然和Oracle中临时表名字相同,使用 ...
- Django中的跨表查询,多表查询。
一:Django中的ORM进行操作. 必须掌握的十三条: <1> all(): 查询所有结果 <2> filter(**kwargs): 它包含了与所给筛选条件相匹配的对象 & ...
- Postgresql中的数据类型大全
一.数值类型: 下面是PostgreSQL所支持的数值类型的列表和简单说明: 名字 存储空间 描述 范围 smallint 2 字节 小范围整数 -32768 到 +32767 integer 4 字 ...
随机推荐
- 对于随机变量的标准差standard deviation、样本标准差sample standard deviation、标准误差standard error的解释
参考:http://blog.csdn.net/ysuncn/article/details/1749729
- 【JSP】JSP检查字符串是否为数字
//判断是否是正整数 function IsNum(s) { if(s!=null){ var r,re; re = /\d*/i; //\d表示数字,*表示匹配多个数字 r = s.match(re ...
- Launcher2编译
Android的源码包,压缩文件大概有3个G左右,要使用其中自带的一些源码需要很多技巧,否则会提示找不到一些库,大量的报错让人心神不定,不知所从. 我拿桌面代码举个例子吧. 桌面代码在源码包的pack ...
- acdream 1044
题意:有你一个草坪,草的初始高度都是100,让你用割草机割,割草机只能横着或竖着割,每次割的高度一定,问你能不能割出给定的草坪出来. 考虑任意一个草被割要么是横着要么竖着,所以任意一个草必然是它所在行 ...
- 基于wke封装的duilib的webkit浏览器控件,可以c++与js互交,源码及demo下载地址
转载请说明原出处,谢谢~~ 前些日子用wke内核封装了duilib的webkit浏览器控件,好多群里朋友私聊我希望可以我公布源码,今天把这个控件的源码和使用demo公布.其实这个控件封装起来没什么难度 ...
- [GRYZ]寒假模拟赛
写在前面 这是首次广饶一中的OIERS自编自导,自出自做(zuo)的模拟赛. 鉴于水平气压比较低,机(wei)智(suo)的WMY/XYD/HYXZC就上网FQ下海找了不少水(fei)题,经过他们优( ...
- 在ubuntu下配置android开发环境
http://developer.android.com/sdk/installing/index.html 基本上上面官网的链接可以解决所有问题,但是具体在安装过程中还是有一些坑. 说说具体流程 1 ...
- jq实现图片轮播:圆形焦点+左右控制+自动轮播
来源:http://www.ido321.com/862.html html代码: 1: <!DOCTYPE html> 2: <html lang="en"&g ...
- UNIX系统文件
密码文件 密码文件又称用户数据库,一般为/etc/passwd,对应的结构为struct passwd,该文件内容大体如下: 描述 passwd字段 用户名 char* pw_name 加密密码 ch ...
- Python对象初探
数据结构 PyObject_HEAD //对象公共头部 Py_ssize_t ob_refcnt; //对象引用数 PyTypeObject *ob_type; //对象类型 PyObject_V ...