Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hxaU1-00053d-Q4 for pgsql-general@arkaria.postgresql.org; Tue, 13 Aug 2019 17:21:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hxaU0-0001iE-CT for pgsql-general@arkaria.postgresql.org; Tue, 13 Aug 2019 17:21:16 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hxaU0-0001i7-17 for pgsql-general@lists.postgresql.org; Tue, 13 Aug 2019 17:21:16 +0000 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hxaTt-0001HF-JJ for pgsql-general@lists.postgresql.org; Tue, 13 Aug 2019 17:21:15 +0000 Received: by mail-pg1-x544.google.com with SMTP id w3so14389441pgt.13 for ; Tue, 13 Aug 2019 10:21:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=KryTTCg1KmJX2chpEKEriC8T4gfOOe0z4SOdnqVIGW8=; b=AoysXQuElZUKB5QzIEDdLLfRHsYt0Mbg4mQ+C4nm8JC5qtdVe98tbgpJYGumIYN1co NrbVvB4v66OyP25RsrrEFGXWwtOhQhi+StsBe9j8L+i4xtj3az+gQC0/f2OzSyEvXdrP AOcyITdoThH9zb7fW9/VIl0lh4cuFQ8CHq3lF7+qa3e1D90V1dBydWeMLSjwm7Cim+U+ 0uk0W4UnZfPtYf9BsbdaTd6nFPZ8cf1L0jUWYeUidd632RDgDTsa1GIgeMcgNR9k/Jca afd2Y1BagCARPiLMjZ8ZqpWcIqFJZyscjCyQrMYYNoO2c/LB4M5nPEPNVy01x7+7ZZNz 6HSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=KryTTCg1KmJX2chpEKEriC8T4gfOOe0z4SOdnqVIGW8=; b=saArWCW3UhVDAO3feGXEb2oxN/m7OPkAsDGV7AZ1wQzknvz/J8T0NXmwWQwWfvU+GO G3VNmwXOXLRAeNv8UTJOWuXml6s1nE0a7FdgwN90LJ0rbXHm1mnEPwleu6Xcq5yaoh8P M8lTI0wCLwmMP+J1BqGXGlCQcclB81kdfVKNyroJQItCWrU3OMBC4MH/B8KlNav5+aHY HF9LDchu3JtidzmalKyotyotWLoeROa/qWNYPSWnt6TuzXNG97BCjcAQgFXPjHI7hIuz fQQ7DrIoEyw+z34n4Ra2cPdvKLOZFqoOzKJPHSns5hHlKUIOwmq47GcRleC4heLHACKZ WHJQ== X-Gm-Message-State: APjAAAVkO1KPU55OM0dTlmj7CxL03zO/oYqVsM5ygNLOry82FjgLlIM2 7eqLii7Dar4DUK47i99OqGCTW0VV X-Google-Smtp-Source: APXvYqyTJyQRD3GLiEV609u1mPBNifKc0J34wEpDufXEWmrbL4SI6jEpZLm0W3WV6qTLQm2F6e7epQ== X-Received: by 2002:a63:e948:: with SMTP id q8mr34264508pgj.93.1565716866578; Tue, 13 Aug 2019 10:21:06 -0700 (PDT) Received: from [10.104.134.41] ([155.100.47.1]) by smtp.gmail.com with ESMTPSA id o3sm5192937pje.1.2019.08.13.10.21.05 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Aug 2019 10:21:06 -0700 (PDT) Subject: Re: Changing work_mem To: pgsql-general@lists.postgresql.org References: <2cbec921-a0c2-016f-1831-82dd45106af3@mail.ru> <6d170b3b-17b7-8e02-bbf6-2a6885b317eb@mail.ru> <50c20aea-6f63-2cf7-1760-bb28679ff3e7@mail.ru> <9c6b069a-c99b-4b65-92fa-59404012e576@mail.ru> From: Rob Sargent Message-ID: <0066b922-7671-c4c0-4367-183778b9e5d7@gmail.com> Date: Tue, 13 Aug 2019 11:21:04 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <9c6b069a-c99b-4b65-92fa-59404012e576@mail.ru> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 8/13/19 11:04 AM, rihad wrote: > On 08/13/2019 08:44 PM, rihad wrote: >> On 08/13/2019 08:22 PM, Luca Ferrari wrote: >>> On Tue, Aug 13, 2019 at 5:59 PM rihad wrote: >>>> [dbname] LOG:  temporary file: path >>>> "base/pgsql_tmp/pgsql_tmp93683.257381", size 594 >>>> >>> The setting 'work_mem' is within context 'user', that means it will >>> affect running sessione unless the session itself has already issued a >>> SET work_mem to xxx. >>> So this could be a reason why you don't seem to see any change. >>> >>> Also keep in mind that work_mem work on a connection basis, so you are >>> going to possibly see 521MB x num_connections if all your clients are >>> doig the same kind of sort concurrently, which probably causes >>> PostgreSQL to go to disk due to memory unavailable. >>> >>> Hope this helps. >>> Luca >>> . >>> >> Thanks. The box has 15GB mem free (as in FreeBSD ))) >> >> And it hasn't moved a notch after the increase. >> >> No code does SET work_mem=... AFAIK. >> >> My apologies to Mr. Peter but I still think that older processes, >> some of them started a couple of weeks ago, use the older setting. > Sorry, I just decreased work_mem back to 256MB, reloaded, and > instantly started seeing 82mb temp file creation, not 165mb as was > usual with work_mem=512MB. > > So it indeed was applied immediately. > Really weird figures ) > > The files are written because work-mem was insufficient to complete the task at hand, so some data was flushed to disk, more data read into memory, processed and eventually all merged into final result.  Larger work-mem means more to flush, but less often.