PostgreSQL:Oid2name 介绍

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
[pg93@redhatB 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
[pg93@redhatB 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
[pg93@redhatB 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
[pg93@redhatB 16386]$ cd $PGDATA/pg_tblspc/16385
[pg93@redhatB 16385]$ cd PG_9.3_201305061/16386/

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

2.4 查看 16703 文件是什么

1
2
3
4
5
[pg93@redhatB 16386]$ oid2name -d francs -f 16703
From database "francs":
Filenode Table Name
-------------------------
16703 test_not_full

2.5 显示更多信息

1
2
3
4
5
[pg93@redhatB 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
[pg93@redhatB ~]$ psql francs francs -c "select oid,relname from pg_class where relname='test_1'";
oid | relname
-------+---------
16457 | test_1
(1 row)

[pg93@redhatB ~]$ oid2name -d francs -o 16457
From database "francs":
Filenode Table Name
----------------------
16457 test_1

参考

原创文章,作者:carmelaweatherly,如若转载,请注明出处:https://blog.ytso.com/237985.html

(0)
上一篇 2022年1月29日 22:56
下一篇 2022年1月29日

相关推荐

发表回复

登录后才能评论