<div dir="ltr">Hi,<div>what if I want to get the <b>primary node hostname</b>, is there any &quot;easy way&quot; to get it  ?</div><div>how can I get the hostname using the node_id (without sql query &amp; string manipulation)??</div><div><br></div><div>Thanks,</div><div>cohavisi</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Nov 10, 2015 at 1:43 AM, Tatsuo Ishii <span dir="ltr">&lt;<a href="mailto:ishii@postgresql.org" target="_blank">ishii@postgresql.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">&gt; Hi,<br>
&gt;<br>
&gt; *using postgresql 9.3.1 and pgpool 3.42*<br>
<span class="">&gt;<br>
&gt; I try to write failover &amp; failback mechanism using pgpool attach/detach pcp<br>
&gt; command.<br>
&gt; but sometimes I had noticed that the argument send to the failback script<br>
&gt; are wrong (new primary hostname is not right):<br>
<br>
</span>There&#39;s no parameter for new primary hostname.  If you care about<br>
primary node, you should use %P.<br>
<br>
#   %P = old primary node id<br>
<br>
Note that &quot;master node&quot; != &quot;primary node&quot; in pgpool-II terms. The<br>
master node is a live node which has the youngest node id.<br>
--<br>
Tatsuo Ishii<br>
SRA OSS, Inc. Japan<br>
English: <a href="http://www.sraoss.co.jp/index_en.php" rel="noreferrer" target="_blank">http://www.sraoss.co.jp/index_en.php</a><br>
Japanese:<a href="http://www.sraoss.co.jp" rel="noreferrer" target="_blank">http://www.sraoss.co.jp</a><br>
<br>
&gt; # *psql -U postgres -h 192.168.15.59 -p 9999 template1 -c &quot;show<br>
&gt; pool_nodes;&quot;*<br>
<span class="">&gt; Password for user postgres:<br>
&gt;  node_id |   hostname    | port | status | lb_weight |  role<br>
&gt; ---------+---------------+------+--------+-----------+---------<br>
&gt;  0       | 192.168.15.55 | 5432 | 2      | 0.500000  | standby<br>
&gt;  1       | 192.168.15.56 | 5432 | 2      | 0.500000  | primary<br>
&gt; (2 rows)<br>
&gt;<br>
&gt;<br>
</span>&gt; #* pcp_detach_node -d 10 192.168.15.59 9898 user password 0*<br>
<span class="">&gt; DEBUG: send: tos=&quot;R&quot;, len=44<br>
&gt; DEBUG: recv: tos=&quot;r&quot;, len=21, data=AuthenticationOK<br>
&gt; DEBUG: send: tos=&quot;D&quot;, len=6<br>
&gt; DEBUG: recv: tos=&quot;d&quot;, len=20, data=CommandComplete<br>
&gt; DEBUG: send: tos=&quot;X&quot;, len=4<br>
&gt;<br>
&gt;<br>
</span>&gt; [root@mgrdb-56 etc]# *psql -U postgres -h 192.168.15.59 -p 9999 template1<br>
&gt; -c &quot;show pool_nodes;&quot;*<br>
<span class="">&gt; Password for user postgres:<br>
&gt;  node_id |   hostname    | port | status | lb_weight |  role<br>
&gt; ---------+---------------+------+--------+-----------+---------<br>
&gt;  0       | 192.168.15.55 | 5432 | 3      | 0.500000  | standby<br>
&gt;  1       | 192.168.15.56 | 5432 | 2      | 0.500000  | primary<br>
&gt; (2 rows)<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
</span>&gt; # *pcp_attach_node -d 10 192.168.15.59 9898 user password 0*<br>
<span class="">&gt; DEBUG: send: tos=&quot;R&quot;, len=44<br>
&gt; DEBUG: recv: tos=&quot;r&quot;, len=21, data=AuthenticationOK<br>
&gt; DEBUG: send: tos=&quot;D&quot;, len=6<br>
&gt; DEBUG: recv: tos=&quot;c&quot;, len=20, data=CommandComplete<br>
&gt; DEBUG: send: tos=&quot;X&quot;, len=4<br>
&gt;<br>
&gt;<br>
&gt;<br>
</span>&gt; *failback.sh script is being executed:*<br>
&gt; *from pgpool.conf:*<br>
&gt; *failback_command=&#39;/etc/pgpool-II/recovery/failback.sh %d %h %H %m %M %D %R<br>
&gt; %r&#39;*<br>
&gt;<br>
&gt; *from failback.sh:*<br>
&gt; *NODE_ID=$1*<br>
&gt; *HOST_NAME=$2*<br>
&gt; *NEW_MASTER_HOSTNAME=$3*<br>
&gt; *NEW_MASTER_NODE_ID=$4*<br>
&gt; *OLD_MASTER_NODE_ID=$5*<br>
&gt; *DATABASE_CLUSTER_PATH=$6*<br>
&gt; *MASTER_CLUSTER_PATH=$7*<br>
&gt; *NEW_MASTER_PORT=$8*<br>
&gt;<br>
&gt; *function log()*<br>
&gt; *{*<br>
&gt; *###log error messages###*<br>
&gt; *[ ! &quot;$1&quot; ] &amp;&amp; return 0*<br>
&gt; */bin/echo &quot;[$(/bin/date +%m/%d/%y\ %H:%M:%S.%2N)] - $1&quot; &gt;&gt;<br>
&gt; $PGHOME/failback.log*<br>
&gt; *}*<br>
&gt;<br>
&gt; *log &quot;&quot;*<br>
&gt; *log &quot;--- failback of $HOST_NAME ---&quot;*<br>
&gt; *log &quot;&quot;*<br>
&gt; *log &quot;node_id: $NODE_ID&quot;*<br>
&gt; *log &quot;hostname: $HOST_NAME&quot;*<br>
&gt; *log &quot;hostname of new master: $NEW_MASTER_HOSTNAME&quot;*<br>
&gt; *log &quot;new master node id: $NEW_MASTER_NODE_ID&quot;*<br>
&gt; *log &quot;old master node id: $OLD_MASTER_NODE_ID&quot;*<br>
&gt; *log &quot;database cluster path: $DATABASE_CLUSTER_PATH&quot;*<br>
&gt; *log &quot;master database cluster path: $MASTER_CLUSTER_PATH&quot;*<br>
&gt; *log &quot;master port: $NEW_MASTER_PORT&quot;*<br>
&gt; *for i in $*; do*<br>
&gt; *  log &quot;$i&quot;*<br>
&gt; *done*<br>
&gt; *exit 0*<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; *and the log outputs:*<br>
&gt;<br>
&gt; *[11/09/15 19:02:00.66] - --- failback of 192.168.15.55 ---*<br>
&gt; *[11/09/15 19:02:00.66] - node_id: 0*<br>
&gt; *[11/09/15 19:02:00.67] - hostname: 192.168.15.55*<br>
&gt; *[11/09/15 19:02:00.67] - hostname of new master: 192.168.15.55*<br>
&gt; *[11/09/15 19:02:00.67] - new master node id: 0*<br>
&gt; *[11/09/15 19:02:00.67] - old master node id: 1*<br>
&gt; *[11/09/15 19:02:00.67] - database cluster path:<br>
&gt; /home/postgres/databases/fabrix*<br>
&gt; *[11/09/15 19:02:00.68] - master database cluster path:<br>
&gt; /home/postgres/databases/fabrix*<br>
&gt; *[11/09/15 19:02:00.68] - master port: 5432*<br>
&gt; *[11/09/15 19:02:00.68] - 0*<br>
&gt; *[11/09/15 19:02:00.68] - 192.168.15.55*<br>
&gt; *[11/09/15 19:02:00.68] - 192.168.15.55*<br>
&gt; *[11/09/15 19:02:00.69] - 0*<br>
&gt; *[11/09/15 19:02:00.69] - 1*<br>
&gt; *[11/09/15 19:02:00.69] - /home/postgres/databases/fabrix*<br>
&gt; *[11/09/15 19:02:00.69] - /home/postgres/databases/fabrix*<br>
&gt; *[11/09/15 19:02:00.69] - 5432*<br>
<div class="HOEnZb"><div class="h5">&gt;<br>
&gt;<br>
&gt;<br>
&gt; as you can tell the new master us not 192.168.15.55 , should be<br>
&gt; 192.168.15.56.<br>
&gt;<br>
&gt;<br>
&gt; Please advice,<br>
&gt;<br>
&gt; cohavisi<br>
</div></div></blockquote></div><br></div>