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 1iHaGH-0006bG-HR for pgsql-general@arkaria.postgresql.org; Mon, 07 Oct 2019 21:09:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iHaGF-0004Ul-KY for pgsql-general@arkaria.postgresql.org; Mon, 07 Oct 2019 21:09:43 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iHaGF-0004Ue-3f for pgsql-general@lists.postgresql.org; Mon, 07 Oct 2019 21:09:43 +0000 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iHaG8-0000C7-3J for pgsql-general@postgresql.org; Mon, 07 Oct 2019 21:09:41 +0000 Received: by mail-wm1-x342.google.com with SMTP id p7so903941wmp.4 for ; Mon, 07 Oct 2019 14:09:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=yIsRh6X3rkjNr/XHxzBUzVS6dgFQUFjd1dUhKVfZCJ4=; b=MXzguJ21Idz9NKwrlJD4mbsPte0e3l5QAtNNWmVqNNGDUAIPi6TOh70C5yWkE43/NU nKVYotAyn6o8U6Q1dz96bTZv3l4E2XOLx9qp3V8p5HngLEr/7bC6z8PFhZRWLaCaFgzd TKvLNxfE2clrRDqBNap6KJ8dXZhMaMpHo65JJa8sDH9xVhvMwyqxIN3qNw2AZXsZFDiT s8jaJKfbqQE7eCsKMMhmnkNFdKQtYVMYpx6j0IgUiyLGIuI3Xcf5aAOsBDe+GO0P/IWV p54XGGOkRKa3UbRbqmy61YesnieVjP7b6vrMt0d5tM4COF84Xcj+bVt6HcxHhar4L2Pb oQYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=yIsRh6X3rkjNr/XHxzBUzVS6dgFQUFjd1dUhKVfZCJ4=; b=QBxu21V6R143xU7ER5v+nioxRj/vLNhghEKho9kIfYU49q0uY82mVATSvYrrWIjrdy nK+SCA1DBO891Wx8YR4T6Ss014WaqcRrQyG1IRQmhTn1qVYG28qJU/dtz/6fLG85Wm0V vst8PsQukoILXtO6CZ/ni9PIPWo8R4vhZP0Z1Vai5pjzna4n0j043jPJf8atpTEyjDYw /+OluJyH9M9BXqDIMYQC1gROyoFFWnzJWZ0P55b46eeeEqvgIiUPpGKVRpe+Ovx51xxC aviXJ7xVTq6b4QWBo5JijVp7CwiKfjjzWi5wZ2yGy05GjIFziu1Dd752fhfb3ys47hse naLQ== X-Gm-Message-State: APjAAAVz37vTc1eHyb5Jk16p/LxQ9+fwVqRr/uqTzmTU9Ws3eVaL7PK0 8da68Jz3FaRQRJj5Navdo0PGbg== X-Google-Smtp-Source: APXvYqz+1yB+H5Knqw1iAtTlGdQwHCjZSyraO+sA+k1sIIjpMsi0akRT2QopW3hUhK+k5JHXwQF1Tw== X-Received: by 2002:a05:600c:2049:: with SMTP id p9mr949447wmg.30.1570482574694; Mon, 07 Oct 2019 14:09:34 -0700 (PDT) Received: from localhost (ip-86-49-253-183.net.upcbroadband.cz. [86.49.253.183]) by smtp.gmail.com with ESMTPSA id n8sm1403103wma.7.2019.10.07.14.09.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Oct 2019 14:09:34 -0700 (PDT) Date: Mon, 7 Oct 2019 23:09:33 +0200 From: Tomas Vondra To: dangal Cc: pgsql-general@postgresql.org Subject: Re: temporary files Message-ID: <20191007210933.7kla65cvnddnvlwm@development> References: <1570481561995-0.post@n3.nabble.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1570481561995-0.post@n3.nabble.com> User-Agent: NeoMutt/20180716 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Mon, Oct 07, 2019 at 01:52:41PM -0700, dangal wrote: >Hello everyone, I have a question to see if you can help me, I have set >work_mem in 100 MB but I have the following in the pgbadger > >Queries generating the most temporary files (N) > >Count Total size Min size Max size Avg size >   58 3.24 GiB 57.15 MiB 57.15 MiB 57.15 MiB > >How could it be that if you require 57 MB, 100 MB will not reach ? >thanks a lot > The on-disk and in-memory representations are not the same, and the on-disk one is often significantly more efficient. Data that needs 57MB temporary file may beed ~150MB memory to perform in-memory sort, for example. Yet another reason may be that e.g. hash join splits the memory into batches, and each one has to fit into work_mem. And whevener we hit the limit, we double the number of batches, i.e. we cut the batch size in half. Thus the size is somewhere between 50 and 100MB, with ~75MB on average. Furthermore, we also estimate the batch size before running the query, so we may start with unnecessarily many batches, pushing the average batch size down even more. FWIW it's somewhat suspicious you have 58 temp files with almost no variability in size. That seems as if a single query was executed repeatedly. Maybe try looking into what query that is. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services