Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id CB59C633394 for ; Tue, 27 Oct 2009 07:11:05 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 71321-02 for ; Tue, 27 Oct 2009 10:10:48 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.postnewspapers.com.au (202-89-185-120.static.dsl.amnet.net.au [202.89.185.120]) by mail.postgresql.org (Postfix) with ESMTP id 0ED1663350E for ; Tue, 27 Oct 2009 07:10:51 -0300 (ADT) Received: from localhost (access [127.0.0.1]) by mail.postnewspapers.com.au (Postfix) with ESMTP id 1A3861E0448; Tue, 27 Oct 2009 18:10:47 +0800 (WST) X-Virus-Scanned: Debian amavisd-new at postnewspapers.com.au Received: from mail.postnewspapers.com.au ([127.0.0.1]) by localhost (access.postnewspapers.com.au [127.0.0.1]) (amavisd-new, port 10024) with LMTP id ct28x3vcmsZb; Tue, 27 Oct 2009 18:10:44 +0800 (WST) Received: from [10.1.1.6] (124-169-36-119.dyn.iinet.net.au [124.169.36.119]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "Craig Ringer", Issuer "POST Certificate Authority" (verified OK)) by mail.postnewspapers.com.au (Postfix) with ESMTPSA id 1282D1E0442; Tue, 27 Oct 2009 18:10:44 +0800 (WST) Message-ID: <4AE6C723.105@postnewspapers.com.au> Date: Tue, 27 Oct 2009 18:10:43 +0800 From: Craig Ringer User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.1.1) Gecko/20090715 Thunderbird/3.0b3 MIME-Version: 1.0 To: Raimon Fernandez CC: pgsql-general@postgresql.org Subject: Re: Implementing Frontend/Backend Protocol TCP/IP References: <92781008-8A70-42CE-A49B-6EE67103FACB@montx.com> <20091026231516.GN8812@alvh.no-ip.org> <4AE62E21.7040600@hogranch.com> In-Reply-To: X-Enigmail-Version: 0.97a Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.393 tagged_above=-10 required=5 tests=AWL=0.206, BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200910/1019 X-Sequence-Number: 154713 On 27/10/2009 3:20 PM, Raimon Fernandez wrote: > REALbasic has plugin for PostgreSQL, but they are synchronous and > freeze the GUI when interacting with PG. This is not a problem noramlly, > as the SELECTS/UPDATES/... are fast enopugh, but sometimes we need to > fetch 1000, 5000 or more rows and the application stops to respond, I > can't have a progressbar because all is freeze, until all data has come > from PG, so we need a better way. You're tackling a pretty big project given the problem you're trying to solve. The ongoing maintenance burden is likely to be significant. I'd be really, REALLY surprised if it was worth it in the long run. Can you not do the Pg operations in another thread? libpq is safe to use in a multi-threaded program so long as you never try to share a connection, result set, etc between threads. In most cases, you never want to use any of libpq outside one "database worker" thread, in which case it's dead safe. You can have your worker thread raise flags / post events / whatever to notify the main thread when it's done some work. If that approach isn't palatable to you or isn't suitable in your environment, another option is to just use a cursor. If you have a big fetch to do, instead of: SELECT * FROM customer; issue: BEGIN; DECLARE customer_curs CURSOR FOR SELECT * FROM customer; ... then progressively FETCH blocks of results from the cursor: FETCH 100 FROM customer_curs; ... until there's nothing left and you can close the transaction or, if you want to keep using the transaction, just close the cursor. See: http://www.postgresql.org/docs/8.4/static/sql-declare.html http://www.postgresql.org/docs/8.4/static/sql-fetch.html http://www.postgresql.org/docs/8.4/static/sql-close.html -- Craig Ringer