Received: from localhost (unknown [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id E5FD49FB7C0 for ; Wed, 17 Oct 2007 20:28:52 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 91510-06 for ; Wed, 17 Oct 2007 20:28:43 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 2C9959FB462 for ; Wed, 17 Oct 2007 20:28:48 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.1/8.14.1) with ESMTP id l9HNSgL4012887; Wed, 17 Oct 2007 19:28:42 -0400 (EDT) To: Alvaro Herrera cc: henk de wit , Scott Marlowe , "pgsql-performance@postgresql.org" Subject: Re: Huge amount of memory consumed during transaction In-reply-to: <20071017204058.GR5737@alvh.no-ip.org> References: <20071017204058.GR5737@alvh.no-ip.org> Comments: In-reply-to Alvaro Herrera message dated "Wed, 17 Oct 2007 17:40:58 -0300" Date: Wed, 17 Oct 2007 19:28:42 -0400 Message-ID: <12886.1192663722@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200710/212 X-Sequence-Number: 27234 Alvaro Herrera writes: > henk de wit escribió: >>> How is the memory consumed? How are you measuring it? I assume you >>> mean the postgres process that is running the query uses the memory. >>> If so, which tool(s) are you using and what's the output that shows it >>> being used? >> >> It's periodically measured and recorded by a script from which the relevant parts are: >> >> GET_VSZ="ps aux | grep $REQ_GREP | grep -v grep | grep -v $$ | awk '{print \$5}' >> | sort -n | tail -n1"; >> GET_RSS="ps aux | grep $REQ_GREP | grep -v grep | grep -v $$ | awk '{print \$6}' >> | sort -n | tail -n1"; On many variants of Unix, this is going to lead to a totally misleading number. The first problem is that shared buffers will be counted multiple times (once for each PG process). The second problem is that, depending on platform, a specific page of shared memory is counted against a process only after it first touches that page. This means that when you run a big seqscan, or anything else that touches a lot of buffers, the reported size of the process gradually increases from just its local memory space to its local memory space plus the total size of the Postgres shared buffer arena. This change in the reported size is *utterly meaningless* in terms of actual memory consumption. It's not easy to get useful measurements from "ps" when dealing with heavy memory sharing. There have been some discussions recently of alternative tools that let you get a clearer picture; check the PG list archives. regards, tom lane