[Ilugc] CGI and PgSQL

  • From: km@xxxxxxxxxxxxxx (km)
  • Date: Thu Jan 11 19:12:09 2007

On Thu, Jan 11, 2007 at 07:00:15PM +0530, Bharathi Subramanian wrote:

Hi All,

We have written an CGI Program in C + libpq. In that, whenever a req
is received, we will do,

1. Connect to PgSQL
2. Exec the Query
3. Return the result

This above steps takes nearly 8ms. 4ms to Connect to PgSQL and 4ms for
other steps. We like to avoid doing the 1st step every time, by
keeping the PgSQL connection alive. Any tips to do this?

Apache v2.0
PgSQL v7.4.6

Well i use a python variant for such stuff - have psycopg2 python module 
installed.

import psycopg2
conn = psycopg2.connect("dbname=mydb user=bla ...")
cur = conn.cursor()
cur.execute('SELECT .....;')
<as before .. do several SQL query executions using cursor (cur) as before>
conn.commit()
conn.close()

regards,
KM

Other related posts: