Re: sessions and prepared statements

From: PFC <lists(at)peufeu(dot)com>
To: "John DeSoi" <desoi(at)pgedit(dot)com>, "chester c young" <chestercyoung(at)yahoo(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: sessions and prepared statements
Date: 2006-06-16 20:21:06
Message-ID: op.ta89hgofcigqcu@apollo13
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

>> 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.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Jeff Frost 2006-06-17 02:29:31 keeping last 30 entries of a log table
Previous Message Greg Stark 2006-06-16 15:57:13 Re: Repetitive code