oid2name — 解析 PostgreSQL 資料目錄中的 OID 和檔案節點
oid2name [選項...]
oid2name 是一個實用程式,可幫助管理員檢查 PostgreSQL 使用的檔案結構。要使用它,您需要熟悉資料庫檔案結構,該結構在 第 66 章 中進行了描述。
名稱 “oid2name” 是歷史原因,實際上相當具有誤導性,因為大多數時候您使用它時,實際上關心的是表的 filenode 號(這是在資料庫目錄中可見的檔名)。請務必理解表 OID 和表 filenode 之間的區別!
oid2name 連線到目標資料庫並提取 OID、filenode 和/或表名資訊。您還可以讓它顯示資料庫 OID 或表空間 OID。
oid2name 接受以下命令列引數
-f filenode--filenode=filenode顯示具有 filenode filenode 的表的 istream 資訊。
-i--indexes包括列表中的索引和序列。
-o oid--oid=oid顯示具有 OID oid 的表的 istream 資訊。
-q--quiet省略標題(適用於指令碼)。
-s--tablespaces顯示錶空間 OID。
-S--system-objects包括系統物件(位於 information_schema、pg_toast 和 pg_catalog 模式中的物件)。
-t tablename_pattern--table=tablename_pattern顯示與 tablename_pattern 匹配的表的 istream 資訊。
-V--version列印 oid2name 版本並退出。
-x--extended顯示有關每個物件的更多資訊:表空間名稱、模式名稱和 OID。
-?--help顯示有關 oid2name 命令列引數的幫助,然後退出。
oid2name 還接受以下用於連線引數的命令列引數
-d database--dbname=database要連線的資料庫。
-h 主機--host=主機資料庫伺服器的主機。
-H host資料庫伺服器的主機。從 PostgreSQL 12 開始,此引數的使用已棄用。
-p 埠--port=埠資料庫伺服器的埠。
-U 使用者名稱--username=使用者名稱要連線的使用者。
要顯示特定表,請使用 -o、-f 和/或 -t 選擇要顯示的表。 -o 接受 OID,-f 接受 filenode,-t 接受表名(實際上,它是一個 LIKE 模式,因此您可以使用 foo% 之類的內容)。您可以使用任意多個這些選項,並且列表將包括所有匹配任何選項的物件。但請注意,這些選項只能顯示 -d 給出的資料庫中的物件。
如果您不提供 -o、-f 或 -t,但提供了 -d,它將列出 -d 指定的資料庫中的所有表。在此模式下,-S 和 -i 選項控制要列出的內容。
如果您也不提供 -d,它將顯示資料庫 OID 的列表。或者,您可以提供 -s 來獲取表空間列表。
PGHOSTPGPORTPGUSER預設連線引數。
此實用程式以及大多數其他 PostgreSQL 實用程式也使用 libpq 支援的環境變數(請參閱 第 32.15 節)。
環境變數 PG_COLOR 指定是否在診斷訊息中使用顏色。可能的值為 always、auto 和 never。
oid2name 需要一個正在執行的資料庫伺服器,且系統目錄未損壞。因此,在從災難性的資料庫損壞情況中恢復時,它的作用有限。
$ # what's in this database server, anyway?
$ oid2name
All databases:
Oid Database Name Tablespace
----------------------------------
17228 alvherre pg_default
17255 regression pg_default
17227 template0 pg_default
1 template1 pg_default
$ oid2name -s
All tablespaces:
Oid Tablespace Name
-------------------------
1663 pg_default
1664 pg_global
155151 fastdisk
155152 bigdisk
$ # OK, let's look into database alvherre
$ cd $PGDATA/base/17228
$ # get top 10 db objects in the default tablespace, ordered by size
$ ls -lS * | head -10
-rw------- 1 alvherre alvherre 136536064 sep 14 09:51 155173
-rw------- 1 alvherre alvherre 17965056 sep 14 09:51 1155291
-rw------- 1 alvherre alvherre 1204224 sep 14 09:51 16717
-rw------- 1 alvherre alvherre 581632 sep 6 17:51 1255
-rw------- 1 alvherre alvherre 237568 sep 14 09:50 16674
-rw------- 1 alvherre alvherre 212992 sep 14 09:51 1249
-rw------- 1 alvherre alvherre 204800 sep 14 09:51 16684
-rw------- 1 alvherre alvherre 196608 sep 14 09:50 16700
-rw------- 1 alvherre alvherre 163840 sep 14 09:50 16699
-rw------- 1 alvherre alvherre 122880 sep 6 17:51 16751
$ # What file is 155173?
$ oid2name -d alvherre -f 155173
From database "alvherre":
Filenode Table Name
----------------------
155173 accounts
$ # you can ask for more than one object
$ oid2name -d alvherre -f 155173 -f 1155291
From database "alvherre":
Filenode Table Name
-------------------------
155173 accounts
1155291 accounts_pkey
$ # you can mix the options, and get more details with -x
$ oid2name -d alvherre -t accounts -f 1155291 -x
From database "alvherre":
Filenode Table Name Oid Schema Tablespace
------------------------------------------------------
155173 accounts 155173 public pg_default
1155291 accounts_pkey 1155291 public pg_default
$ # show disk space for every db object
$ du [0-9]* |
> while read SIZE FILENODE
> do
> echo "$SIZE `oid2name -q -d alvherre -i -f $FILENODE`"
> done
16 1155287 branches_pkey
16 1155289 tellers_pkey
17561 1155291 accounts_pkey
...
$ # same, but sort by size
$ du [0-9]* | sort -rn | while read SIZE FN
> do
> echo "$SIZE `oid2name -q -d alvherre -f $FN`"
> done
133466 155173 accounts
17561 1155291 accounts_pkey
1177 16717 pg_proc_proname_args_nsp_index
...
$ # If you want to see what's in tablespaces, use the pg_tblspc directory
$ cd $PGDATA/pg_tblspc
$ oid2name -s
All tablespaces:
Oid Tablespace Name
-------------------------
1663 pg_default
1664 pg_global
155151 fastdisk
155152 bigdisk
$ # what databases have objects in tablespace "fastdisk"?
$ ls -d 155151/*
155151/17228/ 155151/PG_VERSION
$ # Oh, what was database 17228 again?
$ oid2name
All databases:
Oid Database Name Tablespace
----------------------------------
17228 alvherre pg_default
17255 regression pg_default
17227 template0 pg_default
1 template1 pg_default
$ # Let's see what objects does this database have in the tablespace.
$ cd 155151/17228
$ ls -l
total 0
-rw------- 1 postgres postgres 0 sep 13 23:20 155156
$ # OK, this is a pretty small table ... but which one is it?
$ oid2name -d alvherre -f 155156
From database "alvherre":
Filenode Table Name
----------------------
155156 foo
B. Palmer <bpalmer@crimelabs.net>
如果您在文件中發現任何不正確、與您對特定功能的體驗不符或需要進一步澄清的內容,請使用 此表單 報告文件問題。