Add notice_per_node_statement.
authorTatsuo Ishii <ishii@sraoss.co.jp>
Tue, 7 Feb 2023 08:25:17 +0000 (17:25 +0900)
committerTatsuo Ishii <ishii@sraoss.co.jp>
Tue, 7 Feb 2023 10:24:43 +0000 (19:24 +0900)
The new GUC variable allows to emit NOTICE message of queries per
backend basis.  It's similar to log_per_node_statement but as the log
level is NOTICE, the log is printed on client's terminal, thus users
can know where their queries go to without looking into pgpool log
files.

Also this is useful to create expected/results style test cases.

Discussion: https://www.pgpool.net/pipermail/pgpool-hackers/2023-February/004276.html

doc.ja/src/sgml/connection-pooling.sgml
doc/src/sgml/connection-pooling.sgml
src/config/pool_config_variables.c
src/context/pool_query_context.c
src/include/pool_config.h
src/include/protocol/pool_proto_modules.h
src/protocol/pool_proto_modules.c
src/sample/pgpool.conf.sample-stream

index 83872760a705a10aacc37be18c829f828d9fccbc..64e2fb98b9d14aa9198c8fd98d206ebbc73347e2 100644 (file)
@@ -1113,7 +1113,7 @@ local0.*    /var/log/pgpool.log
     <listitem>
      <para>
       <!--
-      Similar to <xref linkend="guc-log-statement">, except that it print the
+      Similar to <xref linkend="guc-log-statement">, except that it prints the
       logs for each DB node separately. It can be useful to make sure that
       replication or load-balancing is working.
       -->
@@ -1132,6 +1132,53 @@ local0.*    /var/log/pgpool.log
     </listitem>
    </varlistentry>
 
+   <varlistentry id="guc-notice-per-node-statement" xreflabel="notice_per_node_statement">
+    <term><varname>notice_per_node_statement</varname> (<type>boolean</type>)
+     <indexterm>
+      <!--
+      <primary><varname>notice_per_node_statement</varname> configuration parameter</primary>
+      -->
+      <primary><varname>notice_per_node_statement</varname> 設定パラメータ</primary>
+     </indexterm>
+    </term>
+    <listitem>
+     <para>
+      <!--
+      Similar to <xref linkend="guc-log-per-node-statement">, except
+      that it prints the statement logs for each DB node separately as
+      a NOTICE message. With the
+      default <xref linkend="client_min_messages"> setting (that is
+      NOTICE), the log message will be printed on client's terminal as
+      well. This is convenient for clients because it does not need to
+      access <productname>Pgpool-II</productname> log file.  Note that
+      unlike <xref linkend="guc-log-per-node-statement">, <xref linkend="guc-notice-per-node-statement">
+      does not print internal queries, (e.g., system catalog inquiry).
+      This is because this feature is designed to be used for testing
+      as well. As internal queries tend to be non-deterministic,
+      printing them in testing is not helpful. For the same reason,
+      backend process id is not printed.
+      -->
+      <xref linkend="guc-log-per-node-statement">と似ていますが、NOTICEメッセージとしてDBノード単位でログが出力されます。
+      <xref linkend="guc-client-min-messages">のデフォルト設定(すなわちNOTICE)では、このログメッセージはクライアントの端末にも出力されます。
+      クライアントにとっては、<productname>Pgpool-II</productname>のログファイルにアクセスする必要がないので便利です。
+      <xref linkend="guc-log-per-node-statement">と違って、<xref linkend="guc-notice-per-node-statement">は内部的に発行する問い合わせ(たとえば
+システムカタログへの問い合わせ)は出力しないことに注意してください。
+      これは、この機能がテストにも使えるように設計されているからです。
+      内部的な問い合わせは非決定論的に発行される傾向があるため、テストに使うには適していません。
+      同じ理由で、バックエンドのプロセスIDも出力されません。
+     </para>
+     <para>
+      <!--
+      This parameter can be changed by reloading the <productname>Pgpool-II</> configurations.
+      You can also use <xref linkend="SQL-PGPOOL-SET"> command to alter the value of
+      this parameter for a current session.
+      -->
+      このパラメータは<productname>Pgpool-II</>の設定を再読み込みすることで変更可能です。
+      現在のセッションでのパラメータ値は、<xref linkend="SQL-PGPOOL-SET">コマンドで変更することもできます。
+     </para>
+    </listitem>
+   </varlistentry>
+
    <varlistentry id="guc-log-client-messages" xreflabel="log_client_messages">
     <term><varname>log_client_messages</varname> (<type>boolean</type>)
      <indexterm>
