hostname, the port, the status, the weight (only meaningful if
you use the load balancing mode), the role, the SELECT query
counts issued to each backend, whether each node is the load
- bakance node or not, and the replication delay (only if in
- streaming replication mode). The possible values in the status
- column are explained in the <xref linkend="pcp-node-info">
- reference. If the hostname is something like "/tmp", that means
+ bakance node or not, the replication delay (only if in streaming
+ replication mode) and last status change time. The possible
+ values in the status column are explained in
+ the <xref linkend="pcp-node-info"> reference. If the hostname is
+ something like "/tmp", that means
<productname>Pgpool-II</productname> is connecting to backend by
using UNIX domain sockets. The SELECT count does not include
internal queries used
by <productname>Pgoool-II</productname>. Also the counters are
- reset to zero upon starting up of pgpool-II. displays the
- current value of
- <productname>Pgpool-II</productname> configuration parameters.
+ reset to zero upon starting up
+ of <productname>Pgpool-II</productname>. The last status change
+ time is initially set to the
+ time <productname>Pgpool-II</productname> starts. After that
+ whenever "status" or "role" is changed, it is updated.
-->
-
<command>SHOW POOL_NODES</command> はホスト名、ポート番号、状態、
重み(ロードバランスモードで運用しているときにのみ意味があります)、
ノードの役割、発行された SELECT の数、ロードバランスノードであるかどうか、
- レプリケーション遅延 (ストリーミングレプリケーションモードのみ) が表示されます。
+ ã\83¬ã\83\97ã\83ªã\82±ã\83¼ã\82·ã\83§ã\83³é\81\85å»¶ (ã\82¹ã\83\88ã\83ªã\83¼ã\83\9fã\83³ã\82°ã\83¬ã\83\97ã\83ªã\82±ã\83¼ã\82·ã\83§ã\83³ã\83¢ã\83¼ã\83\89ã\81®ã\81¿) ã\80\81æ\9c\80çµ\82ç\8a¶æ\85\8bå¤\89æ\9b´æ\99\82å\88»ã\81\8c表示ã\81\95ã\82\8cã\81¾ã\81\99ã\80\82
状態(status)の意味については、 <xref linkend="pcp-node-info"> リファレンスで説明されています。
ホスト名が "/tmp" のように表示される場合、UNIX ドメインソケットを使用して
<productname>Pgpool-II</productname> が <productname>PostgreSQL</productname> に接続していることを意味します。
SELECT の数には、<productname>Pgpool-II</productname> 内部で発行されるクエリの数は含まれません。
また、このカウンタは <productname>Pgpool-II</productname> がスタートした時に 0にリセットされます。
+ 最終状態変更時刻は、<productname>Pgpool-II</productname>が起動した時にセットされたあとは、"status"あるいは"role"が変更される度に更新されます。
</para>
<para>
<!--
ここでは例を示します。
<programlisting>
test=# show pool_nodes;
- node_id | hostname | port | status | lb_weight | role | select_cnt | load_balance_node | replication_delay
----------+----------+-------+--------+-----------+---------+------------+-------------------+-------------------
- 0 | /tmp | 11002 | up | 0.500000 | primary | 0 | false | 0
- 1 | /tmp | 11003 | up | 0.500000 | standby | 0 | true | 0
+ node_id | hostname | port | status | lb_weight | role | select_cnt | load_balance_node | replication_delay | last_status_change
+---------+----------+-------+--------+-----------+---------+------------+-------------------+-------------------+---------------------
+ 0 | /tmp | 11002 | up | 0.500000 | primary | 0 | true | 0 | 2018-06-12 21:45:59
+ 1 | /tmp | 11003 | up | 0.500000 | standby | 0 | false | 0 | 2018-06-12 21:45:59
(2 rows)
</programlisting>
</para>
hostname, the port, the status, the weight (only meaningful if
you use the load balancing mode), the role, the SELECT query
counts issued to each backend, whether each node is the load
- bakance node or not, and the replication delay (only if in
- streaming replication mode). The possible values in the status
- column are explained in the <xref linkend="pcp-node-info">
- reference. If the hostname is something like "/tmp", that means
+ bakance node or not, the replication delay (only if in streaming
+ replication mode) and last status change time. The possible
+ values in the status column are explained in
+ the <xref linkend="pcp-node-info"> reference. If the hostname is
+ something like "/tmp", that means
<productname>Pgpool-II</productname> is connecting to backend by
using UNIX domain sockets. The SELECT count does not include
internal queries used
by <productname>Pgoool-II</productname>. Also the counters are
- reset to zero upon starting up of <productname>Pgpool-II</productname>.
+ reset to zero upon starting up
+ of <productname>Pgpool-II</productname>. The last status change
+ time is initially set to the
+ time <productname>Pgpool-II</productname> starts. After that
+ whenever "status" or "role" is changed, it is updated.
</para>
<para>
Here is an example session:
<programlisting>
test=# show pool_nodes;
- node_id | hostname | port | status | lb_weight | role | select_cnt | load_balance_node | replication_delay
----------+----------+-------+--------+-----------+---------+------------+-------------------+-------------------
- 0 | /tmp | 11002 | up | 0.500000 | primary | 0 | false | 0
- 1 | /tmp | 11003 | up | 0.500000 | standby | 0 | true | 0
+ node_id | hostname | port | status | lb_weight | role | select_cnt | load_balance_node | replication_delay | last_status_change
+---------+----------+-------+--------+-----------+---------+------------+-------------------+-------------------+---------------------
+ 0 | /tmp | 11002 | up | 0.500000 | primary | 0 | true | 0 | 2018-06-12 21:45:59
+ 1 | /tmp | 11003 | up | 0.500000 | standby | 0 | false | 0 | 2018-06-12 21:45:59
(2 rows)
</programlisting>
</para>
* pgpool: a language independent connection pool server for PostgreSQL
* written by Tatsuo Ishii
*
- * Copyright (c) 2003-2017 PgPool Global Development Group
+ * Copyright (c) 2003-2018 PgPool Global Development Group
*
* Permission to use, copy, modify, and distribute this software and
* its documentation for any purpose and without fee is hereby
char backend_hostname[MAX_DB_HOST_NAMELEN]; /* backend host name */
int backend_port; /* backend port numbers */
BACKEND_STATUS backend_status; /* backend status */
+ time_t status_changed_time; /* backend status changed time */
double backend_weight; /* normalized backend load balance ratio */
double unnormalized_weight; /* descripted parameter */
char backend_data_directory[MAX_PATH_LENGTH];
char select[POOLCONFIG_MAXWEIGHTLEN+1];
char load_balance_node[POOLCONFIG_MAXWEIGHTLEN+1];
char delay[POOLCONFIG_MAXWEIGHTLEN+1];
+ char last_status_change[POOLCONFIG_MAXDATELEN];
} POOL_REPORT_NODES;
/* processes report struct */
extern void do_health_check_child(int *node_id);
extern POOL_NODE_STATUS *verify_backend_node_status(POOL_CONNECTION_POOL_SLOT **slots);
extern POOL_NODE_STATUS *pool_get_node_status(void);
+extern void pool_set_backend_status_changed_time(int backend_id);
#endif /* POOL_H */
all_backend_down = check_all_backend_down();
BACKEND_INFO(node_id).backend_status = CON_CONNECT_WAIT; /* unset down status */
+ pool_set_backend_status_changed_time(node_id);
+
if (!(request_details & REQ_DETAIL_UPDATE))
{
/* The request is a proper failbak request
BACKEND_INFO(node_id_set[i]).backend_port)));
BACKEND_INFO(node_id_set[i]).backend_status = CON_DOWN; /* set down status */
+ pool_set_backend_status_changed_time(node_id_set[i]);
if (reqkind == NODE_QUARANTINE_REQUEST)
{
bkinfo->backend_hostname,
bkinfo->backend_port)));
bkinfo->backend_status = CON_DOWN; /* set down status */
+ pool_set_backend_status_changed_time(i);
(void)write_status_file();
follow_cnt++;
}
/* Save primary node id */
+ if (Req_info->primary_node_id != new_primary)
+ {
+ if (Req_info->primary_node_id >= 0)
+ pool_set_backend_status_changed_time(Req_info->primary_node_id);
+ if (new_primary >= 0)
+ pool_set_backend_status_changed_time(new_primary);
+ }
Req_info->primary_node_id = new_primary;
ereport(LOG,
(errmsg("failover: set new primary node: %d", Req_info->primary_node_id)));
if (backend_rec.status[i] == CON_DOWN)
{
BACKEND_INFO(i).backend_status = CON_DOWN;
+ pool_set_backend_status_changed_time(i);
(void)write_status_file();
ereport(LOG,
(errmsg("read_status_file: %d th backend is set to down status", i)));
BACKEND_INFO(i).backend_status == CON_UP)
{
BACKEND_INFO(i).backend_status = CON_CONNECT_WAIT;
+ pool_set_backend_status_changed_time(i);
(void)write_status_file();
someone_wakeup = true;
}
for (i=0;i<MAX_NUM_BACKENDS;i++)
{
BACKEND_INFO(i).backend_status = CON_UNUSED;
+ pool_set_backend_status_changed_time(i);
}
for (i=0;;i++)
else if (!strncasecmp("down", readbuf, 4))
{
BACKEND_INFO(i).backend_status = CON_DOWN;
+ pool_set_backend_status_changed_time(i);
ereport(LOG,
(errmsg("reading status file: %d th backend is set to down status", i)));
}
else if (!strncasecmp("unused", readbuf, 6))
{
BACKEND_INFO(i).backend_status = CON_UNUSED;
+ pool_set_backend_status_changed_time(i);
}
else
{
for (i=0;i< pool_config->backend_desc->num_backends;i++)
{
BACKEND_INFO(i).backend_status = CON_CONNECT_WAIT;
+ pool_set_backend_status_changed_time(i);
}
(void)write_status_file();
}
if (BACKEND_INFO(i).backend_status != CON_DOWN)
{
BACKEND_INFO(i).backend_status = CON_DOWN;
+ pool_set_backend_status_changed_time(i);
my_backend_status[i] = &(BACKEND_INFO(i).backend_status);
reload_maste_node_id = true;
node_status_was_changed_to_down = true;
node_status_was_changed_to_up = true;
BACKEND_INFO(i).backend_status = CON_CONNECT_WAIT;
+ pool_set_backend_status_changed_time(i);
my_backend_status[i] = &(BACKEND_INFO(i).backend_status);
reload_maste_node_id = true;
*port = '\0';
}
}
+
+/*
+ * Set backend status changed time for specified backend id.
+ */
+void
+pool_set_backend_status_changed_time(int backend_id)
+{
+ time_t tval;
+ tval = time(NULL);
+ BACKEND_INFO(backend_id).status_changed_time = tval;
+}
pool_init_params(&s->con->params);
- BACKEND_INFO(i).backend_status = CON_UP;
+ if (BACKEND_INFO(i).backend_status != CON_UP)
+ {
+ BACKEND_INFO(i).backend_status = CON_UP;
+ pool_set_backend_status_changed_time(i);
+ }
active_backend_count++;
}
select_cnt text,
load_balance_node text,
replication_delay text,
+ last_status_change text,
mode text);
INSERT INTO tmp VALUES
-('0',:dir,'11002','up','0.500000','primary','0','false','0','s'),
-('1',:dir,'11003','down','0.500000','standby','0','false','0','s'),
-('0',:dir,'11002','up','0.500000','master','0','false','0','r'),
-('1',:dir,'11003','down','0.500000','slave','0','false','0','r');
+('0',:dir,'11002','up','0.500000','primary','0','false','0','XXXX-XX-XX XX:XX:XX','s'),
+('1',:dir,'11003','down','0.500000','standby','0','false','0','XXXX-XX-XX XX:XX:XX','s'),
+('0',:dir,'11002','up','0.500000','master','0','false','0','XXXX-XX-XX XX:XX:XX','r'),
+('1',:dir,'11003','down','0.500000','slave','0','false','0','XXXX-XX-XX XX:XX:XX','r');
-SELECT node_id,hostname,port,status,lb_weight,role,select_cnt,load_balance_node,replication_delay
+SELECT node_id,hostname,port,status,lb_weight,role,select_cnt,load_balance_node,replication_delay,last_status_change
FROM tmp
WHERE mode = :mode
select_cnt text,
load_balance_node text,
replication_delay text,
+ last_status_change text,
mode text);
INSERT INTO tmp VALUES
-('0',:dir,'11002','down','0.500000','standby','0','false','0','s'),
-('1',:dir,'11003','up','0.500000','primary','0','false','0','s'),
-('0',:dir,'11002','down','0.500000','slave','0','false','0','r'),
-('1',:dir,'11003','up','0.500000','master','0','false','0','r');
+('0',:dir,'11002','down','0.500000','standby','0','false','0','XXXX-XX-XX XX:XX:XX','s'),
+('1',:dir,'11003','up','0.500000','primary','0','false','0','XXXX-XX-XX XX:XX:XX','s'),
+('0',:dir,'11002','down','0.500000','slave','0','false','0','XXXX-XX-XX XX:XX:XX','r'),
+('1',:dir,'11003','up','0.500000','master','0','false','0','XXXX-XX-XX XX:XX:XX','r');
-SELECT node_id,hostname,port,status,lb_weight,role,select_cnt,load_balance_node,replication_delay
+SELECT node_id,hostname,port,status,lb_weight,role,select_cnt,load_balance_node,replication_delay,last_status_change
FROM tmp
WHERE mode = :mode
# trigger failover on node 1
$PG_CTL -D data1 -m f stop
wait_for_pgpool_startup
- $PSQL -c "show pool_nodes" test |sed -e 's/true /false/'> result
+ $PSQL -c "show pool_nodes" test |sed -e 's/true /false/' -e 's/....-..-.. ..:..:../XXXX-XX-XX XX:XX:XX/g'> result
# check the output of "show pool_nodes".
LANG=C $PSQL -f ../create_expected.sql -v mode="'$mode'" -v dir="'$PGSOCKET_DIR'" test | tail -n 6 > expected
# trigger failover on node 0
$PG_CTL -D data0 -m f stop
wait_for_failover_done
- $PSQL -c "show pool_nodes" test | sed -e 's/true /false/' > result
+ $PSQL -c "show pool_nodes" test |sed -e 's/true /false/' -e 's/....-..-.. ..:..:../XXXX-XX-XX XX:XX:XX/g'> result
if [ ! -s result ];then
./shutdownall
echo "result file is empty."
POOL_REPORT_NODES* nodes = palloc(NUM_BACKENDS * sizeof(POOL_REPORT_NODES));
BackendInfo *bi = NULL;
POOL_SESSION_CONTEXT *session_context = pool_get_session_context(false);
+ struct tm tm;
for (i = 0; i < NUM_BACKENDS; i++)
{
else
snprintf(nodes[i].role, POOLCONFIG_MAXWEIGHTLEN, "%s", "slave");
}
+
+ /* status last changed */
+ localtime_r(&bi->status_changed_time, &tm);
+ strftime(nodes[i].last_status_change, POOLCONFIG_MAXDATELEN, "%F %T", &tm);
}
*nrows = i;
void nodes_reporting(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend)
{
- static char *field_names[] = {"node_id","hostname", "port", "status", "lb_weight", "role", "select_cnt", "load_balance_node", "replication_delay"};
+ static char *field_names[] = {"node_id","hostname", "port", "status", "lb_weight", "role", "select_cnt", "load_balance_node", "replication_delay", "last_status_change"};
short num_fields = sizeof(field_names)/sizeof(char *);
int i;
short s;
hsize = htonl(size+4);
pool_write(frontend, &hsize, sizeof(hsize));
pool_write(frontend, nodes[i].delay, size);
+
+ size = strlen(nodes[i].last_status_change);
+ hsize = htonl(size+4);
+ pool_write(frontend, &hsize, sizeof(hsize));
+ pool_write(frontend, nodes[i].last_status_change, size);
}
}
else
len += 4 + strlen(nodes[i].select); /* int32 + data; */
len += 4 + strlen(nodes[i].load_balance_node); /* int32 + data; */
len += 4 + strlen(nodes[i].delay); /* int32 + data; */
+ len += 4 + strlen(nodes[i].last_status_change); /* int32 + data; */
len = htonl(len);
pool_write(frontend, &len, sizeof(len));
s = htons(num_fields);
len = htonl(strlen(nodes[i].delay));
pool_write(frontend, &len, sizeof(len));
pool_write(frontend, nodes[i].delay, strlen(nodes[i].delay));
+
+ len = htonl(strlen(nodes[i].last_status_change));
+ pool_write(frontend, &len, sizeof(len));
+ pool_write(frontend, nodes[i].last_status_change, strlen(nodes[i].last_status_change));
}
}