Executing prepared statements in the multithreaded envs

From: Ruslan R(dot) Laishev <zator(at)yandex(dot)ru>
To: pgsql-novice <pgsql-novice(at)postgresql(dot)org>
Subject: Executing prepared statements in the multithreaded envs
Date: 2017-10-17 14:00:44
Message-ID: 344601508248844@web36g.yandex.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

<div><span style="font-family:courier new,monospace;">Hi All!</span></div><div> </div><div><span style="font-family:courier new,monospace;">I'd like to use a pool of connections in multi-threaded environment, so:</span></div><div> </div><div><span style="font-family:courier new,monospace;">1. I created a pool of N-connection by calling PQconnectdb().</span></div><div><span style="font-family:courier new,monospace;">2. Do I'm need to calling PQprepare() for the every sql_query for the every connection from the pool ?</span></div><div> </div><div><span style="font-family:courier new,monospace;">#define POOLSZ 3</span></div><div><span style="font-family:courier new,monospace;">PGconn pool[POOLSZ];</span></div><div> </div><div><span style="font-family:courier new,monospace;">#define QUERYSZ 2</span></div><div><span style="font-family:courier new,monospace;">const char SQL_Qry_name [QUERYSZ][32] = { {"add_pdp11"}, {"add_mvax2"} };</span></div><div><span style="font-family:courier new,monospace;">const char SQL_Qry_expr [QUERYSZ][128] = { {"select add_pdp11($1, $1, $3);"}, {"select add_mvax2($1, $1, $3, $4, $5);" } };</span></div><div> </div><div><span style="font-family:courier new,monospace;">/* Create connections pool ... */</span></div><div><div><span style="font-family:courier new,monospace;">for (i = 0; i &lt; POOLSZ; i++)</span></div><div><span style="font-family:courier new,monospace;">pool[i] = PGconnectdb(...);</span></div><div> </div><div><span style="font-family:courier new,monospace;">/* Prepare every SQL expression in the every session */</span></div></div><div><span style="font-family:courier new,monospace;">for (i = 0; i &lt; POOLSZ; i++)</span></div><div><span style="font-family:courier new,monospace;">for (j = 0; j &lt; QUERYSZ; i++)</span></div><div><span style="font-family:courier new,monospace;">PQrepare(SQL_Qry_name[j], SQL_Qry_expr[j], ...);</span></div><div> </div><div> </div><div> </div><div><span style="font-family:courier new,monospace;">So, do I running in the right direction ?</span></div><div> </div><div><span style="font-family:courier new,monospace;">-- </span></div><div><span style="font-family:courier new,monospace;">С уважением,<br />Ruslan R. Laishev</span></div><div><span style="font-family:courier new,monospace;">OpenVMS bigot, natural born system/network progger, C contractor.</span></div><div><span style="font-family:courier new,monospace;">+79013163222</span></div><div><span style="font-family:courier new,monospace;">+79910009922</span></div><div> </div>

Attachment Content-Type Size
unknown_filename text/html 2.5 KB

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message David G. Johnston 2017-10-17 14:09:13 Re: Executing prepared statements in the multithreaded envs
Previous Message Gerald Cheves 2017-10-17 05:31:48 Re: The server does not listen