您必须创建PCPPASSFILE。搜索 pgpool文档以获取更多信息。
示例 1:
为登录用户创建 PCPPASSFILE ( vi ~/.pcppass
),文件内容为 127.0.0.1:9897:user:pass (hostname:port:username:password),设置文件权限 0600 ( chmod 0600 ~/.pcppass
)
命令应该在不询问密码的情况下运行
pcp_attach_node -h 127.0.0.1 -U user -p 9897 -w -n 1
示例 2:
创建PCPPASSFILE( vi /usr/local/etc/.pcppass
),文件内容为127.0.0.1:9897:user:pass(hostname:port:username:password),设置文件权限0600( chmod 0600 /usr/local/etc/.pcppass
),设置变量PCPPASSFILE( export PCPPASSFILE=/usr/local/etc/.pcppass
)
命令应该在不询问密码的情况下运行
pcp_attach_node -h 127.0.0.1 -U user -p 9897 -w -n 1
自动附加节点的脚本
您可以使用例如 crontab 来安排此脚本。
#!/bin/bash
#pgpool status
#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.
source $HOME/.bash_profile
export PCPPASSFILE=/appl/scripts/.pcppass
STATUS_0=$(/usr/local/bin/pcp_node_info -h 127.0.0.1 -U postgres -p 9897 -n 0 -w | cut -d " " -f 3)
echo $(date +%Y.%m.%d-%H:%M:%S.%3N)" [INFO] NODE 0 status "$STATUS_0;
if (( $STATUS_0 == 3 ))
then
echo $(date +%Y.%m.%d-%H:%M:%S.%3N)" [WARN] NODE 0 is down - attaching node"
TMP=$(/usr/local/bin/pcp_attach_node -h 127.0.0.1 -U postgres -p 9897 -n 0 -w -v)
echo $(date +%Y.%m.%d-%H:%M:%S.%3N)" [INFO] "$TMP
fi
STATUS_1=$(/usr/local/bin/pcp_node_info -h 127.0.0.1 -U postgres -p 9897 -n 1 -w | cut -d " " -f 3)
echo $(date +%Y.%m.%d-%H:%M:%S.%3N)" [INFO] NODE 1 status "$STATUS_1;
if (( $STATUS_1 == 3 ))
then
echo $(date +%Y.%m.%d-%H:%M:%S.%3N)" [WARN] NODE 1 is down - attaching node"
TMP=$(/usr/local/bin/pcp_attach_node -h 127.0.0.1 -U postgres -p 9897 -n 1 -w -v)
echo $(date +%Y.%m.%d-%H:%M:%S.%3N)" [INFO] "$TMP
fi
exit 0