index fbd59289d6d4987047416f937bae4ad627f4b832..9b376329e722f456ff7e9d06b9f25f97a1e4e9ac 100644 (file)
     </listitem>
    </varlistentry>
 
+   <varlistentry id="guc-notice-per-node-statement" xreflabel="notice_per_node_statement">
+    <term><varname>notice_per_node_statement</varname> (<type>boolean</type>)
+     <indexterm>
+      <primary><varname>notice_per_node_statement</varname> configuration parameter</primary>
+     </indexterm>
+    </term>
+    <listitem>
+     <para>
+      Similar to <xref linkend="guc-log-per-node-statement">, except
+      that it prints the statement logs for each DB node separately as
+      a NOTICE message. With the
+      default <xref linkend="guc-client-min-messages"> setting (that
+      is NOTICE), the log message will be printed on client's terminal
+      as well. This is convenient for clients because it does not need
+      to access <productname>Pgpool-II</productname> log file.  Note
+      that
+      unlike <xref linkend="guc-log-per-node-statement">, <xref linkend="guc-notice-per-node-statement">
+      does not print internal queries, (e.g., system catalog inquiry).
+      This is because this feature is designed to be used for testing
+      as well. As internal queries tend to be non-deterministic,
+      printing them in testing is not helpful. For the same reason,
+      backend process id is not printed.
+     </para>
+     <para>
+      This parameter can be changed by reloading the <productname>Pgpool-II</> configurations.
+      You can also use <xref linkend="SQL-PGPOOL-SET"> command to alter the value of
+      this parameter for a current session.
+     </para>
+    </listitem>
+   </varlistentry>
+
    <varlistentry id="guc-log-client-messages" xreflabel="log_client_messages">
     <term><varname>log_client_messages</varname> (<type>boolean</type>)
      <indexterm>
index 39935f72c9e2a9d2de5952004d06a33b01ba5dc7..38de1d05a515647cef2d15fc14e5317b77e2999c 100644 (file)
@@ -633,6 +633,16 @@ static struct config_bool ConfigureNamesBool[] =
                NULL, NULL, NULL
        },
 
+       {
+               {"notice_per_node_statement", CFGCXT_SESSION, LOGGING_CONFIG,
+                       "Logs notice message for per node detailed SQL statements.",
+                       CONFIG_VAR_TYPE_ENUM, false, 0
+               },
+               &g_pool_config.notice_per_node_statement,
+               false,
+               NULL, NULL, NULL
+       },
+
        {
                {"log_client_messages", CFGCXT_SESSION, LOGGING_CONFIG,
                        "Logs any client messages in the pgpool logs.",
index 5ba6ce2da00a22097feff4cf89fb0e439bf2bf48..0277f9a846fabae8d270f47041e3e767ece12d33 100644 (file)
@@ -870,6 +870,7 @@ pool_send_and_wait(POOL_QUERY_CONTEXT * query_context,
                }
 
                per_node_statement_log(backend, i, string);
+               per_node_statement_notice(backend, i, string);
                stat_count_up(i, query_context->parse_tree);
                send_simplequery_message(CONNECTION(backend, i), len, string, MAJOR(backend));
        }
@@ -1047,6 +1048,7 @@ pool_extended_send_and_wait(POOL_QUERY_CONTEXT * query_context,
                        }
 
                        per_node_statement_log(backend, i, msgbuf);
+                       per_node_statement_notice(backend, i, msgbuf);
                }
 
                /* if Execute message, count up stats count */
