From 7f2e956520ada05b30d9332628bc26a4dacc8913 Mon Sep 17 00:00:00 2001 From: Fantix King Date: Sat, 16 Nov 2024 04:23:54 +0800 Subject: [PATCH] Truncate all STATEMENT/QUERY log lines (#123) --- ...gresql-edgedb__gate_statement_log-14.patch | 28 ------- ...gresql-edgedb__gate_statement_log-15.patch | 28 ------- ...gresql-edgedb__gate_statement_log-16.patch | 28 ------- .../postgresql-edgedb__truncate_log-14.patch | 75 +++++++++++++++++++ .../postgresql-edgedb__truncate_log-15.patch | 75 +++++++++++++++++++ .../postgresql-edgedb__truncate_log-16.patch | 75 +++++++++++++++++++ .../postgresql-edgedb__truncate_log-17.patch | 75 +++++++++++++++++++ 7 files changed, 300 insertions(+), 84 deletions(-) delete mode 100644 edgedbpkg/postgresql/patches/postgresql-edgedb__gate_statement_log-14.patch delete mode 100644 edgedbpkg/postgresql/patches/postgresql-edgedb__gate_statement_log-15.patch delete mode 100644 edgedbpkg/postgresql/patches/postgresql-edgedb__gate_statement_log-16.patch create mode 100644 edgedbpkg/postgresql/patches/postgresql-edgedb__truncate_log-14.patch create mode 100644 edgedbpkg/postgresql/patches/postgresql-edgedb__truncate_log-15.patch create mode 100644 edgedbpkg/postgresql/patches/postgresql-edgedb__truncate_log-16.patch create mode 100644 edgedbpkg/postgresql/patches/postgresql-edgedb__truncate_log-17.patch diff --git a/edgedbpkg/postgresql/patches/postgresql-edgedb__gate_statement_log-14.patch b/edgedbpkg/postgresql/patches/postgresql-edgedb__gate_statement_log-14.patch deleted file mode 100644 index b599d7c..0000000 --- a/edgedbpkg/postgresql/patches/postgresql-edgedb__gate_statement_log-14.patch +++ /dev/null @@ -1,28 +0,0 @@ -From 33b7d8a7aa52caa5425df91156ee2d64523f5062 Mon Sep 17 00:00:00 2001 -From: Fantix King -Date: Fri, 30 Aug 2024 13:34:32 -0400 -Subject: [PATCH 6/6] Gate long STATEMENT log in SERIALIZATION error - ---- - src/backend/utils/error/elog.c | 5 ++++- - 1 file changed, 4 insertions(+), 1 deletion(-) - -diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c -index 8d33686510a..bd3197606d0 100644 ---- a/src/backend/utils/error/elog.c -+++ b/src/backend/utils/error/elog.c -@@ -3106,7 +3106,10 @@ send_message_to_server_log(ErrorData *edata) - */ - if (is_log_level_output(edata->elevel, log_min_error_statement) && - debug_query_string != NULL && -- !edata->hide_stmt) -+ !edata->hide_stmt && -+ // Hide STATEMENT in serialization error if longer than 128 bytes -+ (edata->sqlerrcode != ERRCODE_T_R_SERIALIZATION_FAILURE || -+ strnlen(debug_query_string, 128) < 128)) - { - log_line_prefix(&buf, edata); - appendStringInfoString(&buf, _("STATEMENT: ")); --- -2.46.0 - diff --git a/edgedbpkg/postgresql/patches/postgresql-edgedb__gate_statement_log-15.patch b/edgedbpkg/postgresql/patches/postgresql-edgedb__gate_statement_log-15.patch deleted file mode 100644 index 34bd192..0000000 --- a/edgedbpkg/postgresql/patches/postgresql-edgedb__gate_statement_log-15.patch +++ /dev/null @@ -1,28 +0,0 @@ -From 743774f3da65c2d3035f32781c2bbb04f1918e79 Mon Sep 17 00:00:00 2001 -From: Fantix King -Date: Fri, 30 Aug 2024 13:34:32 -0400 -Subject: [PATCH 6/6] Gate long STATEMENT log in SERIALIZATION error - ---- - src/backend/utils/error/elog.c | 5 +++++ - 1 file changed, 5 insertions(+) - -diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c -index 01066832e18..24bd20ce382 100644 ---- a/src/backend/utils/error/elog.c -+++ b/src/backend/utils/error/elog.c -@@ -2384,6 +2384,11 @@ check_log_of_query(ErrorData *edata) - if (debug_query_string == NULL) - return false; - -+ // Hide STATEMENT in serialization error if longer than 128 bytes -+ if (edata->sqlerrcode == ERRCODE_T_R_SERIALIZATION_FAILURE -+ && strnlen(debug_query_string, 128) >= 128) -+ return false; -+ - return true; - } - --- -2.46.0 - diff --git a/edgedbpkg/postgresql/patches/postgresql-edgedb__gate_statement_log-16.patch b/edgedbpkg/postgresql/patches/postgresql-edgedb__gate_statement_log-16.patch deleted file mode 100644 index c06ceb7..0000000 --- a/edgedbpkg/postgresql/patches/postgresql-edgedb__gate_statement_log-16.patch +++ /dev/null @@ -1,28 +0,0 @@ -From a1f48b8e5f6595488c88f49e2b06d6ebe66ff90f Mon Sep 17 00:00:00 2001 -From: Fantix King -Date: Fri, 30 Aug 2024 13:34:32 -0400 -Subject: [PATCH 6/6] Gate long STATEMENT log in SERIALIZATION error - ---- - src/backend/utils/error/elog.c | 5 +++++ - 1 file changed, 5 insertions(+) - -diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c -index 893f8a5b563..8bd84808a7d 100644 ---- a/src/backend/utils/error/elog.c -+++ b/src/backend/utils/error/elog.c -@@ -2701,6 +2701,11 @@ check_log_of_query(ErrorData *edata) - if (debug_query_string == NULL) - return false; - -+ // Hide STATEMENT in serialization error if longer than 128 bytes -+ if (edata->sqlerrcode == ERRCODE_T_R_SERIALIZATION_FAILURE -+ && strnlen(debug_query_string, 128) >= 128) -+ return false; -+ - return true; - } - --- -2.46.0 - diff --git a/edgedbpkg/postgresql/patches/postgresql-edgedb__truncate_log-14.patch b/edgedbpkg/postgresql/patches/postgresql-edgedb__truncate_log-14.patch new file mode 100644 index 0000000..d300702 --- /dev/null +++ b/edgedbpkg/postgresql/patches/postgresql-edgedb__truncate_log-14.patch @@ -0,0 +1,75 @@ +From 2c80b43e91b812fd7083801eca5b0b8f41d0c178 Mon Sep 17 00:00:00 2001 +From: Fantix King +Date: Thu, 14 Nov 2024 19:44:01 -0500 +Subject: [PATCH 6/6] Truncate long STATEMENT/QUERY log + +--- + src/backend/utils/error/elog.c | 31 +++++++++++++++++++++++++++++-- + 1 file changed, 29 insertions(+), 2 deletions(-) + +diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c +index 8d33686510a..ae186e79a29 100644 +--- a/src/backend/utils/error/elog.c ++++ b/src/backend/utils/error/elog.c +@@ -185,6 +185,7 @@ static void write_pipe_chunks(char *data, int len, int dest); + static void send_message_to_frontend(ErrorData *edata); + static const char *error_severity(int elevel); + static void append_with_tabs(StringInfo buf, const char *str); ++static void append_n_with_tabs(StringInfo buf, const char *str, int n); + + + /* +@@ -3065,7 +3066,7 @@ send_message_to_server_log(ErrorData *edata) + { + log_line_prefix(&buf, edata); + appendStringInfoString(&buf, _("QUERY: ")); +- append_with_tabs(&buf, edata->internalquery); ++ append_n_with_tabs(&buf, edata->internalquery, 1024); + appendStringInfoChar(&buf, '\n'); + } + if (edata->context && !edata->hide_ctx) +@@ -3110,7 +3111,7 @@ send_message_to_server_log(ErrorData *edata) + { + log_line_prefix(&buf, edata); + appendStringInfoString(&buf, _("STATEMENT: ")); +- append_with_tabs(&buf, debug_query_string); ++ append_n_with_tabs(&buf, debug_query_string, 1024); + appendStringInfoChar(&buf, '\n'); + } + +@@ -3551,6 +3552,32 @@ append_with_tabs(StringInfo buf, const char *str) + } + + ++/* ++ * append_n_with_tabs ++ * ++ * Append the string to the StringInfo buffer truncating at n characters, ++ * inserting a tab after any newline, and `...` at the end if truncated. ++ */ ++static void ++append_n_with_tabs(StringInfo buf, const char *str, int n) ++{ ++ char ch; ++ ++ while ((ch = *str++) != '\0' && n > 0) ++ { ++ appendStringInfoCharMacro(buf, ch); ++ if (ch == '\n') ++ appendStringInfoCharMacro(buf, '\t'); ++ n--; ++ } ++ if (ch != '\0') { ++ appendStringInfoCharMacro(buf, '.'); ++ appendStringInfoCharMacro(buf, '.'); ++ appendStringInfoCharMacro(buf, '.'); ++ } ++} ++ ++ + /* + * Write errors to stderr (or by equal means when stderr is + * not available). Used before ereport/elog can be used +-- +2.47.0 + diff --git a/edgedbpkg/postgresql/patches/postgresql-edgedb__truncate_log-15.patch b/edgedbpkg/postgresql/patches/postgresql-edgedb__truncate_log-15.patch new file mode 100644 index 0000000..394dfd7 --- /dev/null +++ b/edgedbpkg/postgresql/patches/postgresql-edgedb__truncate_log-15.patch @@ -0,0 +1,75 @@ +From 38b74895b1dbbad3c6fa935cbb3f77f449b8d5ea Mon Sep 17 00:00:00 2001 +From: Fantix King +Date: Thu, 14 Nov 2024 19:44:01 -0500 +Subject: [PATCH 6/6] Truncate long STATEMENT/QUERY log + +--- + src/backend/utils/error/elog.c | 31 +++++++++++++++++++++++++++++-- + 1 file changed, 29 insertions(+), 2 deletions(-) + +diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c +index 01066832e18..4bad03460e4 100644 +--- a/src/backend/utils/error/elog.c ++++ b/src/backend/utils/error/elog.c +@@ -180,6 +180,7 @@ static void log_line_prefix(StringInfo buf, ErrorData *edata); + static void send_message_to_server_log(ErrorData *edata); + static void send_message_to_frontend(ErrorData *edata); + static void append_with_tabs(StringInfo buf, const char *str); ++static void append_n_with_tabs(StringInfo buf, const char *str, int n); + + + /* +@@ -2876,7 +2877,7 @@ send_message_to_server_log(ErrorData *edata) + { + log_line_prefix(&buf, edata); + appendStringInfoString(&buf, _("QUERY: ")); +- append_with_tabs(&buf, edata->internalquery); ++ append_n_with_tabs(&buf, edata->internalquery, 1024); + appendStringInfoChar(&buf, '\n'); + } + if (edata->context && !edata->hide_ctx) +@@ -2919,7 +2920,7 @@ send_message_to_server_log(ErrorData *edata) + { + log_line_prefix(&buf, edata); + appendStringInfoString(&buf, _("STATEMENT: ")); +- append_with_tabs(&buf, debug_query_string); ++ append_n_with_tabs(&buf, debug_query_string, 1024); + appendStringInfoChar(&buf, '\n'); + } + +@@ -3365,6 +3366,32 @@ append_with_tabs(StringInfo buf, const char *str) + } + + ++/* ++ * append_n_with_tabs ++ * ++ * Append the string to the StringInfo buffer truncating at n characters, ++ * inserting a tab after any newline, and `...` at the end if truncated. ++ */ ++static void ++append_n_with_tabs(StringInfo buf, const char *str, int n) ++{ ++ char ch; ++ ++ while ((ch = *str++) != '\0' && n > 0) ++ { ++ appendStringInfoCharMacro(buf, ch); ++ if (ch == '\n') ++ appendStringInfoCharMacro(buf, '\t'); ++ n--; ++ } ++ if (ch != '\0') { ++ appendStringInfoCharMacro(buf, '.'); ++ appendStringInfoCharMacro(buf, '.'); ++ appendStringInfoCharMacro(buf, '.'); ++ } ++} ++ ++ + /* + * Write errors to stderr (or by equal means when stderr is + * not available). Used before ereport/elog can be used +-- +2.47.0 + diff --git a/edgedbpkg/postgresql/patches/postgresql-edgedb__truncate_log-16.patch b/edgedbpkg/postgresql/patches/postgresql-edgedb__truncate_log-16.patch new file mode 100644 index 0000000..96729f2 --- /dev/null +++ b/edgedbpkg/postgresql/patches/postgresql-edgedb__truncate_log-16.patch @@ -0,0 +1,75 @@ +From 19e6ae523ab82adf8f256ed2dd892183c2d20593 Mon Sep 17 00:00:00 2001 +From: Fantix King +Date: Thu, 14 Nov 2024 19:44:01 -0500 +Subject: [PATCH 6/6] Truncate long STATEMENT/QUERY log + +--- + src/backend/utils/error/elog.c | 31 +++++++++++++++++++++++++++++-- + 1 file changed, 29 insertions(+), 2 deletions(-) + +diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c +index 7112fb00069..b0326ba3649 100644 +--- a/src/backend/utils/error/elog.c ++++ b/src/backend/utils/error/elog.c +@@ -192,6 +192,7 @@ static void log_line_prefix(StringInfo buf, ErrorData *edata); + static void send_message_to_server_log(ErrorData *edata); + static void send_message_to_frontend(ErrorData *edata); + static void append_with_tabs(StringInfo buf, const char *str); ++static void append_n_with_tabs(StringInfo buf, const char *str, int n); + + + /* +@@ -3218,7 +3219,7 @@ send_message_to_server_log(ErrorData *edata) + { + log_line_prefix(&buf, edata); + appendStringInfoString(&buf, _("QUERY: ")); +- append_with_tabs(&buf, edata->internalquery); ++ append_n_with_tabs(&buf, edata->internalquery, 1024); + appendStringInfoChar(&buf, '\n'); + } + if (edata->context && !edata->hide_ctx) +@@ -3261,7 +3262,7 @@ send_message_to_server_log(ErrorData *edata) + { + log_line_prefix(&buf, edata); + appendStringInfoString(&buf, _("STATEMENT: ")); +- append_with_tabs(&buf, debug_query_string); ++ append_n_with_tabs(&buf, debug_query_string, 1024); + appendStringInfoChar(&buf, '\n'); + } + +@@ -3707,6 +3708,32 @@ append_with_tabs(StringInfo buf, const char *str) + } + + ++/* ++ * append_n_with_tabs ++ * ++ * Append the string to the StringInfo buffer truncating at n characters, ++ * inserting a tab after any newline, and `...` at the end if truncated. ++ */ ++static void ++append_n_with_tabs(StringInfo buf, const char *str, int n) ++{ ++ char ch; ++ ++ while ((ch = *str++) != '\0' && n > 0) ++ { ++ appendStringInfoCharMacro(buf, ch); ++ if (ch == '\n') ++ appendStringInfoCharMacro(buf, '\t'); ++ n--; ++ } ++ if (ch != '\0') { ++ appendStringInfoCharMacro(buf, '.'); ++ appendStringInfoCharMacro(buf, '.'); ++ appendStringInfoCharMacro(buf, '.'); ++ } ++} ++ ++ + /* + * Write errors to stderr (or by equal means when stderr is + * not available). Used before ereport/elog can be used +-- +2.47.0 + diff --git a/edgedbpkg/postgresql/patches/postgresql-edgedb__truncate_log-17.patch b/edgedbpkg/postgresql/patches/postgresql-edgedb__truncate_log-17.patch new file mode 100644 index 0000000..1195409 --- /dev/null +++ b/edgedbpkg/postgresql/patches/postgresql-edgedb__truncate_log-17.patch @@ -0,0 +1,75 @@ +From a5969a9f10e83a28154d1d8297babd2b31170dc0 Mon Sep 17 00:00:00 2001 +From: Fantix King +Date: Thu, 14 Nov 2024 19:44:01 -0500 +Subject: [PATCH 6/6] Truncate long STATEMENT/QUERY log + +--- + src/backend/utils/error/elog.c | 31 +++++++++++++++++++++++++++++-- + 1 file changed, 29 insertions(+), 2 deletions(-) + +diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c +index b924b524d0b..2246e8f6047 100644 +--- a/src/backend/utils/error/elog.c ++++ b/src/backend/utils/error/elog.c +@@ -191,6 +191,7 @@ static void log_line_prefix(StringInfo buf, ErrorData *edata); + static void send_message_to_server_log(ErrorData *edata); + static void send_message_to_frontend(ErrorData *edata); + static void append_with_tabs(StringInfo buf, const char *str); ++static void append_n_with_tabs(StringInfo buf, const char *str, int n); + + + /* +@@ -3237,7 +3238,7 @@ send_message_to_server_log(ErrorData *edata) + { + log_line_prefix(&buf, edata); + appendStringInfoString(&buf, _("QUERY: ")); +- append_with_tabs(&buf, edata->internalquery); ++ append_n_with_tabs(&buf, edata->internalquery, 1024); + appendStringInfoChar(&buf, '\n'); + } + if (edata->context && !edata->hide_ctx) +@@ -3280,7 +3281,7 @@ send_message_to_server_log(ErrorData *edata) + { + log_line_prefix(&buf, edata); + appendStringInfoString(&buf, _("STATEMENT: ")); +- append_with_tabs(&buf, debug_query_string); ++ append_n_with_tabs(&buf, debug_query_string, 1024); + appendStringInfoChar(&buf, '\n'); + } + +@@ -3729,6 +3730,32 @@ append_with_tabs(StringInfo buf, const char *str) + } + + ++/* ++ * append_n_with_tabs ++ * ++ * Append the string to the StringInfo buffer truncating at n characters, ++ * inserting a tab after any newline, and `...` at the end if truncated. ++ */ ++static void ++append_n_with_tabs(StringInfo buf, const char *str, int n) ++{ ++ char ch; ++ ++ while ((ch = *str++) != '\0' && n > 0) ++ { ++ appendStringInfoCharMacro(buf, ch); ++ if (ch == '\n') ++ appendStringInfoCharMacro(buf, '\t'); ++ n--; ++ } ++ if (ch != '\0') { ++ appendStringInfoCharMacro(buf, '.'); ++ appendStringInfoCharMacro(buf, '.'); ++ appendStringInfoCharMacro(buf, '.'); ++ } ++} ++ ++ + /* + * Write errors to stderr (or by equal means when stderr is + * not available). Used before ereport/elog can be used +-- +2.47.0 +