前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >oid2name列出PostgreSQL和对应的oid

oid2name列出PostgreSQL和对应的oid

原创
作者头像
DB之路
修改2021-03-15 17:47:32
1.2K0
修改2021-03-15 17:47:32
举报
文章被收录于专栏:数据库PG数据库PG

PostgreSQL 提供 oid2name 客户端程序,用来解析数据目录里的文件,平常用得比较少,这里简单介绍下。

Oid2name 手册介绍

1.1 手册介绍

1 2 3 4 5 6 7 8 9 10

Name  oid2name -- resolve OIDs and file nodes in a PostgreSQL data directory   Synopsis  oid2name [option...]   Description  oid2name is a utility program that helps administrators to examine the file structure used by  PostgreSQL. To make use of it, you need to be familiar with the database file structure, which  is described in Chapter 56.

1.2 oid2name 参数

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25

[pg12@db12 pg_tblspc]$ 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 (dont 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.   Report bugs to <pgsql-bugs@postgresql.org>.

Oid2name 使用

2.1 列出所有库

1 2 3 4 5 6 7 8 9

[pg12@db12 pg_tblspc]$ oid2name All databases:   Oid Database Name   Tablespace -------------------------------------  16386 francs   tbs_francs  12895    postgres   pg_default  16390   source_db tbs_source_db  12890   template0   pg_default    1   template1   pg_default

2.2 列出所有表空间

1 2 3 4 5 6 7 8

[pg12@db12 pg_tblspc]$ oid2name -s All tablespaces:   Oid Tablespace Name ------------------------  1663    pg_default  1664    pg_global  16385 tbs_francs  16389  tbs_source_db

2.3 进入数据目录

1 2 3 4 5 6 7 8 9 10 11 12

[pg12@db12 16386]$ cd $PGDATA/pg_tblspc/16385 [pg12@db12 16385]$ cd PG_9.3_201305061/16386/   [pg12@db12 16386]$ ll | tail -n 8 -rw-------. 1 pg12 pg12 35M Jun 3 17:47 16702 -rw-------. 1 pg12 pg12 161M Jun 3 16:22 16703 -rw-------. 1 pg12 pg12 64K Jun 3 15:45 16703_fsm -rw-------. 1 pg12 pg12 8.0K Jun 3 16:14 16703_vm -rw-------. 1 pg12 pg12 35M Jun 3 15:45 16704 -rw-------. 1 pg12 pg12 512 May 15 10:30 pg_filenode.map -rw-------. 1 pg12 pg12 98K Jun 3 10:26 pg_internal.init -rw-------. 1 pg12 pg12  4 May 15 10:30 PG_VERSION

2.4 查看 16703 文件是什么

1 2 3 4 5

[pg12@db12 16386]$ oid2name -d francs -f 16703 From database "francs":  Filenode   Table Name -------------------------   16703 test_not_full

2.5 显示更多信息

1 2 3 4 5

[pg12@db12 16386]$ oid2name -d francs -f 16703 -x From database "francs":  Filenode   Table Name  Oid Schema Tablespace ----------------------------------------------------   16703 test_not_full 16688 francs tbs_francs

2.6 根据 oid 查对表信息

1 2 3 4 5 6 7 8 9 10 11

[pg12@db12 ~]$ psql francs francs -c "select oid,relname from pg_class where relname='test_1'";  oid | relname -------+--------- 16457 | test_1 (1 row)   [pg12@db12 ~]$ oid2name -d francs -o 16457 From database "francs":  Filenode Table Name ----------------------   16457   test_1

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档