<div dir="ltr">Because it is quite elaborate explanation, it might not be a good fit for docs, which are supposed to be concise. Probably it should reside somewhere in wiki and the docs for max_pool should link there. But don&#39;t mind me if you think these can fit right in the docs.<br>

<br><div class="gmail_quote">On Wed, Aug 22, 2012 at 7:06 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">Great explanation. I would like to add this to somewhere in the document.<br>
Thanks!<br>
--<br>
Tatsuo Ishii<br>
SRA OSS, Inc. Japan<br>
English: <a href="http://www.sraoss.co.jp/index_en.php" target="_blank">http://www.sraoss.co.jp/index_en.php</a><br>
Japanese: <a href="http://www.sraoss.co.jp" target="_blank">http://www.sraoss.co.jp</a><br>
<div><div><br>
&gt; Hi Hackers,<br>
&gt;<br>
&gt;     I have answered max_pool related question a few times, and more than<br>
&gt; once the following explanation cleared up the other party&#39;s confusion just<br>
&gt; y reading it, without any more explanation from me. Do you think this<br>
&gt; deserves some place on pgpool docs?<br>
&gt;<br>
&gt;     max_pool parameter configures how many connections to cache _per<br>
&gt; child_. So if num_init_children is configured to 100, and max_pool is<br>
&gt; configured to 3, then pgpool can potentially open 300 (=3*100) connections<br>
&gt; to the backend database.<br>
&gt;<br>
&gt;     A child process opens a new backend connection only if the requested<br>
&gt; [user,database] pair is not already in the cache. So if the application<br>
&gt; uses only one user to connect to only one database, say [pguser1,pgdb1],<br>
&gt; then each child will continue to reuse the first connection and will never<br>
&gt; open a second connection, so in effect pgpool will open no more than 100<br>
&gt; backend connections even though max_pool is set to 3.<br>
&gt;<br>
&gt;     But if the application uses more than one pair of [user,database]<br>
&gt; connection parameters, then each child will cache the connection it might<br>
&gt; already have for another pair, and open a new backend connection for the<br>
&gt; requested pair.<br>
&gt;<br>
&gt;     For eg., if the application now uses these 4 pairs: [user1,db1]<br>
&gt; [user1,db2] [user2,db1] [user2,db2] to connect to pgpool, then each child<br>
&gt; process can cache up to 3 connections for the first 3 different pairs it<br>
&gt; receives connection requests for. But as soon as it receives a request for<br>
&gt; the 4th pair that it does not yet have a connection for, then it will<br>
&gt; disconnect the oldest connection in the cache and open a new connection for<br>
&gt; the 4th pair.<br>
&gt;<br>
&gt;     As we already know that there&#39;s no guarantee as to which child process<br>
&gt; will handle an incoming connection request, max_pool tries to improve the<br>
&gt; performance a little bit by caching connections of different pairs, in the<br>
&gt; hopes that an incoming connection request might match one of the<br>
&gt; connections cached by the child process. But this also causes an explosion<br>
&gt; in the number of connections that pgpool would request from the database.<br>
&gt;<br>
&gt;     So, in order to guarantee that the application connection requests are<br>
&gt; never rejected, and that the connection requests wait until a database<br>
&gt; connection is available, the following condition should be met:<br>
&gt;<br>
&gt; max_pool*num_init_children &lt;= (max_connections -<br>
&gt; superuser_reserved_connections)<br>
&gt;<br>
&gt;     If the application uses superuser connections (which is not<br>
&gt; recommended), then the condition is reduced to:<br>
&gt;<br>
&gt; max_pool*num_init_children &lt;= max_connections<br>
&gt;<br>
&gt;     Setting max_pool to 1 will guarantee that the number of database<br>
&gt; connections opened by pgpool child processes never exceeds the<br>
&gt; num_init_children value. If for performance reasons, as explained above,<br>
&gt; you do wish to set max_pool to more than 1, then max_connections will also<br>
&gt; have to be increased accordingly so that application connection requests do<br>
&gt; not get denied.<br>
&gt;<br>
&gt; Best regards,<br>
&gt; --<br>
&gt; Gurjeet Singh<br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br><div dir="ltr">Gurjeet Singh<br><br></div><br>
</div>