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/access/transam | |
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/access/transam')
-rw-r--r-- | src/backend/access/transam/xact.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index e9ed92b70bb..b04fdb5d5ed 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -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 * |