Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add new directive log_per_node_statement.

If true, print all statements to the log. Similar to log_statement except
that prints DB node id and backend process id info.
  • Loading branch information...
commit 1df596da2d3680b84fd8ee139022c73317e1e136 1 parent b488dee
t-ishii authored
View
6 pgpool.conf.sample
@@ -1,6 +1,6 @@
#
# pgpool-II configuration file sample
-# $Header: /cvsroot/pgpool/pgpool-II/pgpool.conf.sample,v 1.27 2009/11/12 07:37:27 t-ishii Exp $
+# $Header: /cvsroot/pgpool/pgpool-II/pgpool.conf.sample,v 1.28 2009/11/15 08:27:35 t-ishii Exp $
# Host name or IP address to listen on: '*' for all, '' for no TCP/IP
# connections
@@ -137,6 +137,10 @@ ignore_leading_white_space = true
# debugging.
log_statement = false
+# If true, print all statements to the log. Similar to log_statement except
+# that prints DB node id and backend process id info.
+log_per_node_statement = false
+
# If true, incoming connections will be printed to the log.
log_connections = false
View
4 pool.h
@@ -1,7 +1,7 @@
/* -*-pgsql-c-*- */
/*
*
- * $Header: /cvsroot/pgpool/pgpool-II/pool.h,v 1.44 2009/11/14 13:22:32 t-ishii Exp $
+ * $Header: /cvsroot/pgpool/pgpool-II/pool.h,v 1.45 2009/11/15 08:27:35 t-ishii Exp $
*
* pgpool: a language independent connection pool server for PostgreSQL
* written by Tatsuo Ishii
@@ -173,6 +173,7 @@ typedef struct {
data consistency */
int ignore_leading_white_space; /* ignore leading white spaces of each query */
int log_statement; /* 0:false, 1: true - logs all SQL statements */
+ int log_per_node_statement; /* 0:false, 1: true - logs per node detailed SQL statements */
int parallel_mode; /* if non 0, run in parallel query mode */
@@ -653,6 +654,7 @@ extern void cancel_request(CancelPacket *sp);
/* pool_process_query.c */
void free_select_result(POOL_SELECT_RESULT *result);
void reset_variables(void);
+void per_node_statement_log(POOL_CONNECTION_POOL *backend, int node_id, char *query);
/* pool_relcache.c */
POOL_RELCACHE *pool_create_relcache(int cachesize, char *sql,
View
14 pool_config.c
@@ -485,7 +485,7 @@ char *yytext;
/* -*-pgsql-c-*- */
/*
*
- * $Header: /cvsroot/pgpool/pgpool-II/pool_config.c,v 1.30 2009/11/15 08:05:02 t-ishii Exp $
+ * $Header: /cvsroot/pgpool/pgpool-II/pool_config.c,v 1.31 2009/11/15 08:27:35 t-ishii Exp $
*
* pgpool: a language independent connection pool server for PostgreSQL
* written by Tatsuo Ishii
@@ -1863,6 +1863,7 @@ int pool_init_config(void)
pool_config->logdir = DEFAULT_LOGDIR;
pool_config->pid_file_name = DEFAULT_PID_FILE_NAME;
pool_config->log_statement = 0;
+ pool_config->log_per_node_statement = 0;
pool_config->log_connections = 0;
pool_config->log_hostname = 0;
pool_config->enable_pool_hba = 0;
@@ -2899,6 +2900,17 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context)
}
pool_config->log_statement = v;
}
+ else if (!strcmp(key, "log_per_node_statement") && CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
+ {
+ int v = eval_logical(yytext);
+
+ if (v < 0)
+ {
+ pool_error("pool_config: invalid value %s for %s", yytext, key);
+ return(-1);
+ }
+ pool_config->log_per_node_statement = v;
+ }
else if (!strcmp(key, "log_statement") && CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
{
int v = eval_logical(yytext);
View
14 pool_config.l
@@ -1,7 +1,7 @@
/* -*-pgsql-c-*- */
/*
*
- * $Header: /cvsroot/pgpool/pgpool-II/pool_config.l,v 1.26 2009/11/15 08:05:02 t-ishii Exp $
+ * $Header: /cvsroot/pgpool/pgpool-II/pool_config.l,v 1.27 2009/11/15 08:27:35 t-ishii Exp $
*
* pgpool: a language independent connection pool server for PostgreSQL
* written by Tatsuo Ishii
@@ -138,6 +138,7 @@ int pool_init_config(void)
pool_config->logdir = DEFAULT_LOGDIR;
pool_config->pid_file_name = DEFAULT_PID_FILE_NAME;
pool_config->log_statement = 0;
+ pool_config->log_per_node_statement = 0;
pool_config->log_connections = 0;
pool_config->log_hostname = 0;
pool_config->enable_pool_hba = 0;
@@ -1174,6 +1175,17 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context)
}
pool_config->log_statement = v;
}
+ else if (!strcmp(key, "log_per_node_statement") && CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
+ {
+ int v = eval_logical(yytext);
+
+ if (v < 0)
+ {
+ pool_error("pool_config: invalid value %s for %s", yytext, key);
+ return(-1);
+ }
+ pool_config->log_per_node_statement = v;
+ }
else if (!strcmp(key, "log_statement") && CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
{
int v = eval_logical(yytext);
View
9 pool_process_query.c
@@ -1,6 +1,6 @@
/* -*-pgsql-c-*- */
/*
- * $Header: /cvsroot/pgpool/pgpool-II/pool_process_query.c,v 1.173 2009/11/14 13:22:32 t-ishii Exp $
+ * $Header: /cvsroot/pgpool/pgpool-II/pool_process_query.c,v 1.174 2009/11/15 08:27:35 t-ishii Exp $
*
* pgpool: a language independent connection pool server for PostgreSQL
* written by Tatsuo Ishii
@@ -3415,6 +3415,8 @@ POOL_STATUS insert_lock(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend
/* issue lock table command */
snprintf(qbuf, sizeof(qbuf), "LOCK TABLE %s IN SHARE ROW EXCLUSIVE MODE", table);
+ per_node_statement_log(backend, MASTER_NODE_ID, qbuf);
+
status = do_command(frontend, MASTER(backend), qbuf, MAJOR(backend), MASTER_CONNECTION(backend)->pid,
MASTER_CONNECTION(backend)->key, 0);
if (status == POOL_END)
@@ -4266,6 +4268,8 @@ POOL_STATUS start_internal_transaction(POOL_CONNECTION *frontend, POOL_CONNECTIO
{
if (VALID_BACKEND(i))
{
+ per_node_statement_log(backend, i, "BEGIN");
+
if (do_command(frontend, CONNECTION(backend, i), "BEGIN", MAJOR(backend),
MASTER_CONNECTION(backend)->pid, MASTER_CONNECTION(backend)->key, 0) != POOL_CONTINUE)
return POOL_END;
@@ -4299,6 +4303,8 @@ POOL_STATUS end_internal_transaction(POOL_CONNECTION *frontend, POOL_CONNECTION_
{
if (VALID_BACKEND(i) && !IS_MASTER_NODE_ID(i))
{
+ per_node_statement_log(backend, i, "COMMIT");
+
/* COMMIT success? */
if (do_command(frontend, CONNECTION(backend, i), "COMMIT", MAJOR(backend),
MASTER_CONNECTION(backend)->pid, MASTER_CONNECTION(backend)->key, 1) != POOL_CONTINUE)
@@ -4311,6 +4317,7 @@ POOL_STATUS end_internal_transaction(POOL_CONNECTION *frontend, POOL_CONNECTION_
}
/* commit on master */
+ per_node_statement_log(backend, MASTER_NODE_ID, "COMMIT");
if (do_command(frontend, MASTER(backend), "COMMIT", MAJOR(backend),
MASTER_CONNECTION(backend)->pid, MASTER_CONNECTION(backend)->key, 1) != POOL_CONTINUE)
{
View
40 pool_proto_modules.c
@@ -1,6 +1,6 @@
/* -*-pgsql-c-*- */
/*
- * $Header: /cvsroot/pgpool/pgpool-II/pool_proto_modules.c,v 1.24 2009/11/14 13:22:32 t-ishii Exp $
+ * $Header: /cvsroot/pgpool/pgpool-II/pool_proto_modules.c,v 1.25 2009/11/15 08:27:35 t-ishii Exp $
*
* pgpool: a language independent connection pool server for PostgreSQL
* written by Tatsuo Ishii
@@ -559,6 +559,8 @@ POOL_STATUS NotificationResponse(POOL_CONNECTION *frontend,
/* Send the query to master node */
+ per_node_statement_log(backend, MASTER_NODE_ID, string);
+
if (send_simplequery_message(MASTER(backend), len, string, MAJOR(backend)) != POOL_CONTINUE)
{
free_parser();
@@ -598,6 +600,8 @@ POOL_STATUS NotificationResponse(POOL_CONNECTION *frontend,
if (!VALID_BACKEND(i) || IS_MASTER_NODE_ID(i))
continue;
+ per_node_statement_log(backend, i, string);
+
if (send_simplequery_message(CONNECTION(backend, i), len, string, MAJOR(backend)) != POOL_CONTINUE)
{
free_parser();
@@ -629,6 +633,8 @@ POOL_STATUS NotificationResponse(POOL_CONNECTION *frontend,
/* send "COMMIT" or "ROLLBACK" to only master node if query is "COMMIT" or "ROLLBACK" */
if (commit)
{
+ per_node_statement_log(backend, MASTER_NODE_ID, string);
+
if (send_simplequery_message(MASTER(backend), len, string, MAJOR(backend)) != POOL_CONTINUE)
{
free_parser();
@@ -657,6 +663,9 @@ POOL_STATUS NotificationResponse(POOL_CONNECTION *frontend,
else
{
free_parser();
+
+ per_node_statement_log(backend, MASTER_NODE_ID, string);
+
if (send_simplequery_message(MASTER(backend), len, string, MAJOR(backend)) != POOL_CONTINUE)
return POOL_END;
@@ -689,7 +698,7 @@ POOL_STATUS Execute(POOL_CONNECTION *frontend,
char kind;
int status, commit = 0;
Portal *portal;
- char *string1;
+ char *string1 = NULL;
PrepareStmt *p_stmt;
POOL_STATUS ret;
int specific_error = 0;
@@ -794,7 +803,7 @@ POOL_STATUS Execute(POOL_CONNECTION *frontend,
if (!commit)
{
/* Send the query to master node */
-
+ per_node_statement_log(backend, MASTER_NODE_ID, string1);
if (send_execute_message(backend, MASTER_NODE_ID, len, string) != POOL_CONTINUE)
return POOL_END;
@@ -836,8 +845,12 @@ POOL_STATUS Execute(POOL_CONNECTION *frontend,
if (send_execute_message(backend, i, len + 5, msg))
return POOL_END;
}
- else if (send_execute_message(backend, i, len, string) != POOL_CONTINUE)
- return POOL_END;
+ else
+ {
+ per_node_statement_log(backend, i, string1);
+ if (send_execute_message(backend, i, len, string) != POOL_CONTINUE)
+ return POOL_END;
+ }
}
/* Wait for nodes other than the master node */
@@ -863,6 +876,8 @@ POOL_STATUS Execute(POOL_CONNECTION *frontend,
/* send "COMMIT" or "ROLLBACK" to only master node if query is "COMMIT" or "ROLLBACK" */
if (commit)
{
+ per_node_statement_log(backend, MASTER_NODE_ID, string1);
+
if (send_execute_message(backend, MASTER_NODE_ID, len, string) != POOL_CONTINUE)
return POOL_END;
@@ -882,6 +897,8 @@ POOL_STATUS Execute(POOL_CONNECTION *frontend,
}
else
{
+ per_node_statement_log(backend, MASTER_NODE_ID, string1);
+
if (send_execute_message(backend, MASTER_NODE_ID, len, string) != POOL_CONTINUE)
return POOL_END;
@@ -1149,6 +1166,8 @@ POOL_STATUS Parse(POOL_CONNECTION *frontend,
{
pool_log("Parse: received deadlock error message from master node");
+ per_node_statement_log(backend, i, POOL_ERROR_QUERY);
+
if (send_simplequery_message(CONNECTION(backend, i),
strlen(POOL_ERROR_QUERY)+1,
POOL_ERROR_QUERY,
@@ -2619,3 +2638,14 @@ static int is_temp_table(POOL_CONNECTION_POOL *backend, Node *node)
result = (int)pool_search_relcache(relcache, backend, str);
return result;
}
+
+/*
+ * Make per DB node statement log
+ */
+void per_node_statement_log(POOL_CONNECTION_POOL *backend, int node_id, char *query)
+{
+ POOL_CONNECTION_POOL_SLOT *slot = backend->slots[node_id];
+
+ if (pool_config->log_per_node_statement)
+ pool_log("DB node id: %d backend pid: %d statement: %s", node_id, ntohl(slot->pid), query);
+}
View
5 pool_relcache.c
@@ -1,6 +1,6 @@
/* -*-pgsql-c-*- */
/*
- * $Header: /cvsroot/pgpool/pgpool-II/pool_relcache.c,v 1.3 2009/11/05 06:27:12 t-ishii Exp $
+ * $Header: /cvsroot/pgpool/pgpool-II/pool_relcache.c,v 1.4 2009/11/15 08:27:35 t-ishii Exp $
*
* pgpool: a language independent connection pool server for PostgreSQL
* written by Tatsuo Ishii
@@ -139,6 +139,9 @@ void *pool_search_relcache(POOL_RELCACHE *relcache, POOL_CONNECTION_POOL *backen
/* Not in cache. Check the system catalog */
snprintf(query, sizeof(query), relcache->sql, rel);
+
+ per_node_statement_log(backend, MASTER_NODE_ID, query);
+
if (do_query(MASTER(backend), query, &res) != POOL_CONTINUE)
{
pool_error("pool_search_relcache: do_query failed");
Please sign in to comment.
Something went wrong with that request. Please try again.