如何在postgres中使用\ timing

aNa*_*ame 4 postgresql timing psql

我想知道在Postgres中执行查询所花费的时间,我看到很多建议使用\ timing的响应,但是我是Postgres中的新手,我不知道如何使用它,任何人都可以帮忙
先感谢您

Lau*_*lbe 5

由于这是命令,因此\timing只能与命令行客户端一起使用。psqlpsql

这是一个打开和关闭执行时间报告的开关:

test=> \timing
Timing is on.
test=> SELECT 42;
????????????
? ?column? ?
????????????
?       42 ?
????????????
(1 row)

Time: 0.745 ms
test=> \timing
Timing is off.
Run Code Online (Sandbox Code Playgroud)

  • 如果要测量将结果输出到文件所需的时间,可以在 UNIX 上使用“time”,如下所示:“time psql -P pager=off -c 'SELECT ...' >outfile” (2认同)