LoginSignup
7
9

More than 5 years have passed since last update.

PostgreSQLでSQLファイルの実行速度を計測する

Last updated at Posted at 2017-08-18

PostgreSQLでSQLファイルに記述したSQL文の実行速度を計測したかったのでメモ。

\timingを使う

\timingを使えば簡単に実行速度の計算ができます。

command
db=# \timing \i select.sql

実行速度の計測を解除するには、もう一度\timingを実行します。

command
db=# \timing
タイミングは off です。

出力されるレコードが多いとき

上記のコマンドだと出力されるレコードが多いときに余計に時間がかかります。
そこで、実行結果を外部のファイル保存するようにします。
\oを使えば、出力するファイルを指定できます。

command
db=# \o out.log
db=# \timing \i select.sql
タイミングは on です。
時間: 2421.986 ms
db=#

外部のファイルへの保存を解除するには、もう一度\oを実行します。

command
db=# \o
7
9
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
7
9