<div dir="ltr">Hi!<br>Here is test case that fails on slow replication.<div><br><div class="gmail_quote">чт, 23 апр. 2015 г. в 17:16, Tatsuo Ishii &lt;<a href="mailto:ishii@postgresql.org">ishii@postgresql.org</a>&gt;:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">&gt; Our stored function is not balanced. But next select in the same<br>
<br>
Could you show me a concrete example? I hardly believe that SELECT<br>
foo() or SELECT * FROM foo() is not load balanced if neither white and<br>
black function lists are not specified.<br>
<br>
&gt; transaction is balanced. Documentation, if i understand it correctly,<br>
&gt; states that it should not be balanced. I think it should be clarified.<br>
&gt;<br>
&gt; <a href="http://www.pgpool.net/docs/latest/pgpool-en.html" target="_blank">http://www.pgpool.net/docs/latest/pgpool-en.html</a><br>
&gt;<br>
&gt; For a query to be load balanced, all the following requirements must be met:<br>
&gt;<br>
&gt;    - PostgreSQL version 7.4 or later<br>
&gt;    - *the query must not be in an explicitly declared transaction (i.e. not<br>
&gt;    in a BEGIN ~ END block)*<br>
<br>
This is simply wrong. Sorry for the outdated info. I will fix it.<br>
<br>
&gt; So query in explicitly declared transaction will not be balanced. But then<br>
&gt; in the stame doc:<br>
&gt;<br>
&gt; <a href="http://www.pgpool.net/docs/latest/pgpool-en.html" target="_blank">http://www.pgpool.net/docs/latest/pgpool-en.html</a><br>
&gt; In an explicit transaction:Transaction starting commands such as BEGIN are<br>
&gt; sent to the primary node.Following SELECT and some other queries that can<br>
&gt; be sent to both primary or standby are executed in the transaction or on<br>
&gt; the standby node.Commands which cannot be executed on the standby such as<br>
&gt; INSERT are sent to the primary. After one of these commands, even SELECTs<br>
&gt; are sent to the primary node, This is because these SELECTs might want to<br>
&gt; see the result of an INSERT immediately. This behavior continues until the<br>
&gt; transaction closes or aborts.<br>
&gt;<br>
&gt; This states that after any writing in transaction all statements should not<br>
&gt; be balanced. This contradicts first part, which can be understood as if<br>
&gt; transactions are not balanced at all.<br>
<br>
Correct.<br>
<br>
&gt; ср, 22 апр. 2015 г. в 18:24, Tatsuo Ishii &lt;<a href="mailto:ishii@postgresql.org" target="_blank">ishii@postgresql.org</a>&gt;:<br>
&gt;<br>
&gt;&gt; pgpool-II has no idea which is a stored function or not regarding load<br>
&gt;&gt; balancing: all functions are treated as same. So &quot;SELECT upper(&#39;foo&#39;)&quot;<br>
&gt;&gt; is load balanced if white and black function list is empty.<br>
&gt;&gt;<br>
&gt;&gt; BTW if you do not want to load balance particular SELECT, you can add<br>
&gt;&gt; &quot;/*NO LOAD BALANCE*/&quot; to the SELECT statement. See the manual for more<br>
&gt;&gt; details.<br>
&gt;&gt;<br>
&gt;&gt; Best regards,<br>
&gt;&gt; --<br>
&gt;&gt; Tatsuo Ishii<br>
&gt;&gt; SRA OSS, Inc. Japan<br>
&gt;&gt; English: <a href="http://www.sraoss.co.jp/index_en.php" target="_blank">http://www.sraoss.co.jp/index_en.php</a><br>
&gt;&gt; Japanese:<a href="http://www.sraoss.co.jp" target="_blank">http://www.sraoss.co.jp</a><br>
&gt;&gt;<br>
&gt;&gt; &gt; Hi, Lachezar!<br>
&gt;&gt; &gt; The function itself is not balanced, it would fail on read only node<br>
&gt;&gt; &gt; (slave) but it does not (by default stored functions are not balanced<br>
&gt;&gt; even<br>
&gt;&gt; &gt; if they are not explicitly listed in black list). Problem is with next<br>
&gt;&gt; &gt; statement in this transaction, which is select. And we want this select<br>
&gt;&gt; to<br>
&gt;&gt; &gt; be run on master.<br>
&gt;&gt; &gt; And looking in documentation I think it should be run on master.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; вт, 21 апр. 2015 г. в 18:26, Lachezar Dobrev &lt;<a href="mailto:l.dobrev@gmail.com" target="_blank">l.dobrev@gmail.com</a>&gt;:<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt;   Non-authority response:<br>
&gt;&gt; &gt;&gt;   You might want to use a white-list[1] or black-list[2] of functions<br>
&gt;&gt; &gt;&gt; to inform the PgPool which functions are suitable for distributing, or<br>
&gt;&gt; &gt;&gt; which are not suitable. Documentation specifies that you can use<br>
&gt;&gt; &gt;&gt; either, but not both. I suppose adding your functions to the<br>
&gt;&gt; &gt;&gt; black_function_list would be easier. Not sure if that will help<br>
&gt;&gt; &gt;&gt; though. My understanding was, that everything in a transaction (BEGIN;<br>
&gt;&gt; &gt;&gt; /* EVERYTHING; */ END;) would be sent to the master.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;   [1]<br>
&gt;&gt; <a href="http://www.pgpool.net/docs/latest/pgpool-en.html#WHITE_FUNCTION_LIST" target="_blank">http://www.pgpool.net/docs/latest/pgpool-en.html#WHITE_FUNCTION_LIST</a><br>
&gt;&gt; &gt;&gt;   [2]<br>
&gt;&gt; <a href="http://www.pgpool.net/docs/latest/pgpool-en.html#BLACK_FUNCTION_LIST" target="_blank">http://www.pgpool.net/docs/latest/pgpool-en.html#BLACK_FUNCTION_LIST</a><br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; 2015-04-21 5:55 GMT+03:00 Сергей Мелехин &lt;<a href="mailto:cpro29a@gmail.com" target="_blank">cpro29a@gmail.com</a>&gt;:<br>
&gt;&gt; &gt;&gt; &gt; There is another part in docs:<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; <a href="http://www.pgpool.net/docs/latest/pgpool-en.html" target="_blank">http://www.pgpool.net/docs/latest/pgpool-en.html</a><br>
&gt;&gt; &gt;&gt; &gt; In an explicit transaction:Transaction starting commands such as BEGIN<br>
&gt;&gt; &gt;&gt; are<br>
&gt;&gt; &gt;&gt; &gt; sent to the primary node.Following SELECT and some other queries that<br>
&gt;&gt; &gt;&gt; can be<br>
&gt;&gt; &gt;&gt; &gt; sent to both primary or standby are executed in the transaction or on<br>
&gt;&gt; the<br>
&gt;&gt; &gt;&gt; &gt; standby node.Commands which cannot be executed on the standby such as<br>
&gt;&gt; &gt;&gt; INSERT<br>
&gt;&gt; &gt;&gt; &gt; are sent to the primary. After one of these commands, even SELECTs are<br>
&gt;&gt; &gt;&gt; sent<br>
&gt;&gt; &gt;&gt; &gt; to the primary node, This is because these SELECTs might want to see<br>
&gt;&gt; the<br>
&gt;&gt; &gt;&gt; &gt; result of an INSERT immediately. This behavior continues until the<br>
&gt;&gt; &gt;&gt; &gt; transaction closes or aborts.<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; It looks like pgpool treats all stored functions as non writing in<br>
&gt;&gt; this<br>
&gt;&gt; &gt;&gt; &gt; scenario.<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; вт, 21 апр. 2015 г. в 12:05, Сергей Мелехин &lt;<a href="mailto:cpro29a@gmail.com" target="_blank">cpro29a@gmail.com</a>&gt;:<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt;&gt; Hi!<br>
&gt;&gt; &gt;&gt; &gt;&gt; Our test server is relatively slow, and there are some lags in<br>
&gt;&gt; &gt;&gt; replication<br>
&gt;&gt; &gt;&gt; &gt;&gt; between master and slave sometimes. We are using pgpool 3.3.4 in load<br>
&gt;&gt; &gt;&gt; &gt;&gt; balancing mode to mimic our production environment.<br>
&gt;&gt; &gt;&gt; &gt;&gt; Some unit tests are making some changes in database (calling stored<br>
&gt;&gt; &gt;&gt; &gt;&gt; functions) and immediately check them issuing select queries.<br>
&gt;&gt; Sometimes<br>
&gt;&gt; &gt;&gt; they<br>
&gt;&gt; &gt;&gt; &gt;&gt; fail not finding records they have just inserted.<br>
&gt;&gt; &gt;&gt; &gt;&gt; Judging by this verse in documentation:<br>
&gt;&gt; &gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; &gt;&gt; For a query to be load balanced, all the following requirements must<br>
&gt;&gt; be<br>
&gt;&gt; &gt;&gt; &gt;&gt; met:<br>
&gt;&gt; &gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; &gt;&gt; PostgreSQL version 7.4 or later<br>
&gt;&gt; &gt;&gt; &gt;&gt; the query must not be in an explicitly declared transaction (i.e. not<br>
&gt;&gt; &gt;&gt; in a<br>
&gt;&gt; &gt;&gt; &gt;&gt; BEGIN ~ END block)<br>
&gt;&gt; &gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; &gt;&gt; we decided that putting whole test in transaction block will avoid<br>
&gt;&gt; load<br>
&gt;&gt; &gt;&gt; &gt;&gt; balancing for such test, but it looks like that no matter being in<br>
&gt;&gt; &gt;&gt; &gt;&gt; transaction, selects are replicated to slave and dont find desired<br>
&gt;&gt; data<br>
&gt;&gt; &gt;&gt; &gt;&gt; because of replication lags. This errors are present when we use<br>
&gt;&gt; stored<br>
&gt;&gt; &gt;&gt; &gt;&gt; functions, when we use explicit DML, selects inside transaction are<br>
&gt;&gt; not<br>
&gt;&gt; &gt;&gt; &gt;&gt; replicated. Function names are not included in white or black list in<br>
&gt;&gt; &gt;&gt; &gt;&gt; pgpool.conf.<br>
&gt;&gt; &gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; &gt;&gt; Is it normal behaviour, or is it a bug?<br>
&gt;&gt; &gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; &gt;&gt; I include simple test, it fails in our slow replication environment.<br>
&gt;&gt; &gt;&gt; &gt;&gt; You&#39;ll need python3 and psycopg2 to run it. And there is db<br>
&gt;&gt; connection<br>
&gt;&gt; &gt;&gt; &gt;&gt; string constant &quot;DB&quot; in the beginning of script you&#39;ll have to<br>
&gt;&gt; change.<br>
&gt;&gt; &gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; &gt;&gt; Thank you for your work!<br>
&gt;&gt; &gt;&gt; &gt;&gt; Sergey Melekhin<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; _______________________________________________<br>
&gt;&gt; &gt;&gt; &gt; pgpool-general mailing list<br>
&gt;&gt; &gt;&gt; &gt; <a href="mailto:pgpool-general@pgpool.net" target="_blank">pgpool-general@pgpool.net</a><br>
&gt;&gt; &gt;&gt; &gt; <a href="http://www.pgpool.net/mailman/listinfo/pgpool-general" target="_blank">http://www.pgpool.net/mailman/listinfo/pgpool-general</a><br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt;<br>
</blockquote></div></div></div>