0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【処理時間】ログ出力設定

0
Posted at

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
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?