他のバージョンの文書 15 | 14 | 13 | 12 | 11 | 10 | 9.6 | 9.5 | 9.4 | 9.3 | 9.2 | 9.1 | 9.0 | 8.4 | 8.3 | 8.2 | 8.1 | 8.0 | 7.4 | 7.3 | 7.2

oid2name

名前

oid2name -- OIDとPostgreSQLデータディレクトリ内のファイルノードを解決する

概要

oid2name [option...]

説明

oid2nameは、管理者がPostgreSQLで使用されるファイル構造を確認することを補助するユーティリティプログラムです。 使用できるようになるためには、第58章で説明されるデータベースファイル構造についての知識が必要です。

注意: "oid2name"という名前は歴史的なものであり、これを使用する場合のほとんどでは、本当はテーブルのファイルノード番号(これはデータベースディレクトリ内で可視なファイル名)が関係しますので、実際誤解されやすいものです。 テーブルのOIDとテーブルファイルノードの違いを確実に理解してください。

oid2nameは対象データベースに接続し、OID、ファイルノード、テーブル名情報を抽出します。 また、データベースOIDまたはテーブル空間OIDを示すようにさせることもできます。

オプション

oid2nameは以下のコマンドライン引数を受け付けます。

-f filenode

filenodeというファイルノードを持つテーブルの情報を表示します。

-i

一覧にインデックスおよびシーケンスを含めます。

-o oid

oidというOIDを持つテーブルの情報を表示します。

-q

ヘッダを省略します。(スクリプト処理に適しています)

-s

テーブル空間OIDを表示します。

-S

システムオブジェクト(information_schemapg_toastpg_catalogスキーマ内に存在するもの)を含めます。

-t tablename_pattern

tablename_patternに一致するテーブル(複数可)の情報を表示します。

-V
--version

oid2nameのバージョンを表示し、終了します。

-x

表示対象の各オブジェクトに関してさらに情報を表示します。テーブル空間名、スキーマ名、OID。

-?
--help

oid2nameのコマンドライン引数の説明を表示し、終了します。

またoid2nameは以下の接続用のパラメータに関するコマンドライン引数を受け付けます。

-d database

接続データベース

-H host

データベースサーバのホスト

-p port

データベースサーバのポート

-U username

接続ユーザ名

-P password

パスワード(廃止予定。コマンドラインに記述することはセキュリティ的に危険です。)

特定のテーブルを表示するために、-o-f-tを使用して表示するテーブルを選択してください。 -oはOIDを、-fはファイルノードを、-tはテーブル名(実際はLIKEパターンです。ですのでfoo%などが使用できます)を引数として取ります。 これらのオプションを必要なだけ使用することができます。 一覧には、オプションのいずれかで一致したオブジェクトがすべて含まれます。 しかしこれらのオプションでは、-dで指定したデータベース内に存在するオブジェクトしか表示しないことに注意してください。

-o-f-tのいずれも指定せずに-dを指定した場合、-dで指定したデータベース上のすべてのテーブルを列挙します。 このモードでは、-Sおよび-iスイッチが何を列挙するかを制御します。

-dも指定しなかった場合、データベースOIDの一覧を示します。 他にも-sを指定してテーブル空間の一覧を得ることもできます。

注釈

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

$ # I wonder what file 155173 is ...
$ 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