バージョンごとのドキュメント一覧

29.1. ディスク使用量の決定 #

<title>Determining Disk Usage</title>

Each table has a primary heap disk file where most of the data is stored. If the table has any columns with potentially-wide values, there also might be a <acronym>TOAST</acronym> file associated with the table, which is used to store values too wide to fit comfortably in the main table (see <xref linkend="storage-toast"/>). There will be one valid index on the <acronym>TOAST</acronym> table, if present. There also might be indexes associated with the base table. Each table and index is stored in a separate disk file &mdash; possibly more than one file, if the file would exceed one gigabyte. Naming conventions for these files are described in <xref linkend="storage-file-layout"/>. 各テーブルには、データの大部分が格納されるプライマリヒープディスクファイルが備わっています。 もしテーブルが、長くなる可能性のある値を持つ列を持つ時は、テーブルに関連付けられたTOASTファイルもあるかもしれません。 このファイルは、メインテーブルに収納するには大き過ぎる値をテーブルに格納するために使用されます(73.2を参照してください)。 TOASTテーブルが存在する場合は、そのテーブルに有効なインデックスが1つあります。 基本テーブルに関連付けられたインデックスが存在することもあります。 テーブルとインデックスはそれぞれ別のディスクファイルに格納されます。 このファイルが1ギガバイトを超える場合は、複数のファイルになります。 これらのファイルの命名規約について73.1で説明します。

You can monitor disk space in three ways: using the SQL functions listed in <xref linkend="functions-admin-dbsize"/>, using the <xref linkend="oid2name"/> module, or using manual inspection of the system catalogs. The SQL functions are the easiest to use and are generally recommended. The remainder of this section shows how to do it by inspection of the system catalogs. ディスクスペースの監視は、次の3つの方法で行えます。 表 9.96にあるSQL関数を使用する方法と oid2nameモジュールを使用する方法、およびシステムカタログを手動で調べる方法です。 SQL関数を使用する方法が、一般的に一番簡単な方法です。 本セクションの残りの部分で、システムカタログを調査することによりこの方法を示します。

Using <application>psql</application> on a recently vacuumed or analyzed database, you can issue queries to see the disk usage of any table: バキュームされて間もないデータベース、もしくは解析されたデータベース上でpsqlを使用することにより、どのようなテーブルでもディスクの使用量を調べる問い合わせを発行できます。

SELECT pg_relation_filepath(oid), relpages FROM pg_class WHERE relname = 'customer';

 pg_relation_filepath | relpages
----------------------+----------
 base/16384/16806     |       60
(1 row)

Each page is typically 8 kilobytes. (Remember, <structfield>relpages</structfield> is only updated by <command>VACUUM</command>, <command>ANALYZE</command>, and a few DDL commands such as <command>CREATE INDEX</command>.) The file path name is of interest if you want to examine the table's disk file directly. 1ページは通常8キロバイトです (relpagesVACUUMANALYZE、さらにCREATE INDEXといったいくつかのDDLによってのみ更新されることに注意してください)。 もしテーブルのディスクファイルを直接調べるときは、ファイルのパス名称に注目して下さい。

To show the space used by <acronym>TOAST</acronym> tables, use a query like the following: TOASTテーブルで使用されている容量を示すには、以下のような問い合わせを使用してください。

SELECT relname, relpages
FROM pg_class,
     (SELECT reltoastrelid
      FROM pg_class
      WHERE relname = 'customer') AS ss
WHERE oid = ss.reltoastrelid OR
      oid = (SELECT indexrelid
             FROM pg_index
             WHERE indrelid = ss.reltoastrelid)
ORDER BY relname;

       relname        | relpages
----------------------+----------
 pg_toast_16806       |        0
 pg_toast_16806_index |        1

You can easily display index sizes, too: インデックスサイズについても、以下のように簡単に表示できます。

SELECT c2.relname, c2.relpages
FROM pg_class c, pg_class c2, pg_index i
WHERE c.relname = 'customer' AND
      c.oid = i.indrelid AND
      c2.oid = i.indexrelid
ORDER BY c2.relname;

      relname      | relpages
-------------------+----------
 customer_id_index |       26

It is easy to find your largest tables and indexes using this information: この情報を使用して、以下のように簡単に最大のテーブルとインデックスを見つけ出すことができます。

SELECT relname, relpages
FROM pg_class
ORDER BY relpages DESC;

       relname        | relpages
----------------------+----------
 bigtable             |     3290
 customer             |     3144