postgresql oid2name解析数据目录文件

cd /usr/lib/postgresql/9.3/bin

./oid2name --help

oid2name helps examining the file structure used by PostgreSQL.


Usage:

oid2name [OPTION]...


Options:

-d DBNAME database to connect to

-f FILENODE show info for table with given file node

-H HOSTNAME database server host or socket directory

-i show indexes and sequences too

-o OID show info for table with given OID

-p PORT database server port number

-q quiet (don't show headers)

-s show all tablespaces

-S show system objects too

-t TABLE show info for named table

-U NAME connect as specified database user

-V,--version output version information,then exit

-x extended (show additional columns)

-?,--help show this help,then exit


The default action is to show all database OIDs.


使用

列出所有库

postgres@db1:/usr/lib/postgresql/9.3/bin$ ./oid2name

All databases:

Oid Database Name Tablespace

---------------------------------------

16387 a pg_default

16388 b pg_default

16389 c pg_default

16477 d pg_default

32700 empty-next-release pg_default

12042 postgres pg_default

12037 template0 pg_default

1 template1 pg_default


列出所有表空间

postgres@db1:/usr/lib/postgresql/9.3/bin$ ./oid2name -s

All tablespaces:

Oid Tablespace Name

-----------------------

1663 pg_default

1664 pg_global


进入数据目录

cd /var/lib/postgresql/9.3/main/base/12037

postgres@db1:~/9.3/main/base/12037$ ls -ltr | tail -n 8

-rw------- 1 postgres postgres 16384 Oct 31 15:28 11904

-rw------- 1 postgres postgres 24576 Oct 31 15:28 11886_fsm

-rw------- 1 postgres postgres 8192 Oct 31 15:28 11879

-rw------- 1 postgres postgres 0 Oct 31 15:28 11861

-rw------- 1 postgres postgres 8192 Oct 31 15:28 11857_vm

-rw------- 1 postgres postgres 8192 Oct 31 15:28 11827

-rw------- 1 postgres postgres 516096 Oct 31 15:28 11797

-rw------- 1 postgres postgres 8192 Oct 31 15:28 11791


查看11791的文件是什么

postgres@db1:~/9.3/main/base/12037$ cd -

/usr/lib/postgresql/9.3/bin

postgres@db1:/usr/lib/postgresql/9.3/bin$ ./oid2name -d a -f 11791

From database "a":

Filenode Table Name

-------------------------------------

11791 pg_user_mapping_oid_index

显示更多的信息

postgres@db1:/usr/lib/postgresql/9.3/bin$ ./oid2name -d a -f 11791 -x

From database "a":

Filenode Table Name Oid Schema Tablespace

------------------------------------------------------------------

11791 pg_user_mapping_oid_index 174 pg_catalog pg_default

根据 oid 查对表信息

postgres@db1:/usr/lib/postgresql/9.3/bin$ psql -d a -c "select oid,relname from pg_class where relname='pg_user_mapping_oid_index'"

oid | relname

-----+---------------------------

174 | pg_user_mapping_oid_index

(1 row)


postgres@db1:/usr/lib/postgresql/9.3/bin$ ./oid2name -d a -o 174

From database "a":

Filenode Table Name

-------------------------------------

11791 pg_user_mapping_oid_index

相关文章

文章浏览阅读601次。Oracle的数据导入导出是一项基本的技能,...
文章浏览阅读553次。开头还是介绍一下群,如果感兴趣polardb...
文章浏览阅读3.5k次,点赞3次,收藏7次。折腾了两个小时多才...
文章浏览阅读2.7k次。JSON 代表 JavaScript Object Notation...
文章浏览阅读2.9k次,点赞2次,收藏6次。navicat 连接postgr...
文章浏览阅读1.4k次。postgre进阶sql,包含分组排序、JSON解...