From 6e3e6cc0e884a6091e1094dff29db430af08fb93 Mon Sep 17 00:00:00 2001 From: Tomas Vondra Date: Mon, 4 Nov 2019 01:57:45 +0100 Subject: 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 --- doc/src/sgml/config.sgml | 85 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) (limited to 'doc/src') diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml index 48d7939d2de..46bc31de4c4 100644 --- a/doc/src/sgml/config.sgml +++ b/doc/src/sgml/config.sgml @@ -5950,6 +5950,12 @@ local0.* /var/log/postgresql Only superusers can change this setting. + + This overrides , + meaning that queries with duration exceeding this setting are not + subject to sampling and are always logged. + + For clients using extended query protocol, durations of the Parse, Bind, and Execute steps are logged independently. @@ -5972,6 +5978,85 @@ local0.* /var/log/postgresql + + log_min_duration_sample (integer) + + log_min_duration_sample configuration parameter + + + + + Allows to sample the logging of the duration of each completed + statement if the statement ran for at least the specified amount of + time. If this value is specified without units, it is taken as milliseconds. + Setting this to zero samples all statement durations. + Minus-one (the default) disables sampling statement durations. + For example, if you set it to 250ms + then all SQL statements that run 250ms or longer will be considered + for sampling, with sample rate is controlled by . + Enabling this parameter can be helpful when the traffic too high to + sample all queries. + Only superusers can change this setting. + + + + This option has lower priority than , + meaning that statements with durations exceeding + are not subject to sampling and are always logged. + + + + For clients using extended query protocol, durations of the Parse, + Bind, and Execute steps are logged independently. + + + + + When using this option together with + , + the text of statements that are logged because of + log_statement will not be repeated in the + duration log message. + If you are not using syslog, it is recommended + that you log the PID or session ID using + + so that you can link the statement message to the later + duration message using the process ID or session ID. + + + + + + + log_statement_sample_rate (real) + + log_statement_sample_rate configuration parameter + + + + + Determines the fraction of statements with duration exceeding + to be logged. + This is a statistical parameter, for example 0.5 + means there is statistically one in two chances to log the statement. + The default is 1.0, meaning log all such + statements. + Setting this to zero disables sampling logging, same as setting + log_min_duration_sample to + -1. + log_statement_sample_rate is helpful when the + traffic is too high to log all queries. + Only superusers can change this setting. + + + + Like all statement-logging options, this option can add significant + overhead. + + + + + log_transaction_sample_rate (real) -- cgit v1.2.3