mirror of
https://github.com/postgres/postgres.git
synced 2025-07-18 17:42:25 +03:00
Allow sampling of statements depending on duration
This allows logging a sample of statements, without incurring excessive log traffic (which may impact performance). This can be useful when analyzing workloads with lots of short queries. The sampling is configured using two new GUC parameters: * log_min_duration_sample - minimum required statement duration * log_statement_sample_rate - sample rate (0.0 - 1.0) Only statements with duration exceeding log_min_duration_sample are considered for sampling. To enable sampling, both those GUCs have to be set correctly. The existing log_min_duration_statement GUC has a higher priority, i.e. statements with duration exceeding log_min_duration_statement will be always logged, irrespectedly of how the sampling is configured. This means only configurations log_min_duration_sample < log_min_duration_statement do actually sample the statements, instead of logging everything. Author: Adrien Nayrat Reviewed-by: David Rowley, Vik Fearing, Tomas Vondra Discussion: https://postgr.es/m/bbe0a1a8-a8f7-3be2-155a-888e661cc06c@anayrat.info
This commit is contained in:
@ -509,8 +509,10 @@ bool session_auth_is_superuser;
|
||||
int log_min_error_statement = ERROR;
|
||||
int log_min_messages = WARNING;
|
||||
int client_min_messages = NOTICE;
|
||||
int log_min_duration_sample = -1;
|
||||
int log_min_duration_statement = -1;
|
||||
int log_temp_files = -1;
|
||||
double log_statement_sample_rate = 1.0;
|
||||
double log_xact_sample_rate = 0;
|
||||
int trace_recovery_messages = LOG;
|
||||
|
||||
@ -2700,10 +2702,23 @@ static struct config_int ConfigureNamesInt[] =
|
||||
NULL, NULL, NULL
|
||||
},
|
||||
|
||||
{
|
||||
{"log_min_duration_sample", PGC_SUSET, LOGGING_WHEN,
|
||||
gettext_noop("Sets the minimum execution time above which "
|
||||
"a sample of statements will be logged."
|
||||
" Sampling is determined by log_statement_sample_rate."),
|
||||
gettext_noop("Zero log a sample of all queries. -1 turns this feature off."),
|
||||
GUC_UNIT_MS
|
||||
},
|
||||
&log_min_duration_sample,
|
||||
-1, -1, INT_MAX,
|
||||
NULL, NULL, NULL
|
||||
},
|
||||
|
||||
{
|
||||
{"log_min_duration_statement", PGC_SUSET, LOGGING_WHEN,
|
||||
gettext_noop("Sets the minimum execution time above which "
|
||||
"statements will be logged."),
|
||||
"all statements will be logged."),
|
||||
gettext_noop("Zero prints all queries. -1 turns this feature off."),
|
||||
GUC_UNIT_MS
|
||||
},
|
||||
@ -3430,6 +3445,16 @@ static struct config_real ConfigureNamesReal[] =
|
||||
NULL, NULL, NULL
|
||||
},
|
||||
|
||||
{
|
||||
{"log_statement_sample_rate", PGC_SUSET, LOGGING_WHEN,
|
||||
gettext_noop("Fraction of statements exceeding log_min_duration_sample to be logged."),
|
||||
gettext_noop("Use a value between 0.0 (never log) and 1.0 (always log).")
|
||||
},
|
||||
&log_statement_sample_rate,
|
||||
1.0, 0.0, 1.0,
|
||||
NULL, NULL, NULL
|
||||
},
|
||||
|
||||
{
|
||||
{"log_transaction_sample_rate", PGC_SUSET, LOGGING_WHEN,
|
||||
gettext_noop("Set the fraction of transactions to log for new transactions."),
|
||||
|
Reference in New Issue
Block a user