Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql 结合postgres查询和日志持续时间_Postgresql - Fatal编程技术网

Postgresql 结合postgres查询和日志持续时间

Postgresql 结合postgres查询和日志持续时间,postgresql,Postgresql,我知道您可以在postgresql.conf中使用下面的配置显示持续时间和日志查询 ------------------------------------------------------------------------------ CUSTOMIZED OPTIONS ------------------------------------------------------------------------------ log_statement = 'all' log_dur

我知道您可以在postgresql.conf中使用下面的配置显示持续时间和日志查询

------------------------------------------------------------------------------
 CUSTOMIZED OPTIONS
------------------------------------------------------------------------------

log_statement = 'all'
log_duration = on
log_line_prefix = '{"Time":[%t], Host:%h} '
然后返回如下日志

{"Time":[2018-08-13 16:24:20 +08], Host:172.18.0.2} LOG:  statement: SELECT "auth_user"."id", "auth_user"."password", "auth_user"."last_login", "auth_user"."is_superuser", "auth_user"."username", "auth_user"."first_name", "auth_user"."last_name", "auth_user"."email", "auth_user"."is_staff", "auth_user"."is_active", "auth_user"."date_joined" FROM "auth_user" WHERE "auth_user"."id" = 1
{"Time":[2018-08-13 16:24:20 +08], Host:172.18.0.2} LOG:  duration: 7.694 ms
但是我可以把持续时间和语句组合成一行吗

LOG: { statement: ..., duration: 7.694 ms}

按照您记录的方式,当服务器开始处理语句时,会记录该语句,但只有在执行结束时才知道持续时间

这就是为什么它必须记录为两条不同的消息


如果您使用
log\u min\u duration\u statement=0
,则该语句将在执行结束时与持续时间一起记录。

您是否尝试过
log\u min\u duration\u statement=0
?您的答案太完美了!!!!