index 3bf1663ec62ff9b07dd9a62b5ebc281ec6148fda..4a9b2133ddba3838c10fd61586aedf486f6bb687 100644 (file)
@@ -6,7 +6,7 @@
  * pgpool: a language independent connection pool server for PostgreSQL
  * written by Tatsuo Ishii
  *
- * Copyright (c) 2003-2022     PgPool Global Development Group
+ * Copyright (c) 2003-2023     PgPool Global Development Group
  *
  * Permission to use, copy, modify, and distribute this software and
  * its documentation for any purpose and without fee is hereby
@@ -398,6 +398,8 @@ typedef struct
        bool            log_statement;  /* logs all SQL statements */
        bool            log_per_node_statement; /* logs per node detailed SQL
                                                                                 * statements */
+       bool            notice_per_node_statement; /* logs notice message for per node detailed SQL
+                                                                                * statements */
        bool            log_client_messages;    /* If true, logs any client messages */
        char       *lobj_lock_table;    /* table name to lock for rewriting
                                                                         * lo_creat */
index 57280a3e315062845feada9bfbcd49126321cc38..4ad7eade61ba45a533fbc4152eea76ad51676cf9 100644 (file)
@@ -6,7 +6,7 @@
  * pgpool: a language independent connection pool server for PostgreSQL
  * written by Tatsuo Ishii
  *
- * Copyright (c) 2003-2022     PgPool Global Development Group
+ * Copyright (c) 2003-2023     PgPool Global Development Group
  *
  * Permission to use, copy, modify, and distribute this software and
  * its documentation for any purpose and without fee is hereby
@@ -117,6 +117,8 @@ extern void handle_query_context(POOL_CONNECTION_POOL * backend);;
 
 extern void pool_emit_log_for_message_length_diff(int *length_array, char *name);
 
+extern void per_node_statement_notice(POOL_CONNECTION_POOL * backend, int node_id, char *query);
+
 /*
  * modules defined in pool_proto2.c
  */
index dbcd7039f3d32119e537a0df6e326ac455ecbdcc..94aed730abe511948f6aecd08dfe47ec27002fc5 100644 (file)
@@ -3,7 +3,7 @@
  * pgpool: a language independent connection pool server for PostgreSQL
  * written by Tatsuo Ishii
  *
- * Copyright (c) 2003-2022     PgPool Global Development Group
+ * Copyright (c) 2003-2023     PgPool Global Development Group
  *
  * Permission to use, copy, modify, and distribute this software and
  * its documentation for any purpose and without fee is hereby
@@ -3568,6 +3568,17 @@ per_node_statement_log(POOL_CONNECTION_POOL * backend, int node_id, char *query)
                                (errmsg("DB node id: %d backend pid: %d statement: %s", node_id, ntohl(slot->pid), query)));
 }
 
+/*
+ * Make per DB node statement notice message
+ */
+void
+per_node_statement_notice(POOL_CONNECTION_POOL * backend, int node_id, char *query)
+{
+       if (pool_config->notice_per_node_statement)
+               ereport(NOTICE,
+                               (errmsg("DB node id: %d statement: %s", node_id, query)));
+}
+
 /*
  * Check kind and produce error message
  * All data read in this function is returned to stream.
index 3305d54121cc08a190146737fb9fafcae3dd1ec6..666c16e6fcffbbdf087bd313f91bbf5061bebd5a 100644 (file)
@@ -256,6 +256,8 @@ backend_clustering_mode = 'streaming_replication'
 #log_per_node_statement = off
                                    # Log all statements
                                    # with node and backend informations
+#notice_per_node_statement = off
+                                   # logs notice message for per node detailed SQL statements
 #log_client_messages = off
                                    # Log any client messages
 #log_standby_delay = 'if_over_threshold'