Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 3851047664D for ; Tue, 21 Jan 2003 15:17:30 -0500 (EST) Received: from stubee.d2hosting.net (d2hosting.net [66.70.41.160]) by postgresql.org (Postfix) with ESMTP id 4E25C475BD7 for ; Tue, 21 Jan 2003 15:17:08 -0500 (EST) Received: from firewall.oxford.d2interactive.com (firewall.oxford.d2interactive.com [68.16.167.2]) by stubee.d2hosting.net (8.11.6/linuxconf) with ESMTP id h0LKGCG28863; Tue, 21 Jan 2003 14:16:12 -0600 Received: from idigx.com (host128.oxford.d2interactive.com [192.168.0.128]) by firewall.oxford.d2interactive.com (8.11.6/linuxconf) with ESMTP id h0LKFtP06532; Tue, 21 Jan 2003 14:16:11 -0600 Message-ID: <3E2DAA7A.60009@idigx.com> Date: Tue, 21 Jan 2003 14:15:54 -0600 From: Thomas Swan User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.2.1) Gecko/20021130 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Raj Mathur Cc: pgsql-admin@postgresql.org Subject: Re: Transactions and HTTP References: <15916.52618.390720.567048@mail.linux-delhi.org> In-Reply-To: <15916.52618.390720.567048@mail.linux-delhi.org> X-Enigmail-Version: 0.71.0.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200301/236 X-Sequence-Number: 7078 Raj Mathur wrote: >Hi, > >Writing a web-based application using PostgreSQL as the back-end >database. The master create functions look something like this: > >1. Accept ID from user. > >2. Verify that ID doesn't exist in database. Start transaction. >Create blank record with ID as key. > >3. Accept remaining data for record from user. > >4. Enter data into newly-created blank record. End transaction. > >Firstly,is it possible to have a transaction spanning multiple >instances of the CGI/mod_perl invocations? > Not easily. You are not always guaranteed the same httpd process when connecting. HTTP is stateless. >Second, there are issues if the user session terminates for some >reason (e.g. user goes offline after the blank record has been >created, etc.) and I end up with a locked blank record in the >database. Would appreciate pointers to best practises in handling >this paradigm. > It is basically a poor design when using HTTP operations. You are better off using server-side session data to store all the information you will need for the complete database operation and then at your final stage of data entry do the record addtion inside of a transaction (i.e. one POST operation), if you want to rollback on error. This should eliminate your concerns over lost locks and hanging transactions. >Unrelated, but I find at least 3 different interfaces to PostgreSQL >from Perl: DBI, Pg and PgSQL. I'm using Pg at the moment, since that >ships with PgSQL by default with Red Hat, but are there any reasons to >choose one over the other? > >Regards, > >-- Raju > >