mirror of
https://github.com/postgres/postgres.git
synced 2025-08-31 17:02:12 +03:00
Improve user control over truncation of logged bind-parameter values.
This patch replaces the boolean GUC log_parameters_on_error introduced
by commit ba79cb5dc
with an integer log_parameter_max_length_on_error,
adding the ability to specify how many bytes to trim each logged
parameter value to. (The previous coding hard-wired that choice at
64 bytes.)
In addition, add a new parameter log_parameter_max_length that provides
similar control over truncation of query parameters that are logged in
response to statement-logging options, as opposed to errors. Previous
releases always logged such parameters in full, possibly causing log
bloat.
For backwards compatibility with prior releases,
log_parameter_max_length defaults to -1 (log in full), while
log_parameter_max_length_on_error defaults to 0 (no logging).
Per discussion, log_parameter_max_length is SUSET since the DBA should
control routine logging behavior, but log_parameter_max_length_on_error
is USERSET because it also affects errcontext data sent back to the
client.
Alexey Bashtanov, editorialized a little by me
Discussion: https://postgr.es/m/b10493cc-a399-a03a-67c7-068f2791ee50@imap.cc
This commit is contained in:
@@ -27,7 +27,7 @@
|
||||
* appendStringInfoStringQuoted
|
||||
*
|
||||
* Append up to maxlen bytes from s to str, or the whole input string if
|
||||
* maxlen <= 0, adding single quotes around it and doubling all single quotes.
|
||||
* maxlen < 0, adding single quotes around it and doubling all single quotes.
|
||||
* Add an ellipsis if the copy is incomplete.
|
||||
*/
|
||||
void
|
||||
@@ -43,9 +43,9 @@ appendStringInfoStringQuoted(StringInfo str, const char *s, int maxlen)
|
||||
Assert(str != NULL);
|
||||
|
||||
slen = strlen(s);
|
||||
if (maxlen > 0 && maxlen < slen)
|
||||
if (maxlen >= 0 && maxlen < slen)
|
||||
{
|
||||
int finallen = pg_mbcliplen(s, slen, maxlen);
|
||||
int finallen = pg_mbcliplen(s, slen, maxlen);
|
||||
|
||||
copy = pnstrdup(s, finallen);
|
||||
chunk_search_start = copy;
|
||||
|
@@ -515,7 +515,6 @@ extern const struct config_enum_entry dynamic_shared_memory_options[];
|
||||
* GUC option variables that are exported from this module
|
||||
*/
|
||||
bool log_duration = false;
|
||||
bool log_parameters_on_error = false;
|
||||
bool Debug_print_plan = false;
|
||||
bool Debug_print_parse = false;
|
||||
bool Debug_print_rewritten = false;
|
||||
@@ -544,6 +543,8 @@ int log_min_messages = WARNING;
|
||||
int client_min_messages = NOTICE;
|
||||
int log_min_duration_sample = -1;
|
||||
int log_min_duration_statement = -1;
|
||||
int log_parameter_max_length = -1;
|
||||
int log_parameter_max_length_on_error = 0;
|
||||
int log_temp_files = -1;
|
||||
double log_statement_sample_rate = 1.0;
|
||||
double log_xact_sample_rate = 0;
|
||||
@@ -1381,15 +1382,6 @@ static struct config_bool ConfigureNamesBool[] =
|
||||
false,
|
||||
NULL, NULL, NULL
|
||||
},
|
||||
{
|
||||
{"log_parameters_on_error", PGC_SUSET, LOGGING_WHAT,
|
||||
gettext_noop("Logs bind parameters of the logged statements where possible."),
|
||||
NULL
|
||||
},
|
||||
&log_parameters_on_error,
|
||||
false,
|
||||
NULL, NULL, NULL
|
||||
},
|
||||
{
|
||||
{"debug_print_parse", PGC_USERSET, LOGGING_WHAT,
|
||||
gettext_noop("Logs each query's parse tree."),
|
||||
@@ -2855,6 +2847,28 @@ static struct config_int ConfigureNamesInt[] =
|
||||
NULL, NULL, NULL
|
||||
},
|
||||
|
||||
{
|
||||
{"log_parameter_max_length", PGC_SUSET, LOGGING_WHAT,
|
||||
gettext_noop("When logging statements, limit logged parameter values to first N bytes."),
|
||||
gettext_noop("-1 to print values in full."),
|
||||
GUC_UNIT_BYTE
|
||||
},
|
||||
&log_parameter_max_length,
|
||||
-1, -1, INT_MAX / 2,
|
||||
NULL, NULL, NULL
|
||||
},
|
||||
|
||||
{
|
||||
{"log_parameter_max_length_on_error", PGC_USERSET, LOGGING_WHAT,
|
||||
gettext_noop("When reporting an error, limit logged parameter values to first N bytes."),
|
||||
gettext_noop("-1 to print values in full."),
|
||||
GUC_UNIT_BYTE
|
||||
},
|
||||
&log_parameter_max_length_on_error,
|
||||
0, -1, INT_MAX / 2,
|
||||
NULL, NULL, NULL
|
||||
},
|
||||
|
||||
{
|
||||
{"bgwriter_delay", PGC_SIGHUP, RESOURCES_BGWRITER,
|
||||
gettext_noop("Background writer sleep time between rounds."),
|
||||
|
@@ -545,8 +545,13 @@
|
||||
# %% = '%'
|
||||
# e.g. '<%u%%%d> '
|
||||
#log_lock_waits = off # log lock waits >= deadlock_timeout
|
||||
#log_parameter_max_length = -1 # when logging statements, limit logged
|
||||
# bind-parameter values to N bytes;
|
||||
# -1 means print in full, 0 disables
|
||||
#log_parameter_max_length_on_error = 0 # when logging an error, limit logged
|
||||
# bind-parameter values to N bytes;
|
||||
# -1 means print in full, 0 disables
|
||||
#log_statement = 'none' # none, ddl, mod, all
|
||||
#log_parameters_on_error = off # on error log statements with bind parameters
|
||||
#log_replication_commands = off
|
||||
#log_temp_files = -1 # log temporary files equal or larger
|
||||
# than the specified size in kilobytes;
|
||||
|
Reference in New Issue
Block a user