Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lSLGh-00010G-D4 for pgsql-admin@arkaria.postgresql.org; Fri, 02 Apr 2021 14:59:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lSLGg-00031P-9K for pgsql-admin@arkaria.postgresql.org; Fri, 02 Apr 2021 14:59:26 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lSLGg-00030n-1w for pgsql-admin@lists.postgresql.org; Fri, 02 Apr 2021 14:59:26 +0000 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lSLGc-0005mL-5i for pgsql-admin@lists.postgresql.org; Fri, 02 Apr 2021 14:59:24 +0000 Received: by mail-wm1-x32f.google.com with SMTP id k128so2619821wmk.4 for ; Fri, 02 Apr 2021 07:59:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20150623.gappssmtp.com; s=20150623; h=message-id:subject:from:to:cc:date:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=EgdEHpCC+d0XkYpqM4BY+fV1QUwuydvRwyzLaHdFJoI=; b=F2EqhR2FxPQWmtB0J6tG8g4VwKKm5rJdwRHsJLtYpYTR7ACFYzkQLJ+aClOBeoDEGb xexshga57u0lGAPEZrX2Li3OrgQQrpJcBU8+tVYam+2fTqweqvo1GUa151AenZs+rt0n EQUq73mPR6lWcwsQA6Vw75IDyeNmcz4jVPIB5cSXjmIwOD3p7i/vVNIjNbRg3UHWg+c0 iTXcpYzCGgVtgt6BU+mqACW9wCU5UiOFJpn4BqnPMqq+yKteyv9xil19C0cukgmrZrV2 tK+gjWMKYjpx0OGGd7G9IOP+79/fCqDS6A5kxW7luE/eNHeB8tjEn0ZJpx2mReFh/iGJ kb/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=EgdEHpCC+d0XkYpqM4BY+fV1QUwuydvRwyzLaHdFJoI=; b=q/epjf6sSHO3C0BwjaeplhGqPhYonslNTVOOrTF+jOrL2kjSmOh08RvfoHJoDaqNNr 9zt69lfRGZDgc1h2b4jg34+7NjEJ5VpQ3S0eMtdg4Vf6D7RLwrzJpDWSYa1ltgtCHAaV eZUCZ1hVnzNcFQDlSKfQd3ldoWVzKKUD0NNdqwB2n1+DQqlttU+oi/eR7C9nqgb25+Be h4CRhReW5rPQg3KVcOdfdmf+WmY2McVBzXKZ9L/vWKEqNhMTpRdBW3wZj6jSDwcHlALk RW2/lQ2UMX3aMX65QTEd9QZgbQWbXztsByY1/3k1+4hunXwgW0D6Wu7RrsmwnVOkLIlS 1mzQ== X-Gm-Message-State: AOAM533NgY4yZk2elW8n8y2++4LFACWg4a6HzLU9phl2oqN1RAIlUELP /Y1wvwAWyMe4eE0szFCKtMdWhQ== X-Google-Smtp-Source: ABdhPJwEekwLg8LAhJc64H0tpxylIj8QMWEIf1HECIIQYcT6VJ1IgXvHtxug10ynfFOVOngULKKH2w== X-Received: by 2002:a1c:400b:: with SMTP id n11mr13085144wma.167.1617375560629; Fri, 02 Apr 2021 07:59:20 -0700 (PDT) Received: from localhost.localdomain (217-149-175-0.nat.highway.telekom.at. [217.149.175.0]) by smtp.gmail.com with ESMTPSA id c9sm13104397wml.42.2021.04.02.07.59.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Apr 2021 07:59:20 -0700 (PDT) Message-ID: <339e1ee870881a3efaffc7ea4cddac6bc4d009cf.camel@cybertec.at> Subject: Re: work_mem From: Laurenz Albe To: "Campbell, Lance" , MichaelDBA , SASIKUMAR Devaraj Cc: "holger@jakobs.com" , "pgsql-admin@lists.postgresql.org" Date: Fri, 02 Apr 2021 16:59:16 +0200 In-Reply-To: References: <04D84259-1B75-4648-949F-78677916194E@jakobs.com> <66290583.2329958.1617367063840@mail.yahoo.com> <1654783699.2333997.1617367552583@mail.yahoo.com> ,<592e5895-8dbd-1a4f-a87c-af72ac8eea02@sqlexec.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, 2021-04-02 at 13:31 +0000, Campbell, Lance wrote: > It feels like there needs to be work_mem and work_mem_stack_size. When work memory is > needed a process “pops” a token off of a stack. When it is done processing it “puts” > the token back on the stack. If the stack is empty then don’t allocate memory just > write to disk for work_mem. > > This does two key things: > > 1) It allows for a real world understanding of how much memory is really needed on a > day to day basis. You can track how often a stack is empty. You can also look at the > number of temp files to see when work exceeds the work_mem allocation. There is no > “art” to setting these values. You can use logical analysis to make choices. > > 2) This also prevents out of memory issues. You are protecting yourself from extreme loads. If I get you right, you want another memory limit per session. I see the point, but then we wouldn't need "work_mem" any more, right? What is the point of limiting the memory per plan node if we have an overall limit? In practice, I have never had trouble with "work_mem". I usually follow my rule of thumb: max_connections * work_mem + shared_buffers < RAM While some backend may need more, many will need less. Only bitmaps, hashes and sorts are memory hungry. Yours, Laurenz Albe -- Cybertec | https://www.cybertec-postgresql.com