1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-28 23:42:10 +03:00

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
This commit is contained in:
Alvaro Herrera
2019-04-03 18:43:59 -03:00
parent d8c0bd9fef
commit 799e220346
7 changed files with 60 additions and 3 deletions

View File

@ -264,6 +264,9 @@ static char *prepareGID;
*/
static bool forceSyncCommit = false;
/* Flag for logging statements in a transaction. */
bool xact_is_sampled = false;
/*
* Private context for transaction-abort work --- we reserve space for this
* at startup to ensure that AbortTransaction and AbortSubTransaction can work
@ -1903,6 +1906,11 @@ StartTransaction(void)
s->state = TRANS_START;
s->fullTransactionId = InvalidFullTransactionId; /* until assigned */
/* Determine if statements are logged in this transaction */
xact_is_sampled = log_xact_sample_rate != 0 &&
(log_xact_sample_rate == 1 ||
random() <= log_xact_sample_rate * MAX_RANDOM_VALUE);
/*
* initialize current transaction state fields
*