支援的版本:目前 (17) / 16 / 15 / 14 / 13
開發版本:devel
不支援的版本:12 / 11 / 10 / 9.6 / 9.5 / 9.4 / 9.3 / 9.2 / 9.1 / 9.0 / 8.4 / 8.3

oid2name

oid2name — 在 PostgreSQL 資料目錄中解析 OID 和檔案節點

概要

oid2name [option...]

描述

oid2name 是一個工具程式,可協助管理員檢查 PostgreSQL 使用的檔案結構。 若要使用它,您需要熟悉資料庫檔案結構,這在第 65 章中說明。

注意

名稱 oid2name 具有歷史意義,實際上相當具有誤導性,因為在您使用它的時候,大多數時候您實際上會關注表格的 filenode 號碼(這些是資料庫目錄中可見的檔案名稱)。 請務必了解表格 OID 和表格 filenode 之間的差異!

oid2name 連線到目標資料庫並提取 OID、filenode 和/或表格名稱資訊。 您也可以讓它顯示資料庫 OID 或表空間 OID。

選項

oid2name 接受下列命令列引數

-f filenode
--filenode=filenode

顯示具有 filenode filenode 的表格的資訊。

-i
--indexes

在清單中包含索引和序列。

-o oid
--oid=oid

顯示具有 OID oid 的表格的資訊。

-q
--quiet

省略標頭(對於腳本編寫很有用)。

-s
--tablespaces

顯示表空間 OID。

-S
--system-objects

包含系統物件(位於 information_schemapg_toastpg_catalog 綱要中的物件)。

-t tablename_pattern
--table=tablename_pattern

顯示符合 tablename_pattern 的表格的資訊。

-V
--version

列印 oid2name 版本並結束。

-x
--extended

顯示有關每個顯示物件的更多資訊:表空間名稱、綱要名稱和 OID。

-?
--help

顯示有關 oid2name 命令列引數的說明,並結束。

oid2name 還接受下列用於連線參數的命令列引數

-d database
--dbname=database

要連線的資料庫。

-h host
--host=host

資料庫伺服器的主機。

-H host

資料庫伺服器的主機。 自 PostgreSQL 12 起,不建議使用此參數。

-p port
--port=port

資料庫伺服器的埠。

-U username
--username=username

要連線的使用者名稱。

若要顯示特定表格,請使用 -o-f 和/或 -t 選擇要顯示的表格。-o 採用 OID,-f 採用 filenode,而 -t 採用表格名稱(實際上,它是一個 LIKE 模式,因此您可以使用諸如 foo% 之類的東西)。 您可以根據需要使用任意數量的這些選項,並且清單將包含任何選項比對的所有物件。 但是請注意,這些選項只能顯示由 -d 給定的資料庫中的物件。

如果您未提供任何 -o-f-t,但提供了 -d,它將列出由 -d 命名的資料庫中的所有表格。 在此模式下,-S-i 選項控制列出的內容。

如果您未提供 -d,它將顯示資料庫 OID 的清單。 或者,您可以提供 -s 以取得表空間清單。

環境

PGHOST
PGPORT
PGUSER

預設連線參數。

與大多數其他 PostgreSQL 工具程式一樣,此工具程式也使用 libpq 支援的環境變數(請參閱第 32.15 節)。

環境變數 PG_COLOR 指定是否在診斷訊息中使用顏色。可能的值為 alwaysautonever

備註

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

提交更正

如果您在文件中發現任何不正確、與您對特定功能的經驗不符或需要進一步澄清的地方,請使用此表格回報文件問題。