From 3f3c165698d8ded0a96d24ee93b32bc6973dab6d Mon Sep 17 00:00:00 2001 From: Tatsuo Ishii Date: Sat, 10 Feb 2024 11:50:28 +0900 Subject: [PATCH] Fix statement_level_load_balance with BEGIN etc. When statement_level_load_balance is enabled, BEGIN/END/COMMIT/ABORT/SET/SAVEPOINT/RELEASE SAVEPOINT/DEALLOCATE ALL/DISCARD were sent to primary node and all standby nodes even if load_balance_mode is off. This is not only plain wrong but caused slow down if one of the standby nodes are in remote network. Fix this in that pgpool sends such queries to primary node only when load_balance_mode is off. Note that if load_balance_mode is on and statement_level_load_balance is on, such queries are sent to all nodes as before. This is necessary. For example, suppose there are 2 PostgreSQL nodes 0 and 1. An explicit transaction starts followed by two read only SELECTs. The first SELECT is sent to node 0 because the node 0 is chosen as the load balance node. The second SELECT is sent to node 1 because the node 1 is chosen as the load balance node. If pgpool has not sent BEGIN to both node 0 and 1 when the transaction started, the first or the second SELECT will be executed outside the transaction, which is not an expected behavior. However this may bring slow down mentioned above. I guess this has been less known to users and I decided to add some notes to the statement_level_load_balance doc. Reported: [pgpool-general: 8998] https://www.pgpool.net/pipermail/pgpool-general/2024-January/009059.html Discussion: [pgpool-hackers: 4422] https://www.pgpool.net/pipermail/pgpool-hackers/2024-February/004423.html Backpatch-through: v4.1 --- doc.ja/src/sgml/loadbalance.sgml | 28 ++++++++++++++++++++++++++-- doc/src/sgml/loadbalance.sgml | 22 ++++++++++++++++++++-- src/context/pool_query_context.c | 30 ++++++++++++++++++++++-------- 3 files changed, 68 insertions(+), 12 deletions(-) diff --git a/doc.ja/src/sgml/loadbalance.sgml b/doc.ja/src/sgml/loadbalance.sgml index 7d932965f..329f82c13 100644 --- a/doc.ja/src/sgml/loadbalance.sgml +++ b/doc.ja/src/sgml/loadbalance.sgml @@ -479,6 +479,11 @@ DEALLOCATE ALL + + + SAVEPOINT (そしてRELEASE SAVEPOINTのような関連コマンド) + + @@ -1603,7 +1608,7 @@ dml_adaptive_object_relationship_list = 'table_1:table_2' - onに設定すると、参照クエリごとに負荷分散先を決めます。 + onに設定し、がonに設定されていると、参照クエリごとに負荷分散先を決めます。 offに設定すると、セッションが始まるときに決められた負荷分散先がセッションが終了するまで変更されません。 例えば、コネクションプールを利用し、バックエンドサーバに接続したままのようなアプリケーションの場合、 セッションが長い間保持される可能性があるので、セッションが終了するまで負荷分散先のノードが変わりません。 このようなアプリケーションでは、statement_level_load_balanceを有効にすると、 セッションごとではなく、クエリごとに負荷分散先を決めることが可能です。デフォルトはoffです。 + + + + streaming replication modeでは、BEGIN/END/COMMIT/ABORT/SET/SAVEPOINT/RELEASE SAVEPOINT/DEALLOCATE ALL/DISCARDのようなクエリはプライマリノードとロードバランスノードに送られます。 + がonなら、そうしたクエリはすべてのスタンバイノードにも送られます + これは通常問題になりません。 + しかしスタンバイノードの一つが遠隔ネットワークにあると、ネットワーク遅延のためにこうしたクエリで大きな速度低下を起こすことがあります。 + +