<div dir="ltr"><div class="gmail_quote">On Fri, Oct 26, 2012 at 10:27 PM, 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">

<div class="HOEnZb"><div class="h5">&gt;&gt; On Fri, Oct 26, 2012 at 6:00 AM, Tatsuo Ishii &lt;<a href="mailto:ishii@postgresql.org">ishii@postgresql.org</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt;&gt; Sorry for late reply.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; &gt; Hi,<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt;     The docs [1] say that one of the preconditions for load-balancing is<br>
&gt;&gt;&gt; &gt; that<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt;     &gt; The query must not be in an explicitly declared transaction (i.e.<br>
&gt;&gt;&gt; not<br>
&gt;&gt;&gt; &gt; in a BEGIN ~ END block)<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Yeah, the doc is outdated in this regard.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; &gt;     But I see that this is not a strict statement. I extracted a specific<br>
&gt;&gt;&gt; &gt; backend process&#39; log lines (generated using log_per_node_statement), and<br>
&gt;&gt;&gt; I<br>
&gt;&gt;&gt; &gt; could see that on line 6, the SELECT query was load-balanced to a replica<br>
&gt;&gt;&gt; &gt; (node id 2) and the next INSERT statement was correctly sent to the<br>
&gt;&gt;&gt; master.<br>
&gt;&gt;&gt; &gt; But any SELECT after that INSERT was not sent to the replica, and only to<br>
&gt;&gt;&gt; &gt; the master.<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt;     So can we say that load balancing _does_ occur in an explicitly<br>
&gt;&gt;&gt; &gt; declared transaction, but as soon as a DML operation is perfored, any<br>
&gt;&gt;&gt; &gt; subsequent SELECT queries will be sent only to master.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Yes, that is expected behavior if you are using streaming replication<br>
&gt;&gt;&gt; mode. The reason why SELECTs are sent to master after DML issued is,<br>
&gt;&gt;&gt; standby cannot see the modified rows.<br>
&gt;&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; Can we expect doc changes, or I should probably file a bug-report against<br>
&gt;&gt; documentation so that it gets taken care of in due process.<br>
&gt;<br>
&gt; I will propose doc changes.<br>
<br>
</div></div>Included is the patch I promised. There are more to fix than what<br>
discussed though. If you are comfortable with this, I will commit.<br></blockquote><div><br>Looks good to me.<br><br>Best regards,<br></div></div>-- <br><div dir="ltr">Gurjeet Singh<br><br><a href="http://gurjeet.singh.im/" target="_blank">http://gurjeet.singh.im/</a><br>

</div><br>
</div>