[pgsql-jp: 29895] Re: 使用しているファイルサイズを調べたい
sugita @ sra.co.jp
sugita @ sra.co.jp
2003年 5月 15日 (木) 12:59:45 JST
From: sugita @ sra.co.jp
Subject: Re: [pgsql-jp: 29893] 使用しているファイルサイズを調べたい
Date: Thu, 15 May 2003 12:54:18 +0900 (JST)
杉田です。
From: "Emiko Kishi" <kishi @ b-b-net.com>
Subject: [pgsql-jp: 29893] 使用しているファイルサイズを調べたい
Date: Thu, 15 May 2003 11:15:06 +0900
;;; そのとき実測値として、「pg_class.relpagesを合計したもの×8kb」
;;; を使用しようとしていますが、これは妥当な値なのでしょうか?
はい。
;;; 私が調べた限りでは、VACUUM ANALYZE した直後であれば
;;; 正しい値が入っているように思えたのですが・・・。
;;; # レンタルサーバのため、データフォルダを自由に見ることができません。
http://www.sra.co.jp/people/sugita/pg_chkrel.tgz は、テーブルディスク使用量
及びテーブルとインデックスの不要領域計測スクリプトです。このスクリプトを読んで
頂くとどのようにすればよいか分かると思います。このスクリプトでは、リモート接続
した場合には、ファイル領域の実サイズは調べませんので、データフォルダが見えなく
ても使えます。
PostgreSQL 7.0〜7.3 で使用できます。pg_chkrel のコマンドラインシンタックスは、
以下のようになっています。
$ pg_chkrel --help
Usage:
pg_chkrel [options] [dbname [username]]
Options:
-D <dbdir> Specify database directory (default: /Volumes/Home/Users/pgsql/7.3.1/data)
-d <dbname> Specify database name to connect to (default: sugita)
-h <host> Specify database server host (default: domain socket)
-p <port> Specify database server port (default: hardwired)
-U <username> Specify database username (default: sugita)
-k {r|i|a} Specify relation (r), index (i) or all (a) (default: a)
-s <pagesize> Specify page size of heap file (default: 8 KB)
--help show this help, then exit
--version output version information, then exit
$
表示欄は以下のようになっています。
Relation Name … テーブル、インデックス、TOAST の名前。
File Name … テーブル、インデックス、TOAST のファイル名。
Tuples … 統計情報のタプル数。
Pages … 統計情報のページ数。括弧内は、PostgreSQL 7.2 で
有効で、テーブルの場合、そのインデックスと TOAST
を含むテーブル占有ディスク量。
File Size … ローカル接続の場合には、実際のファイルサイズ (KB)。
リモート接続の場合には、Tuples * Pages * ページ
サイズ。
Size/Tuples … File Size/Tuples (KB)。
Tuple Size … 統計情報の平均タプル長 (KB)。PostgreSQL 7.2 以上
で有効。
VACUUM ANALYZE を行った後に pg_chkrel で計測します。判断方法は、Tuples があ
る程度多い場合に、Size/Tuples が大き過ぎる場合は、ゴミの量が多いと判断できます。
PostgreSQL 7.2 以上の場合には、統計情報の平均タプルサイズ Tuple Size との比較
でも判断可能です。
以下は、PostgreSQL 7.3 での実行例です。数千回の一時テーブルを作成した直後で、
pg_catalog.pg_attribute_relid_attnam_index は Tuples が 1290 個ですが、
Size/Tuples が 16 KB と極端に大きくなっています。インデックスは、ゴミがない場
合に、通常 60% が有効領域であることを考えても、かなりゴミ領域があると判断でき
ます。このことは、REINDEX 後の pg_chkrel で 99B に減っている事からも分かります。
==== pg_chkrel の実行結果 ====
Date : Wed May 7 11:45:11 JST 2003
Host : localhost
User : sugita
Database Host : default (local)
Database Name : sugita (16976)
Database User : sugita (1)
Database Port : default
Database Directory : /opt/pgsql/7.3.1/data
Version : PostgreSQL 7.3.1 on i686-pc-linux-gnu, compiled by GCC 2.95.3
Page Size (KB) : 8 (default)
Relation Name File Name Tuples Pages File Size Size/Tuples Tuple Size
r pg_catalog.pg_aggregate 16406 60 1 ( 3) 8 0.133 0.027
i pg_catalog.pg_aggregate_fnoid_index 16600 60 2 ( 2) 16 0.133 -.---
r pg_catalog.pg_am 16396 4 1 ( 5) 8 2.000 0.118
i pg_catalog.pg_am_name_index 16601 4 2 ( 2) 16 2.000 -.---
i pg_catalog.pg_am_oid_index 16602 4 2 ( 2) 16 2.000 -.---
r pg_catalog.pg_amop 16398 180 1 ( 5) 8 0.044 0.011
i pg_catalog.pg_amop_opc_opr_index 16603 180 2 ( 2) 16 0.044 -.---
i pg_catalog.pg_amop_opc_strategy_index 16604 180 2 ( 2) 16 0.044 -.---
r pg_catalog.pg_amproc 16400 57 1 ( 3) 8 0.140 0.010
i pg_catalog.pg_amproc_opc_procnum_index 16605 57 2 ( 2) 16 0.140 -.---
r pg_catalog.pg_attrdef 16384 1 1 ( 6) 8 8.000 0.336
i pg_catalog.pg_attrdef_adrelid_adnum_index 16606 1 2 ( 2) 16 8.000 -.---
i pg_catalog.pg_attrdef_oid_index 16607 1 2 ( 2) 16 8.000 -.---
r pg_catalog.pg_attribute 1249 1290 22 ( 3240) 176 0.136 0.068
i pg_catalog.pg_attribute_relid_attnam_index 16608 1290 2578 ( 2578) 20624 15.981 -.---
i pg_catalog.pg_attribute_relid_attnum_index 16609 1290 640 ( 640) 5120 3.963 -.---
...
r public.c1 1046332 1002 12 ( 41) 96 0.096 0.004
i public.c1_id_2_index 1047342 1002 5 ( 5) 40 0.032 -.---
i public.c1_id_index 1046337 1002 5 ( 5) 40 0.032 -.---
r public.c2 1347362 1000000 4406 ( 8792) 35248 0.035 0.004
i public.c2_id_1_index 2347379 1000000 2193 ( 2193) 17544 0.018 -.---
i public.c2_id_index 2347378 1000000 2193 ( 2193) 17544 0.018 -.---
...
Total 169512
==== REINDEX、VACUUM ANALYZE 後の pg_cherel の実行結果 ====
Date : Wed May 7 13:45:15 JST 2003
Host : localhost
User : sugita
Database Host : default (local)
Database Name : sugita (16976)
Database User : sugita (1)
Database Port : default
Database Directory : /opt/pgsql/7.3.1/data
Version : PostgreSQL 7.3.1 on i686-pc-linux-gnu, compiled by GCC 2.95.3
Page Size (KB) : 8 (default)
Relation Name File Name Tuples Pages File Size Size/Tuples Tuple Size
r pg_catalog.pg_aggregate 16406 60 1 ( 3) 8 0.133 0.027
i pg_catalog.pg_aggregate_fnoid_index 6727465 60 2 ( 2) 16 0.133 -.---
r pg_catalog.pg_am 16396 4 1 ( 5) 8 2.000 0.118
i pg_catalog.pg_am_name_index 6727459 4 2 ( 2) 16 2.000 -.---
i pg_catalog.pg_am_oid_index 6727460 4 2 ( 2) 16 2.000 -.---
r pg_catalog.pg_amop 16398 180 1 ( 5) 8 0.044 0.011
i pg_catalog.pg_amop_opc_opr_index 6727461 180 2 ( 2) 16 0.044 -.---
i pg_catalog.pg_amop_opc_strategy_index 16604 180 2 ( 2) 16 0.044 -.---
r pg_catalog.pg_amproc 16400 57 1 ( 3) 8 0.140 0.010
i pg_catalog.pg_amproc_opc_procnum_index 16605 57 2 ( 2) 16 0.140 -.---
r pg_catalog.pg_attrdef 16384 1 1 ( 6) 8 8.000 0.336
i pg_catalog.pg_attrdef_adrelid_adnum_index 6727479 1 2 ( 2) 16 8.000 -.---
i pg_catalog.pg_attrdef_oid_index 6727480 1 2 ( 2) 16 8.000 -.---
r pg_catalog.pg_attribute 1249 1290 22 ( 45) 176 0.136 0.068
i pg_catalog.pg_attribute_relid_attnam_index 6727453 1290 17 ( 17) 136 0.099 -.---
i pg_catalog.pg_attribute_relid_attnum_index 16609 1290 6 ( 6) 48 0.031 -.---
...
r public.c1 1046332 1002 12 ( 41) 96 0.096 0.004
i public.c1_id_2_index 1047342 1002 5 ( 5) 40 0.032 -.---
i public.c1_id_index 1046337 1002 5 ( 5) 40 0.032 -.---
r public.c2 1347362 1000000 4406 ( 8792) 35248 0.035 0.004
i public.c2_id_1_index 2347379 1000000 2193 ( 2193) 17544 0.018 -.---
i public.c2_id_index 2347378 1000000 2193 ( 2193) 17544 0.018 -.---
...
Total 134264
Kenji Sugita
pgsql-jp メーリングリストの案内