pgpool2.git / summary / log / commit / refs
commit c20858797eafe377b30166b467d2a36de89768e1
Author: Tatsuo Ishii <ishii at sraoss.co.jp>
Date: Tue Feb 22 04:14:04 2011 +0000
Adapt application_name introduced in PostgreSQL 9.0.
When reusing connection, send application_name in the startup packet
to backend and send parameter status to frontend.
child.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++----
pool.h | 3 ++-
2 files changed, 52 insertions(+), 5 deletions(-)
diff --git a/child.c b/child.c
index a6c8264b4..9bbb04cad 100644
--- a/child.c
+++ b/child.c
@@ -762,7 +762,9 @@ static POOL_CONNECTION *do_accept(int unix_fd, int inet_fd, struct timeval *time
}
/*
-* read startup packet
+* Read startup packet
+*
+* Read the startup packet and parse the contents.
*/
static StartupPacket *read_startup_packet(POOL_CONNECTION *cp)
{
@@ -889,6 +891,24 @@ static StartupPacket *read_startup_packet(POOL_CONNECTION *cp)
return NULL;
}
}
+
+ /*
+ * From 9.0, the start up packet may include
+ * application name. After receiving such that packet,
+ * backend sends parameter status of application_name.
+ * Upon reusing connection to backend, we need to
+ * emulate this behavior of backend. So we remember
+ * this and send parameter status packet to frontend
+ * instead of backend in
+ * connect_using_existing_connection().
+ */
+ else if (!strcmp("application_name", p))
+ {
+ p += (strlen(p) + 1);
+ sp->application_name = p;
+ pool_debug("read_startup_packet: application_name: %s", p);
+ }
+
p += (strlen(p) + 1);
}
break;
@@ -951,7 +971,7 @@ static bool connect_using_existing_connection(POOL_CONNECTION *frontend,
{
int i, freed = 0;
/*
- * save startup packet info
+ * Save startup packet info
*/
for (i = 0; i < NUM_BACKENDS; i++)
{
@@ -966,7 +986,7 @@ static bool connect_using_existing_connection(POOL_CONNECTION *frontend,
}
}
- /* reuse existing connection to backend */
+ /* Reuse existing connection to backend */
if (pool_do_reauth(frontend, backend))
{
@@ -977,6 +997,32 @@ static bool 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),
+ MASTER_CONNECTION(backend)->pid,
+ MASTER_CONNECTION(backend)->key, 0) != POOL_CONTINUE)
+ {
+ pool_error("connect_using_existing_connection: do_command failed. command: %s", command_buf);
+ return false;
+ }
+ }
+
+ pool_add_param(&MASTER(backend)->params, "application_name", sp->application_name);
+ }
+
if (send_params(frontend, backend))
{
pool_close(frontend);
@@ -985,7 +1031,7 @@ static bool connect_using_existing_connection(POOL_CONNECTION *frontend,
}
}
- /* send ReadyForQuery to frontend */
+ /* Send ReadyForQuery to frontend */
pool_write(frontend, "Z", 1);
if (MAJOR(backend) == 3)
diff --git a/pool.h b/pool.h
index ad55ecb88..01f7982a3 100644
--- a/pool.h
+++ b/pool.h
@@ -6,7 +6,7 @@
* pgpool: a language independent connection pool server for PostgreSQL
* written by Tatsuo Ishii
*
- * Copyright (c) 2003-2010 PgPool Global Development Group
+ * Copyright (c) 2003-2011 PgPool Global Development Group
*
* Permission to use, copy, modify, and distribute this software and
* its documentation for any purpose and without fee is hereby
@@ -118,6 +118,7 @@ typedef struct
int minor; /* protocol minor version */
char *database; /* database name in startup_packet (malloced area) */
char *user; /* user name in startup_packet (malloced area) */
+ char *application_name; /* not malloced are. pointing to in startup_packet */
} StartupPacket;
typedef struct CancelPacket
[parent: 4f7efbcd4b19]