简体   繁体   English

如何在单个JdbcTemplate execute()和PostgreSQL中记录多个SQL查询的进度

[英]How can I log progress of multiple sql queries in a single JdbcTemplate execute() and PostgreSQL

I have a SQL script with many statements which I execute using JdbcTemplate.execute(). 我有一个包含许多使用JdbcTemplate.execute()执行的语句的SQL脚本。 Some queries are slow and I'd like to write progress of the whole script to the logs. 一些查询很慢,我想将整个脚本的进度写入日志。

As it stands, I only get logs written once all the statements have completed. 就目前而言,我只在所有语句完成后才写日志。

There is another way to get what you want. 还有另一种方式来获得您想要的东西。 Use the PostgreSQL server log . 使用PostgreSQL服务器日志 Set the options in the config file postgresql.conf and reload, or set parameters per session like this: 在配置文件postgresql.conf设置选项并重新加载,或按如下所示为每个会话设置参数:

Log every single SQL statement: 记录每个SQL语句:

set log_statement = 'all';

Or hunt for slow queries in particular, for example: everything that takes longer than 1000 ms: 或特别寻找慢速查询,例如:花费时间超过1000毫秒的所有内容:

set log_min_duration_statement = 1000;

The manual about logging-parameters : 有关记录参数的手册:

log_statement (enum) log_statement(枚举)

Controls which SQL statements are logged. 控制记录哪些SQL语句。 Valid values are none (off), ddl, mod, and all (all statements). 有效值为none(关闭),ddl,mod和all(所有语句)。

If you log everything remember to turn it off afterwards or the log files may grow huge. 如果您记录了所有内容,请记住事后将其关闭,否则日志文件可能会变得很大。

log_min_duration_statement (integer) log_min_duration_statement(整数)

Causes the duration of each completed statement to be logged if the statement ran for at least the specified number of milliseconds. 如果语句至少运行了指定的毫秒数,则导致记录每个完成的语句的持续时间。 Setting this to zero prints all statement durations. 将此设置为零将打印所有语句持续时间。 (...) (...)

The manual on how to set parameters . 有关如何设置参数的手册。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM