X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 53AE09FA2DB for ; Mon, 5 Jun 2006 12:23:11 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 31089-02 for ; Mon, 5 Jun 2006 12:23:01 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from noel.decibel.org (noel.decibel.org [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id 7A9429FA111 for ; Mon, 5 Jun 2006 12:23:00 -0300 (ADT) Received: by noel.decibel.org (Postfix, from userid 1001) id 5453356455; Mon, 5 Jun 2006 10:22:59 -0500 (CDT) Received: (hashcash-sendmail, from uid 1001); Mon, 5 Jun 2006 10:22:59 -0500 Date: Mon, 5 Jun 2006 10:22:59 -0500 From: "Jim C. Nasby" To: Zoltan Boszormenyi Cc: pgsql-hackers@postgresql.org Subject: Re: [PERFORM] psql -A (unaligned format) eats too much memory Message-ID: <20060605152258.GT53487@pervasive.com> References: <44835834.2020309@dunaweb.hu> <44835F86.5040008@dunaweb.hu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <44835F86.5040008@dunaweb.hu> X-Operating-System: FreeBSD 6.0-RELEASE-p4 amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.11 X-Hashcash: 1:20:060605:zboszor@dunaweb.hu::TSzwRbnXGASJDQuJ:0000000000000000000 000000000000000000000000166Q X-Hashcash: 1:20:060605:pgsql-hackers@postgresql.org::PfAX3K+PNHPumADT:000000000 00000000000000000000000006H6 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/156 X-Sequence-Number: 84389 Moving to -hackers On Mon, Jun 05, 2006 at 12:32:38AM +0200, Zoltan Boszormenyi wrote: > >I just noticed that psql's unformatted output uses too much > >memory. Is it normal? It seems that psql draws all records > >of a query off the server before it displays or writes the output. > >I would expect this only with formatted output. > > > >Problem is, I have an export that produces 500'000+ records > >which changes frequently. Several (20+) sites run this query > >nightly with different parameters and download it. The SELECTs > >that run in psql -A -t -c '...' may overlap and the query that runs > >in less than 1.5 minutes if it's the only one at the time may take > >3+ hours if ten such queries overlap. The time is mostly spent > >in swapping, all psql processes take up 300+ MB, so the 1GB > >server is brought to its knees quickly, peek swap usage is 1.8 GB. > >I watched the progress in top and the postmaster processes finished > >their work in about half an hour (that would still be acceptable) > >then the psql processes started eating up memory as they read > >the records. > > > >PostgreSQL 8.1.4 was used on RHEL3. > > > >Is there a way to convince psql to use less memory in unformatted > >mode? I know COPY will be able to use arbitrary SELECTs > >but until then I am still stuck with redirecting psql's output. > > The answer it to use SELECT INTO TEMP and then COPY. > Psql will use much less memory that way. But still... I've been able to verify this on 8.1.4; psql -A -t -c 'SELECT * FROM largetable' > /dev/null results in psql consuming vast quantities of memory. Why is this? ISTM this is a bug... -- Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com Pervasive Software http://pervasive.com work: 512-231-6117 vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461