Remove unnecessary application_name treatment.
authorTatsuo Ishii <ishii@postgresql.org>
Fri, 7 Nov 2025 09:17:54 +0000 (18:17 +0900)
committerTatsuo Ishii <ishii@postgresql.org>
Fri, 7 Nov 2025 09:29:53 +0000 (18:29 +0900)
Commit c20858797eafe377b30166b467d2a36de89768e1 added an treatment to
send "set application_name" command to backend when reusing existing
connection. The reason were:

(1) to set application_name parameter to proper value, which is the
value specified in the startup packet when the connection was created.

(2) to return application_name parameter status message to frontend.

However, (1) is not necessary, because when the previous connection is
closed, queries in reset_query_list are executed and the list usually
includes "DISCARD ALL", which reset the application_name value to the
previous one which was set when the connection was established.  Also
(2) is not necessary either, because send_params() sends all necessary
parameter status messages to frontend including application_name.

For these reasons, I think the treatment added in
c20858797eafe377b30166b467d2a36de89768e1 is not necessary. This commit
just removes the treatment. Also this will enhance the performance
when some of backend nodes are in geographically distant location, by
eliminating the time to send application_name to such a node and wait
for the response.

Author: Tatsuo Ishii <ishii@postgresql.org>
Discussion: https://github.com/pgpool/pgpool2/issues/130
Backpatch-through: v4.2.

src/protocol/child.c

index c83d537d16cdcd641398cc63bb575f0996ca935d..352edb41109c41b7e0e7e72ea601dfe670591cc3 100644 (file)
@@ -823,35 +823,7 @@ connect_using_existing_connection(POOL_CONNECTION * frontend,
 
        if (MAJOR(backend) == 3)
        {
-               char            command_buf[1024];
-
-               /*
-                * If we have received application_name in the start up packet, we
-                * send SET command to backend. Also we add or replace existing
-                * application_name data.
-                */
-               if (sp->application_name)
-               {
-                       snprintf(command_buf, sizeof(command_buf), "SET application_name TO '%s'", sp->application_name);
-
-                       for (i = 0; i < NUM_BACKENDS; i++)
-                       {
-                               if (VALID_BACKEND(i))
-                                       if (do_command(frontend, CONNECTION(backend, i),
-                                                                  command_buf, MAJOR(backend),
-                                                                  MAIN_CONNECTION(backend)->pid,
-                                                                  MAIN_CONNECTION(backend)->key, 0) != POOL_CONTINUE)
-                                       {
-                                               ereport(ERROR,
-                                                               (errmsg("unable to process command for backend connection"),
-                                                                errdetail("do_command returned DEADLOCK status")));
-                                       }
-                       }
-
-                       pool_add_param(&MAIN(backend)->params, "application_name", sp->application_name);
-                       set_application_name_with_string(sp->application_name);
-               }
-
+               /* Send parameter status message to frontend. */
                send_params(frontend, backend);
        }