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 1lJepr-0000Uf-GR for pgsql-general@arkaria.postgresql.org; Tue, 09 Mar 2021 16:03:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lJepq-00082t-Dc for pgsql-general@arkaria.postgresql.org; Tue, 09 Mar 2021 16:03:50 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lJepq-00082m-5p for pgsql-general@lists.postgresql.org; Tue, 09 Mar 2021 16:03:50 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lJepj-0003kk-FI for pgsql-general@postgresql.org; Tue, 09 Mar 2021 16:03:49 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 129G3eWp2022858; Tue, 9 Mar 2021 11:03:40 -0500 From: Tom Lane To: Radoslav Nedyalkov cc: pgsql-general Subject: Re: how to limit statement memory allocation In-reply-to: References: Comments: In-reply-to Radoslav Nedyalkov message dated "Tue, 09 Mar 2021 17:35:35 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2022856.1615305820.1@sss.pgh.pa.us> Date: Tue, 09 Mar 2021 11:03:40 -0500 Message-ID: <2022857.1615305820@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Radoslav Nedyalkov writes: > Occasionally we get bad queries on our db that consume a lot of memory. > These typically are full joins by mistake or just too large result sets. > My understanding is these should go to a temp file but apparently memory > allocation is preferred. Perhaps the accumulation is happening on the client side? libpq doesn't have any provision for spilling a result set to disk. If that's it, you could consider revising your application to read results row-at-a-time, although that might require a good deal of effort. https://www.postgresql.org/docs/current/libpq-single-row-mode.html regards, tom lane