diff options
author | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2019-04-03 18:43:59 -0300 |
---|---|---|
committer | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2019-04-03 18:43:59 -0300 |
commit | 799e220346f1387e823a4dbdc3b1c8c3cdc5c3e0 (patch) | |
tree | 3530d9162d2069475148fdb0db5218b1e1c02b4b /src/backend/tcop/postgres.c | |
parent | d8c0bd9fefa9c70a3f5613fba672fa92f08ea940 (diff) | |
download | postgresql-799e220346f1387e823a4dbdc3b1c8c3cdc5c3e0.tar.gz postgresql-799e220346f1387e823a4dbdc3b1c8c3cdc5c3e0.zip |
Log all statements from a sample of transactions
This is useful to obtain a view of the different transaction types in an
application, regardless of the durations of the statements each runs.
Author: Adrien Nayrat
Reviewed-by: Masahiko Sawada, Hayato Kuroda, Andres Freund
Diffstat (limited to 'src/backend/tcop/postgres.c')
-rw-r--r-- | src/backend/tcop/postgres.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c index f9ce3d8f22a..44a59e1d4fb 100644 --- a/src/backend/tcop/postgres.c +++ b/src/backend/tcop/postgres.c @@ -2194,6 +2194,8 @@ check_log_statement(List *stmt_list) * check_log_duration * Determine whether current command's duration should be logged. * If log_statement_sample_rate < 1.0, log only a sample. + * We also check if this statement in this transaction must be logged + * (regardless of its duration). * * Returns: * 0 if no logging is needed @@ -2209,7 +2211,7 @@ check_log_statement(List *stmt_list) int check_log_duration(char *msec_str, bool was_logged) { - if (log_duration || log_min_duration_statement >= 0) + if (log_duration || log_min_duration_statement >= 0 || xact_is_sampled) { long secs; int usecs; @@ -2243,11 +2245,11 @@ check_log_duration(char *msec_str, bool was_logged) (log_statement_sample_rate == 1 || random() <= log_statement_sample_rate * MAX_RANDOM_VALUE); - if ((exceeded && in_sample) || log_duration) + if ((exceeded && in_sample) || log_duration || xact_is_sampled) { snprintf(msec_str, 32, "%ld.%03d", secs * 1000 + msecs, usecs % 1000); - if (exceeded && !was_logged) + if ((exceeded || xact_is_sampled) && !was_logged) return 2; else return 1; |