Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 2B3D813C7C39 for ; Sun, 10 Jun 2012 00:27:06 -0300 (ADT) Received: from mail-pz0-f46.google.com ([209.85.210.46]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SdYnu-0000K9-9Q for pgsql-performance@postgresql.org; Sun, 10 Jun 2012 03:27:04 +0000 Received: by dady13 with SMTP id y13so3946204dad.19 for ; Sat, 09 Jun 2012 20:26:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding :x-gm-message-state; bh=m3gzdt5BHCVAE7W4zv4zeTV82LfKOZHtbrOE11Ho2zE=; b=KsNMfepxUVRdZHSyMSNvHm5+4TH4JekZGV3brpS2fkWj5RDGkh7wAvRTuABsBsAfwF n/J7hwMYaM1Yz7dApfG1nC/ahTDPa1FX0GAEZfCfYyEkIDn9f4X7ZLkM8T6498ZSEbQQ 0dWHNy9h46Nk/MN2Lu1qF5BazqvPnvxymkxVklSOqUTUTjR5EpS9SMIMnS1FFFtbqiqK FX8UC269MP1VP8Fd5PTfX4lvoHYz9Vck9MY+peESB4ZdC4fKSrvvq4HuSZHAXqUnpCij RQkBm9IlZTyDF9jkhk76sXXt8nl7q3+kT5Q8mWxNc3HLR5s+mEHamUSCB8XPxRQEem/3 jdvw== Received: by 10.68.218.103 with SMTP id pf7mr12012847pbc.67.1339298807603; Sat, 09 Jun 2012 20:26:47 -0700 (PDT) Received: from ayaki.localdomain (203-59-174-91.dyn.iinet.net.au. [203.59.174.91]) by mx.google.com with ESMTPS id tk1sm13440219pbc.8.2012.06.09.20.26.44 (version=SSLv3 cipher=OTHER); Sat, 09 Jun 2012 20:26:46 -0700 (PDT) Message-ID: <4FD413F1.5080404@ringerc.id.au> Date: Sun, 10 Jun 2012 11:26:41 +0800 From: Craig Ringer User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20120430 Thunderbird/12.0.1 MIME-Version: 1.0 To: Konstantin Mikhailov CC: Patric Bechtel , pgsql-performance@postgresql.org Subject: Re: pg 9.1 brings host machine down References: <4FCF4C39.6000506@gmail.com> <4FCF4FBE.3030807@googlemail.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gm-Message-State: ALoCoQk0bUA8sBCsCpZ696xtcO8O25elekviomI7xVZnpYpO1SM4wlEDlIGKqGXuM0hncplV5YNu X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201206/53 X-Sequence-Number: 47079 On 06/09/2012 01:52 AM, Konstantin Mikhailov wrote: > Thanks alot. I've tried to play with work_mem and after few days > of the production testing pg behaves much better. See no more > files in the pgsql_tmp folder. pg processes consumes reasonable > memory, no swap operation any more. I've studied official pg > docs about work_mem an still have no idea which optimal value > work_mem should have. 1MB is obviously too small. I've increased > up to 32m. due to a lot of the sorts and hash joins in the queries. > The trouble is that the optimal work_mem depends on your workload and hardware. Or that's my understanding, anyway. A workload with a few simple queries that sort lots of big data might want work_mem to be really huge (but not so huge that it causes thrashing or pushes indexes out of cache). A workload with lots of really complicated queries full of CTEs, subqueries, etc might use several times work_mem per connection, and if there are lots of connections at once might use unexpectedly large amounts of RAM and cause thrashing or cache competition even with quite a small work_mem. Right now, Pg doesn't have the diagnostic tools or automatic tuning to make it possible to determine an ideal value in any simple way, so it's mostly a matter of examining query plans, tuning, and monitoring. Automatic tuning of work_mem would be great, but would also probably be _really_ hard, and still wouldn't solve the problem where n sorts can consume n times work_mem, so you can't give complicated_query a strict enough work_mem limit without severely starving big_simple_query or having to run a session-local "SET work_mem" before it. A system for auto-tuning Pg at runtime would be amazing, but also very _very_ hard, so tweaking params based on benchmarking and examination of runtime performance is your only real option for now. -- Craig Ringer