X-Original-To: pgsql-interfaces-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 1FB2F9DCA39 for ; Tue, 28 Feb 2006 20:18:26 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 48644-06 for ; Tue, 28 Feb 2006 20:18:28 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 1A5F89DCA07 for ; Tue, 28 Feb 2006 20:18:24 -0400 (AST) Received: from mail.utiba.com.au (eth2643.vic.adsl.internode.on.net [150.101.158.82]) by svr4.postgresql.org (Postfix) with ESMTP id 8B8775AF8A0 for ; Wed, 1 Mar 2006 00:18:26 +0000 (GMT) Received: from localhost (scan1.utiba.com.au [127.0.0.1]) by mail.utiba.com.au (Postfix) with ESMTP id 50326440EC; Wed, 1 Mar 2006 11:18:21 +1100 (EST) Received: from mail.utiba.com.au ([127.0.0.1]) by localhost (scan1.utiba.com.au [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 16734-05; Wed, 1 Mar 2006 11:18:17 +1100 (EST) Received: from mail1.utiba.com (ser1 [192.168.0.1]) by mail.utiba.com.au (Postfix) with ESMTP id 12C5F440DE; Wed, 1 Mar 2006 11:18:17 +1100 (EST) Received: from rotate-the-shield-harmonics.utiba.com (localhost [127.0.0.1]) by mail1.utiba.com (Postfix) with ESMTP id 153BB143023; Wed, 1 Mar 2006 11:18:15 +1100 (EST) From: Philip Yarra Organization: Utiba Pty Ltd To: pgsql-interfaces@postgresql.org Subject: Re: multiple threads using one connection Date: Wed, 1 Mar 2006 11:18:13 +1100 User-Agent: KMail/1.7.2 Cc: Bruce Momjian , Alvaro Herrera , Robert Gruszka References: <200602281817.k1SIH7l10966@candle.pha.pa.us> In-Reply-To: <200602281817.k1SIH7l10966@candle.pha.pa.us> X-enigma: Naturally a smoked function is living MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200603011118.14079.philip@utiba.com> X-Utiba-MailScanner-Information: Please contact the Systems Administrator at Utiba for more information X-Utiba-MailScanner: Found to be clean Utiba-MailScanner-MCPCheck: X-MailScanner-From: philip@utiba.com X-Virus-Scanned: amavisd-new at utiba.com.au X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.08 required=5 tests=[AWL=0.080] X-Spam-Score: 0.08 X-Spam-Level: X-Archive-Number: 200602/90 X-Sequence-Number: 6054 On Wed, 1 Mar 2006 05:17 am, Bruce Momjian wrote: > Just to clarify, libpq is thread-safe is each thread uses its own > connection object. Hope it's okay if I clarify this a little further, Bruce... Robert, I think you *should* be able to use the same connection from multiple threads so long as you do your own work to avoid concurrent use of the connection. I'm sorry, I know less than nothing about Ada, but in C terms you'd be using a mutex, acquiring it before your thread issues a statement on the connection, reading back all data etc., then releasing the mutex. Other threads can then acquire the mutex and use the connection. I assume Ada provides some similar sort of concurrency control. On a side note, the preferred way is to use a connection per thread... and given the overhead of thread creation, ISTM the cost of a connection wouldn't be that high... but I assume you have some good reason for doing it this way. I suppose a connection pool might be another way you could handle this requirement. I say it *should* work because I know this works with ECPG, and AFAIK it uses libpq calls, so should be similar for your language binding, but please test it with a sample app before assuming that I know what I'm talking about. Can someone correct me if I have this wrong? It's been a while since I had to think about this stuff... Regards, Philip. -- "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." - Brian W. Kernighan ----------------- Utiba Pty Ltd This message has been scanned for viruses and dangerous content by Utiba mail server and is believed to be clean.