slow_queryだと指定秒数の閾値を超えてるSQLしか取れないと思われますが、postgresqlのauto_explainを使ってログを出すと各SQLの処理時間が確認できます。
postgresql.logへの出力例
Sep 24 11:59:37 dev postgres[12692]: [21-1] LOG: duration: 0.518 ms plan:
Sep 24 11:59:37 dev postgres[12692]: [21-2] #011Query Text: UPDATE dtb_session SET sess_data= $1, update_date= CURRENT_TIMESTAMP WHERE sess_id = $2
Sep 24 11:59:37 dev postgres[12692]: [21-3] #011Update on dtb_session (cost=0.00..6.07 rows=1 width=47)
Sep 24 11:59:37 dev postgres[12692]: [21-4] #011 -> Seq Scan on dtb_session (cost=0.00..6.07 rows=1 width=47)
Sep 24 11:59:37 dev postgres[12692]: [21-5] #011 Filter: (sess_id = $2)
設定にはpostgresqlのモジュールコンパイルが必要です。
以下設定手順です。
バージョンは適宜読み替えてください。
$ cd /usr/local/src
$ tar zxvf postgresql-9.1.9.tar.gz
$ cd postgresql-9.1.9
$ cp -i ../config.nice-postgresql-9.1.9 .
$ ./config.nice-postgresql-9.1.9
$ make
※ make installはしないこと!
$ cd contrib/auto_explain
$ make
$ make install
※こっちはmake installする。
postgresql.confへの追記
$ vi /var/lib/pgsql/data/postgresql.conf
で、以下の行がコメントアウトされている。
# shared_preload_libraries = '' # (change requires restart)
shared_preload_libraries = ‘auto_explain' # (change requires restart)
# custom_variable_classes = '' # list of custom variable class names
custom_variable_classes = 'auto_explain' # list of custom variable class names
postgresqlをリスタートする。
$ /etc/init.d/pgsql restart