>> 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
someform of
compiled code caching ?- use a lighttpd with php running as a fastcgi process ?The second option ensures that the PHP
codeexecution 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.