无法从 show 命令获取结果,所以我使用pgadmin并添加了一些 PHP 代码来获取它。
首先你必须安装 pgadmin 并将 getNodeInfo.php 添加到文件夹中,getNodeInfo.php 代码:
<?php
/**
* The status value can refrence:
* http://www.pgpool.net/docs/latest/en/html/pcp-node-info.html
*
* Status is represented by a digit from [0 to 3].
*
* 0 - This state is only used during the initialization. PCP will never display it.
*
* 1 - Node is up. No connections yet.
*
* 2 - Node is up. Connections are pooled.
*
* 3 - Node is down.
*/
require_once('common.php');
require_once('command.php');
$_SESSION[SESSION_LOGIN_USER] = "your_pgadmin_account";
$_SESSION[SESSION_LOGIN_USER_PASSWORD] = "your_pgadmin_password";
$nodeCount = getNodeCount();
$nodeInfo = array();
for($i = 0;$i < $nodeCount; $i++){
$nodeInfo[$i] = getNodeInfo($i);
}
echo json_encode($nodeInfo);
exit();
如果你的 pgadmin 可以正常工作,你可以调用http://localhost/getNodeInfo.php来获取喜欢
[
{
"hostname": "host1 ip",
"port": "5432",
"status": "2",
"weight": "0.500"
},
{
"hostname": "host2 ip",
"port": "5432",
"status": "2",
"weight": "0.500"
}
]
如果状态 == 3,则主机已关闭。