<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">2018-04-13 13:16 GMT+09:00 Tatsuo Ishii <span dir="ltr">&lt;<a href="mailto:ishii@sraoss.co.jp" target="_blank">ishii@sraoss.co.jp</a>&gt;</span>:<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; Hello,<br>
&gt; <br>
&gt; At first, I&#39;m sorry I&#39;m not good at English.<br>
&gt; <br>
&gt; <br>
&gt; I&#39;d installed Pgpool 3.7.2 and two Postgres 10.3 instances, and configure a<br>
&gt; master-slave mode cluster. I turned on also load_balancing_mode.<br>
&gt; <br>
&gt; When I was testing and looking into logs, I found that pgpool sent backend0<br>
&gt; several extray queries &quot;SELECT count(*) ...&quot; for every simple select query:<br>
&gt; <br>
&gt; <br>
&gt; # what I did: (23140 is pgpool port)<br>
&gt; $ psql -h 127.0.0.1 -p 23140 -U postgres test -c &quot;select * from mytable;&quot;<br>
&gt; <br>
&gt; <br>
&gt; # what the pgpool log showed (timestamp omitted)<br>
&gt; pid 1583: LOG:  DB node id: 0 backend pid: 469 statement: SELECT count(*)<br>
&gt; from (SELECT has_function_privilege(&#39;<wbr>postgres&#39;, &#39;to_regclass(cstring)&#39;,<br>
&gt; &#39;execute&#39;) WHERE EXISTS(SELECT * FROM pg_catalog.pg_proc AS p WHERE<br>
&gt; p.proname = &#39;to_regclass&#39;)) AS s<br>
&gt; <br>
&gt; pid 1583: LOG:  DB node id: 0 backend pid: 469 statement: SELECT count(*)<br>
&gt; FROM pg_catalog.pg_class AS c WHERE c.relname = &#39;pg_namespace&#39;<br>
&gt; <br>
&gt; pid 1583: LOG:  DB node id: 0 backend pid: 469 statement: SELECT count(*)<br>
&gt; FROM pg_class AS c, pg_namespace AS n WHERE c.oid =<br>
&gt; to_regclass(&#39;&quot;mytable&quot;&#39;) AND c.relnamespace = n.oid AND n.nspname =<br>
&gt; &#39;pg_catalog&#39;<br>
&gt; <br>
&gt; pid 1583: LOG:  DB node id: 0 backend pid: 469 statement: SELECT count(*)<br>
&gt; FROM pg_catalog.pg_class AS c, pg_attribute AS a WHERE c.relname =<br>
&gt; &#39;pg_class&#39; AND a.attrelid = c.oid AND a.attname = &#39;relistemp&#39;<br>
&gt; <br>
&gt; pid 1583: LOG:  DB node id: 0 backend pid: 469 statement: SELECT count(*)<br>
&gt; FROM pg_class AS c, pg_namespace AS n WHERE c.relname = &#39;mytable&#39; AND<br>
&gt; c.relnamespace = n.oid AND n.nspname ~ &#39;^pg_temp_&#39;<br>
&gt; <br>
&gt; pid 1583: LOG:  DB node id: 0 backend pid: 469 statement: SELECT count(*)<br>
&gt; FROM pg_catalog.pg_class AS c, pg_catalog.pg_attribute AS a WHERE c.relname<br>
&gt; = &#39;pg_class&#39; AND a.attrelid = c.oid AND a.attname = &#39;relpersistence&#39;<br>
&gt; <br>
&gt; pid 1583: LOG:  DB node id: 0 backend pid: 469 statement: SELECT count(*)<br>
&gt; FROM pg_catalog.pg_class AS c WHERE c.oid = to_regclass(&#39;&quot;mytable&quot;&#39;) AND<br>
&gt; c.relpersistence = &#39;u&#39;<br>
&gt; <br>
&gt; pid 1583: LOG:  DB node id: 1 backend pid: 2312 statement: select * from<br>
&gt; mytable;<br>
&gt; <br>
&gt; <br>
&gt; I tried more cases and observed:<br>
&gt; 1) INSERT and UPDATE queries do not make these extra queries. Only SELECT<br>
&gt; query does.<br>
&gt; <br>
&gt; 2) The extra queries were always sent to backend#0, regardless of whether<br>
&gt; it was primary or standby.<br>
&gt; <br>
&gt; <br>
&gt; I&#39;d like to ask:<br>
&gt; 1) Is this a normal operation or some signal that something is wrong?<br>
<br>
</div></div>Yes. SELECTs issues queries against PostgreSQL system catalogs to know<br>
if the table is a temporary table or not etc.<br>
<span class=""><br>
&gt; 2) If it is a ordinary operation, is it ok? I mean, couldn&#39;t it be too much<br>
&gt; overhead, if 7 more queries are sent for every 1 &quot;SELECT&quot; query?<br>
<br>
</span>Yes. Although for the first time of a SELECT to a table these queries<br>
are issued, the results are cached and for the next SELECT those<br>
extra queries are no longer issued as long as same table is involved.<br>
The cache is maintained in the pgpool child process memory space, that<br>
means as long as the process continues to run, the cache can be used.<br>
<br></blockquote><div><br></div><div>Ooops. I see. </div><div><br></div><div>I was creating new psql instance to send a SELECT query so that I saw so much extra queries.</div><div><br></div><div>In an interactive mode of psql, only the first query issues that extra query.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
The number of default cache entry per pgpool process is defined as<br>
follows in pgpool.conf:<br>
<br>
relcache_size = 256<br>
<br>
If you rarely see &quot;pool_search_relcache: cache replacement happend&quot; in<br>
the pgpool log, then the cache entry size is big enough. If you see<br>
the message too often, try to increase it.<br></blockquote><div><br></div><div>Thank you very much!</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Best regards,<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_<wbr>en.php</a><br>
Japanese:<a href="http://www.sraoss.co.jp" rel="noreferrer" target="_blank">http://www.sraoss.co.<wbr>jp</a><br>
</blockquote></div><br></div><div class="gmail_extra"><br></div><div class="gmail_extra">gypark</div></div>