X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 3B0829FA4C1 for ; Fri, 16 Jun 2006 17:20:08 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 79202-09 for ; Fri, 16 Jun 2006 17:19:58 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from peufeu.com (boutiquenumerique.com [82.67.9.10]) by postgresql.org (Postfix) with ESMTP id 2741A9FA10A for ; Fri, 16 Jun 2006 17:19:57 -0300 (ADT) Received: (qmail 23135 invoked from network); 16 Jun 2006 22:21:09 +0200 Received: from boutiquenumerique.com (HELO apollo13) (82.67.9.10) by boutiquenumerique.com with SMTP; 16 Jun 2006 22:21:09 +0200 Date: Fri, 16 Jun 2006 22:21:06 +0200 To: "John DeSoi" , "chester c young" Subject: Re: sessions and prepared statements Cc: pgsql-sql@postgresql.org References: <20060615154930.44620.qmail@web54312.mail.yahoo.com> <4B156402-1B7D-46E2-8A4F-9DBD3F119CB7@pgedit.com> From: PFC Content-Type: text/plain; format=flowed; delsp=yes; charset=utf-8 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID: In-Reply-To: <4B156402-1B7D-46E2-8A4F-9DBD3F119CB7@pgedit.com> User-Agent: Opera M2/8.54 (Linux, build 1745) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/216 X-Sequence-Number: 25452 >> in PHP for example, where there are multiple sessions and which you get >> is random: >> >> how do you know if the session you're in has prepared a particular >> statement? >> >> and/or how do you get a list of prepared statements? >> >> last, is there any after login trigger that one could use to prepare >> statements the session would need? or is this a dumb idea? Ahem, if you're concerned about performance, you probably... - don't really use PHP ? Or at least use eaccelerator or some form of compiled code caching ? - use a lighttpd with php running as a fastcgi process ? The second option ensures that the PHP code execution is less likely to be interrupted by a client disconnection ; however it can still crash or exceed the time or memory limit. Thus, when using the persistent connections of PHP : - use pg_pconnect to connect, this will give you a connection from a pool - Make sure the connection does not contain a pending transaction, by chosing one of these options : - Trust the PHP designers (ahem) - Issue a ROLLBACK as your first query - register_shutdown_function( 'pg_query', 'ROLLBACK' ); This issues a ROLLBACK as the last query even if your script is interrupted, but not if the PHP interpreter crashes (happens...). As for preparing the statements only once, I would do the following : Have a SQL script which prepares all statements, creates temp tables etc, and whose last command is : PREPARE connection_status_test AS SELECT 1; Then, you can start your script by EXECUTE connection_status_test; if it fails complaining that the prepared statement is not found, execute the SQL script ; else resume normal operations.