<div dir="ltr">I am using this: <a href="https://www.npmjs.com/package/pg">https://www.npmjs.com/package/pg</a></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, May 30, 2017 at 6:11 PM, Tatsuo Ishii <span dir="ltr">&lt;<a href="mailto:ishii@sraoss.co.jp" target="_blank">ishii@sraoss.co.jp</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">BTW, which PostgreSQL driver are you using? It is possible the author<br>
of the library misunderstand the frontend/backend protocol.<br>
<span class=""><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>
<br>
</span>From: Ankur Jain &lt;<a href="mailto:ankur.jain@obeohealth.com">ankur.jain@obeohealth.com</a>&gt;<br>
Subject: Re: [pgpool-general: 5511] Issue with parameterized query<br>
Date: Tue, 30 May 2017 16:40:12 -0700<br>
Message-ID: &lt;<a href="mailto:CACvFWAq_TkVphnYySJYFRp%2B8JHeQ7L_BYAHyZE7opa7JkVXTyA@mail.gmail.com">CACvFWAq_TkVphnYySJYFRp+<wbr>8JHeQ7L_BYAHyZE7opa7JkVXTyA@<wbr>mail.gmail.com</a>&gt;<br>
<div class="HOEnZb"><div class="h5"><br>
&gt; Hi Tatsuo,<br>
&gt; I just tried the patch on 3.6.4 and it works. Thanks!<br>
&gt; When do you think this will become available in the yum repositories?<br>
&gt; -AJ<br>
&gt;<br>
&gt; On Fri, May 26, 2017 at 1:32 PM, Tatsuo Ishii &lt;<a href="mailto:ishii@sraoss.co.jp">ishii@sraoss.co.jp</a>&gt; wrote:<br>
&gt;<br>
&gt;&gt; I think I found the cause of the problem.<br>
&gt;&gt; It seems node.js sends a query in following pattern:<br>
&gt;&gt;<br>
&gt;&gt; Parse<br>
&gt;&gt; Bind<br>
&gt;&gt; Describe<br>
&gt;&gt; Execute<br>
&gt;&gt; Flush<br>
&gt;&gt; Sync<br>
&gt;&gt;<br>
&gt;&gt; The &quot;Flush&quot; message is actually unnecessary: it just requests backend<br>
&gt;&gt; (in this case Pgpool-II) to send any result pending in the<br>
&gt;&gt; backend. However, which will be accomplished by the subsequent &quot;Sync&quot;<br>
&gt;&gt; message. So the Flush message is completely redundant here.<br>
&gt;&gt;<br>
&gt;&gt; Anyway, the pattern is not supposed in Pgpool-II.<br>
&gt;&gt; Can you please try the attached fix?<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" rel="noreferrer" target="_blank">http://www.sraoss.co.jp/index_<wbr>en.php</a><br>
&gt;&gt; Japanese:<a href="http://www.sraoss.co.jp" rel="noreferrer" target="_blank">http://www.sraoss.co.<wbr>jp</a><br>
&gt;&gt;<br>
&gt;&gt; &gt; Hi Tatsuo,<br>
&gt;&gt; &gt; Thanks for looking into it, I am just coping you and my team-mates<br>
&gt;&gt; instead<br>
&gt;&gt; &gt; of spamming the whole group.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; I have attached more details, hopefully this helps you. I have attached a<br>
&gt;&gt; &gt; node.js script (*pgpool_test.js.txt, *I had to add a .txt extension<br>
&gt;&gt; because<br>
&gt;&gt; &gt; gmail would not allow me to attach a file with a .js extension) which<br>
&gt;&gt; &gt; creates a table* public.test *with just one column (id) and one row<br>
&gt;&gt; (id=1).<br>
&gt;&gt; &gt; It then runs &quot;select  * from public.test where id=1&quot; twice using a<br>
&gt;&gt; &gt; non-parametrized query and then again twice using a parameterized query.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;  As you can see in *output.log*, the table creation and the first two non<br>
&gt;&gt; &gt; parametrized queries run fine. The first parameterized query also runs<br>
&gt;&gt; fine<br>
&gt;&gt; &gt; (because it wasn&#39;t cached). The second parametrized query never returns<br>
&gt;&gt; and<br>
&gt;&gt; &gt; node script just hangs.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; I am also attaching the pgpool output log (*pgpool.log*) and the tcp<br>
&gt;&gt; packet<br>
&gt;&gt; &gt; capture (*dump.out*, viewable in wireshark) that captured all the tcp<br>
&gt;&gt; &gt; traffic between the client and the machine running pgpool. Let me know if<br>
&gt;&gt; &gt; you need anything else.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; -AJ<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; If you want to run the node.js script yourself, here are the instructions<br>
&gt;&gt; &gt; to do that (on a linux machine)<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;    - Install node (the instructions would be machine specific)<br>
&gt;&gt; &gt;    - npm install pg<br>
&gt;&gt; &gt;    - npm install seq<br>
&gt;&gt; &gt;    - PGPORT=&lt;PGPOOL_PORT&gt; PGDATABASE=&lt;DATABASE_NAME&gt;<br>
&gt;&gt; PGHOST=&lt;PH_HOST_NAME&gt;<br>
&gt;&gt; &gt;    PGUSER=&lt;PG_USERNAME&gt; node  pgpool_test.js<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; On Fri, May 19, 2017 at 12:30 AM, Tatsuo Ishii &lt;<a href="mailto:ishii@sraoss.co.jp">ishii@sraoss.co.jp</a>&gt;<br>
&gt;&gt; wrote:<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; Hi,<br>
&gt;&gt; &gt;&gt; &gt; I am having an issue with using parameterized queries with pgpool. My<br>
&gt;&gt; &gt;&gt; setup<br>
&gt;&gt; &gt;&gt; &gt; involves using node.js client with pgpool (3.6.4) and postgresl 9.6.<br>
&gt;&gt; I am<br>
&gt;&gt; &gt;&gt; &gt; using pgpool just for caching using shmem.<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; I have a simple example with the following query &quot;SELECT * FROM<br>
&gt;&gt; &gt;&gt; &gt; master.employer where employer_id=$1&quot;.  The query returns fine the<br>
&gt;&gt; first<br>
&gt;&gt; &gt;&gt; &gt; time and then it gets cached. When I run it again it hits the cache,<br>
&gt;&gt; but<br>
&gt;&gt; &gt;&gt; &gt; returns an empty resultset.<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; Let me know if I can provide with any other details. I have attached<br>
&gt;&gt; the<br>
&gt;&gt; &gt;&gt; &gt; entire pgpool log.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; In the log I see:<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; 2017-05-18 21:13:30: pid 22781: DEBUG:  memcache: sending cached<br>
&gt;&gt; messages:<br>
&gt;&gt; &gt;&gt; &#39;D&#39; len: 4917<br>
&gt;&gt; &gt;&gt; 2017-05-18 21:13:30: pid 22781: DEBUG:  memcache: sending cached<br>
&gt;&gt; messages:<br>
&gt;&gt; &gt;&gt; &#39;C&#39; len: 13<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; which means first Pgpool-II sends &#39;D&#39; (actual row data) in 4917 bytes<br>
&gt;&gt; &gt;&gt; then &#39;C&#39; (Indicating select command completed). This is perfectly sane<br>
&gt;&gt; &gt;&gt; from the protocol&#39;s point of view. So as far as the log says,<br>
&gt;&gt; &gt;&gt; Pgpool-II successfully returns cached data to client. So the remaining<br>
&gt;&gt; &gt;&gt; possibility is the returned data is broken. I don&#39;t what kind of debug<br>
&gt;&gt; &gt;&gt; method node.js has, but is it possible to capture/dump the packet data<br>
&gt;&gt; &gt;&gt; using wireshark?<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Best regards,<br>
&gt;&gt; &gt;&gt; --<br>
&gt;&gt; &gt;&gt; Tatsuo Ishii<br>
&gt;&gt; &gt;&gt; SRA OSS, Inc. Japan<br>
&gt;&gt; &gt;&gt; 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>
&gt;&gt; &gt;&gt; Japanese:<a href="http://www.sraoss.co.jp" rel="noreferrer" target="_blank">http://www.sraoss.co.<wbr>jp</a><br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; diff --git a/src/query_cache/pool_<wbr>memqcache.c b/src/query_cache/pool_<br>
&gt;&gt; memqcache.c<br>
&gt;&gt; index fdef8c1..b8a5a5a 100644<br>
&gt;&gt; --- a/src/query_cache/pool_<wbr>memqcache.c<br>
&gt;&gt; +++ b/src/query_cache/pool_<wbr>memqcache.c<br>
&gt;&gt; @@ -645,43 +645,9 @@ POOL_STATUS pool_fetch_from_memory_cache(<wbr>POOL_CONNECTION<br>
&gt;&gt; *frontend,<br>
&gt;&gt;         pfree(qcache);<br>
&gt;&gt;<br>
&gt;&gt;         /*<br>
&gt;&gt; -        * If we are doing extended query, forward sync message from<br>
&gt;&gt; frontend to<br>
&gt;&gt; -        * backend. This is necessary to prevent receiving Sync message<br>
&gt;&gt; after<br>
&gt;&gt; -        * Sending Ready for query.<br>
&gt;&gt; +        * Send a &quot;READY FOR QUERY&quot; if not in extended query.<br>
&gt;&gt;          */<br>
&gt;&gt; -       if (pool_is_doing_extended_query_<wbr>message())<br>
&gt;&gt; -       {<br>
&gt;&gt; -               char kind;<br>
&gt;&gt; -               int32 len;<br>
&gt;&gt; -               POOL_SESSION_CONTEXT *session_context;<br>
&gt;&gt; -               POOL_CONNECTION *target_backend;<br>
&gt;&gt; -               char buf[5];<br>
&gt;&gt; -<br>
&gt;&gt; -               if (pool_flush(frontend))<br>
&gt;&gt; -                       return POOL_END;<br>
&gt;&gt; -               if (pool_read(frontend, &amp;kind, 1))<br>
&gt;&gt; -                       return POOL_END;<br>
&gt;&gt; -<br>
&gt;&gt; -               ereport(DEBUG2,<br>
&gt;&gt; -                               (errmsg(&quot;memcache: fetching from memory<br>
&gt;&gt; cache: expecting sync: kind &#39;%c&#39;&quot;, kind)));<br>
&gt;&gt; -               if (pool_read(frontend, &amp;len, sizeof(len)))<br>
&gt;&gt; -                       return POOL_END;<br>
&gt;&gt; -<br>
&gt;&gt; -               /* Forward &quot;Sync&quot; message to backend */<br>
&gt;&gt; -               session_context = pool_get_session_context(true)<wbr>;<br>
&gt;&gt; -               target_backend = CONNECTION(backend,<br>
&gt;&gt; session_context-&gt;load_balance_<wbr>node_id);<br>
&gt;&gt; -               pool_write(target_backend, &amp;kind, 1);<br>
&gt;&gt; -               pool_write_and_flush(target_<wbr>backend, &amp;len, sizeof(len));<br>
&gt;&gt; -<br>
&gt;&gt; -               /* Read and discard &quot;Ready for query&quot; message from backend<br>
&gt;&gt; */<br>
&gt;&gt; -               pool_read(target_backend, &amp;kind, 1);<br>
&gt;&gt; -               pool_read(target_backend, buf, sizeof(buf));<br>
&gt;&gt; -       }<br>
&gt;&gt; -<br>
&gt;&gt; -       /*<br>
&gt;&gt; -        * send a &quot;READY FOR QUERY&quot;<br>
&gt;&gt; -        */<br>
&gt;&gt; -       if (MAJOR(backend) == PROTO_MAJOR_V3)<br>
&gt;&gt; +       if (!pool_is_doing_extended_<wbr>query_message() &amp;&amp; MAJOR(backend) ==<br>
&gt;&gt; PROTO_MAJOR_V3)<br>
&gt;&gt;         {<br>
&gt;&gt;                 signed char state;<br>
&gt;&gt;<br>
&gt;&gt; @@ -691,10 +657,7 @@ POOL_STATUS pool_fetch_from_memory_cache(<wbr>POOL_CONNECTION<br>
&gt;&gt; *frontend,<br>
&gt;&gt;                 state = MASTER(backend)-&gt;tstate;<br>
&gt;&gt;                 send_message(frontend, &#39;Z&#39;, 5, (char *)&amp;state);<br>
&gt;&gt;         }<br>
&gt;&gt; -       else<br>
&gt;&gt; -       {<br>
&gt;&gt; -               pool_write(frontend, &quot;Z&quot;, 1);<br>
&gt;&gt; -       }<br>
&gt;&gt; +<br>
&gt;&gt;         if (pool_flush(frontend))<br>
&gt;&gt;         {<br>
&gt;&gt;                 return POOL_END;<br>
&gt;&gt;<br>
&gt;&gt;<br>
</div></div></blockquote></div><br></div>