X-Original-To: pgsql-php-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 17398D1B3AD for ; Mon, 31 May 2004 19:50:51 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 62550-09 for ; Mon, 31 May 2004 19:50:51 -0300 (ADT) Received: from obie.mrkdns.com (obie.mrkdns.com [69.93.72.82]) by svr1.postgresql.org (Postfix) with ESMTP id 02CC1D1B344 for ; Mon, 31 May 2004 19:50:47 -0300 (ADT) Received: from 82-33-0-42.cable.ubr13.newt.blueyonder.co.uk ([82.33.0.42] helo=[192.168.0.12]) by obie.mrkdns.com with asmtp (Exim 4.34) id 1BUvcI-0003M9-LJ; Mon, 31 May 2004 23:50:50 +0100 Message-ID: <40BBB6C3.8030507@chuckie.co.uk> Date: Mon, 31 May 2004 23:50:43 +0100 From: Nick Barr User-Agent: Mozilla Thunderbird 0.6 (Windows/20040502) X-Accept-Language: en-us, en MIME-Version: 1.0 To: A Palmblad Cc: pgsql-php@postgresql.org Subject: Re: PHP memory usage References: <005501c44755$5a851580$97019696@AERS04> In-Reply-To: <005501c44755$5a851580$97019696@AERS04> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - obie.mrkdns.com X-AntiAbuse: Original Domain - postgresql.org X-AntiAbuse: Originator/Caller UID/GID - [0 0] / [47 12] X-AntiAbuse: Sender Address Domain - chuckie.co.uk X-Source: X-Source-Args: X-Source-Dir: X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=0.1 tagged_above=0.0 required=5.0 tests=RCVD_IN_SORBS X-Spam-Level: X-Archive-Number: 200405/55 X-Sequence-Number: 2774 A Palmblad wrote: > We've been running into some issues with PHP and Postgres, and memory usage. > On a dual athlon 64, w/ 4 gigs of RAM, PHP 4.3.6, and Postgres 7.4.2 I've > seen our server start to crawl after some queries returning very large > result sets. Although large result sets aren't exactly what we want to be > dealing with, I really want to avoid a situation where a user could disrupt > our server with certain options to some searches. > > I did a quick commandline test, and it looks like PHP starts to eat memory > during its call to pg_query. By eat memory, I mean use memory well in > excess of php.ini's memory_limit of 8 megs. (I stop it around 90% of > available memory usage) Is this acceptable behaviour, or should I report it > to PHP as a bug? If not, are my only solutions to wrap my selects in > cursors and/or to use limit? > > -Adam Palmblad > > > ---------------------------(end of broadcast)--------------------------- > TIP 7: don't forget to increase your free space map settings > > > My guess is that PHP is pulling the entire record set into memory, something which is not good as you can imagine. The only real solutions to this are to reduce the size of the record set, or use cursors. You could reduce the size of the record set by using paging, i.e. only allowing the user to see say 20 records out of 5000. The way I have implemented this in the past is to do a COUNT(*) on the entire record set then use LIMIT 20 OFFSET 200. Alternatively you could use the cursor to return the data you want to look at. Hope that almost helps. Nick