博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
postgresql中根据oid和filenode去找表的物理文件的位置
阅读量:4077 次
发布时间:2019-05-25

本文共 2821 字,大约阅读时间需要 9 分钟。

1.新建一张表postgres=# create table a(a int);CREATE TABLEpostgres=# select oid,relfilenode from pg_class where relname='a';  oid  | relfilenode -------+------------- 17107 |       17107(1 row)我们会发现,oid和filenode对应的值是一样的,去找一下对应表的物理文件[postgres@node2 13269]$ ls -l 17107-rw-------. 1 postgres postgres 0 Mar 20 06:43 17107[postgres@node2 13269]$ pwd/home/postgres/data/base/13269可以发现,我们可以找到想对应的物理文件去看一下,我之前建的一张表postgres=# select oid,relfilenode from pg_class where relname='test';  oid  | relfilenode -------+------------- 16478 |       16499(1 row)发现oid和filenode对应的值不一样。先查看数据库的oidpostgres=# select oid,datname from pg_database ;  oid  |  datname  -------+----------- 13269 | postgres     1 | template1 13268 | template0 16466 | test 17096 | database(5 rows)去找一下物理文件[postgres@node2 13269]$ ls -l  16478ls: cannot access 16478: No such file or directory[postgres@node2 13269]$ pwd/home/postgres/data/base/13269[postgres@node2 13269]$ ls -l  16499-rw-------. 1 postgres postgres 229376 Mar 14 13:56 16499[postgres@node2 13269]$ pwd/home/postgres/data/base/13269可以看出来我们根据oid找不到对应的物理文件,而根据filenode就找到了。原因:我们在对表进行过truncate或者vacuum操作以后,oid是不变的,而filenode是发生变化的postgres=# insert into a select generate_series(1,100);INSERT 0 100postgres=# select oid,relfilenode from pg_class where relname='a';  oid  | relfilenode -------+------------- 17107 |       17107(1 row)postgres=# truncate a;TRUNCATE TABLEpostgres=# select oid,relfilenode from pg_class where relname='a';  oid  | relfilenode -------+------------- 17107 |       17110(1 row)postgres=# insert into a select generate_series(101,200);INSERT 0 100postgres=# delete from a;DELETE 100postgres=# select oid,relfilenode from pg_class where relname='a';  oid  | relfilenode -------+------------- 17107 |       17110(1 row)postgres=# vacuum full a;VACUUMpostgres=# select oid,relfilenode from pg_class where relname='a';  oid  | relfilenode -------+------------- 17107 |       17111(1 row)所以根据oid去查找表的物理文件的位置是不靠谱的事情。2.查找表物理文件的方式:postgres=# select pg_relation_filepath('a'); pg_relation_filepath ---------------------- base/13269/17111(1 row)另一种方式为通过oid2name[postgres@node2 contrib]$ oid2nameAll databases:    Oid  Database Name  Tablespace----------------------------------  17096       database  pg_default  13269       postgres  pg_default  13268      template0  pg_default      1      template1  pg_default  16466           test  pg_default[postgres@node2 contrib]$ oid2name -d postgres From database "postgres":  Filenode        Table Name----------------------------     17111                 a     16493          lineitem     17089  pgbench_accounts     17086  pgbench_branches     17077   pgbench_history     17080   pgbench_tellers     16484                t3     16499              test     16490           ticket1如果没有oid2name则需要去postgresql解压目录下的contrib安装一下,make,    make install

转载地址:http://fbsni.baihongyu.com/

你可能感兴趣的文章
我发现无人机把Pixhawk2.4.8换成pixhawk4 不需要换很多东西,也不需要再焊什么东西
查看>>
**当你做东西卡住的时候,也是在提醒你需要花时间沉下来深入学东西了,不然做不出来的
查看>>
1-13 笔记
查看>>
pixhawk的offboard模式其实是和定高(AltHold) 定点(loiter) 这些模式平级的一个模式
查看>>
我发觉大家都在讲VINS
查看>>
OpenCV编程中的C++语法知识点回顾
查看>>
C++的模板化等等的确实比C用起来方便多了
查看>>
ROS是不是可以理解成一个虚拟机,就是操作系统之上的操作系统
查看>>
用STL algorithm轻松解决几道算法面试题
查看>>
ACfly之所以不怕炸机因为它觉得某个传感器数据不安全就立马不用了
查看>>
我发觉,不管是弄ROS OPENCV T265二次开发 SDK开发 caffe PX4 都是用的C++
查看>>
ROS的安装(包含文字和视频教程,我的ROS安装教程以这篇为准)
查看>>
国内有个码云,gitee
查看>>
我居然在GAAS的硬件清单上看到了权盛光流,又想起ZN无人机课程他们购买无人机配件也是在权盛
查看>>
原来我之前一直用的APM固件....现在很多东西明白了。
查看>>
GAAS提供的TX2镜像就给你装好了小觅SDK
查看>>
七月在线GAAS-2 ROS与OFFBOARD MODE 笔记
查看>>
我看了下GAAS里ROS里发布的pose 的 topic包含position和orientation,我觉得position是实际位置,orientation是期望位置。错了,是标准的里程计消息。
查看>>
realsense-ros里里程计相关代码
查看>>
transfer.py就是把vins的坐标系转为PX4的坐标系,其实也是个ROS功能包,包含代码分析。(最后发现是改成GAAS里pose的消息形式)
查看>>