Sorry, here is the attached patch.

Le 30/12/2010 22:39, Gilles Darold a écrit :
> Hi,
>
> Here is an other path that display the master/slave state in the "SHOW
> pool_nodes" command.
>
> psql -p 9999 -c "SHOW pool_nodes;"
>
>  node_id |   hostname   | port | status | lb_weight | state
> ---------+--------------+------+--------+-----------+-------
>  0       | 192.168.1.11 | 5432 | 2      | 0.500000  | P
>  1       | 192.168.1.12 | 5432 | 2      | 0.500000  | S
> (2 rows)
>
> P : stand for Primary
> S : stand for Secondary
>
> Feel free to apply the patch if you like it, for me it is really useful
> to know who is the master at a given time
-- 
Gilles Darold
http://dalibo.com - http://dalibo.org

--- pgpool-II/pool_process_reporting.c	2010-12-30 01:47:05.000000000 +0100
+++ pgpool-II-current/pool_process_reporting.c	2010-12-30 19:45:24.000000000 +0100
@@ -55,6 +55,7 @@
 	char port[POOLCONFIG_MAXIDENTLEN+1];
 	char status[POOLCONFIG_MAXSTATLEN+1];
 	char lb_weight[POOLCONFIG_MAXWEIGHTLEN+1];
+        char state[POOLCONFIG_MAXSTATLEN+1];
 } POOL_REPORT_NODES;
 
 /* processes report struct */
@@ -662,8 +663,8 @@
 void nodes_reporting(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend)
 {
 	static char *cursorname = "blank";
-	static short num_fields = 5;
-	static char *field_names[] = {"node_id","hostname", "port", "status", "lb_weight"};
+	static short num_fields = 6;
+	static char *field_names[] = {"node_id","hostname", "port", "status", "lb_weight", "state"};
 	static int oid = 0;
 	static short fsize = -1;
 	static int mod = 0;
@@ -692,6 +693,10 @@
 	    snprintf(nodes[i].port, 	POOLCONFIG_MAXIDENTLEN, "%d", 	bi->backend_port);
 	    snprintf(nodes[i].status, 	POOLCONFIG_MAXSTATLEN, 	"%d", 	bi->backend_status);
 	    snprintf(nodes[i].lb_weight, POOLCONFIG_MAXWEIGHTLEN, "%f", bi->backend_weight/RAND_MAX);
+	    if (IS_MASTER_NODE_ID(i))
+		snprintf(nodes[i].state, POOLCONFIG_MAXSTATLEN, "%s",   "P");
+	    else
+		snprintf(nodes[i].state, POOLCONFIG_MAXSTATLEN, "%s",   "S");
 	}
 
 	nrows = i;
@@ -787,6 +792,11 @@
 			hsize = htonl(size+4);
 			pool_write(frontend, &hsize, sizeof(hsize));
 			pool_write(frontend, nodes[i].lb_weight, size);
+
+			size = strlen(nodes[i].state);
+			hsize = htonl(size+4);
+			pool_write(frontend, &hsize, sizeof(hsize));
+			pool_write(frontend, nodes[i].state, size);
 		}
 	}
 	else
@@ -801,6 +811,7 @@
 			len += sizeof(int) + strlen(nodes[i].port);
 			len += sizeof(int) + strlen(nodes[i].status);
 			len += sizeof(int) + strlen(nodes[i].lb_weight);
+			len += sizeof(int) + strlen(nodes[i].state);
 			len = htonl(len);
 			pool_write(frontend, &len, sizeof(len));
 			s = htons(num_fields);
@@ -825,6 +836,10 @@
 			len = htonl(strlen(nodes[i].lb_weight));
 			pool_write(frontend, &len, sizeof(len));
 			pool_write(frontend, nodes[i].lb_weight, strlen(nodes[i].lb_weight));
+
+			len = htonl(strlen(nodes[i].state));
+			pool_write(frontend, &len, sizeof(len));
+			pool_write(frontend, nodes[i].state, strlen(nodes[i].state));
 		}
 	}
 
_______________________________________________
Pgpool-hackers mailing list
[email protected]
http://pgfoundry.org/mailman/listinfo/pgpool-hackers

Reply via email to