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


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章