Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g37n6-0004Ng-CJ for pgsql-general@arkaria.postgresql.org; Thu, 20 Sep 2018 22:51:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g37n4-00089T-Jv for pgsql-general@arkaria.postgresql.org; Thu, 20 Sep 2018 22:51:18 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g37n4-00089M-8d for pgsql-general@lists.postgresql.org; Thu, 20 Sep 2018 22:51:18 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g37n1-0005Se-Si for pgsql-general@postgresql.org; Thu, 20 Sep 2018 22:51:17 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w8KMpBYg016505; Thu, 20 Sep 2018 18:51:11 -0400 From: Tom Lane To: greigwise cc: pgsql-general@postgresql.org Subject: Re: Out of Memory In-reply-to: <1537481492525-0.post@n3.nabble.com> References: <1537481492525-0.post@n3.nabble.com> Comments: In-reply-to greigwise message dated "Thu, 20 Sep 2018 15:11:32 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <16503.1537483871.1@sss.pgh.pa.us> Date: Thu, 20 Sep 2018 18:51:11 -0400 Message-ID: <16504.1537483871@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk greigwise writes: > Hello, I'm running postgres 9.6.10 on Centos 7. Seeing the occasional out > of memory error trying to run a query. In the logs I see something like > this: > Grand total: 462104832 bytes in 795 blocks; 142439136 free (819860 chunks); > 319665696 used > 2018-09-20 18:08:01 UTC xxxx 5ba3e1a2.7a8a dbname ERROR: out of memory > 2018-09-20 18:08:01 UTC xxxx 5ba3e1a2.7a8a dbname DETAIL: Failed on request > of size 2016. > If I have 142439136 free, then why am I failing on a request of size 2016? The free space must be in contexts other than the one that last little request wanted space in. Overall, you've got about 460MB of space consumed in that session, so it's not *that* surprising that you got OOM. (At least, it's unsurprising on a 32-bit machine. If the server is 64-bit I'd have thought the kernel would be a bit more liberal.) But anyway, this looks like a mighty inefficient usage pattern at best, and maybe a memory leak at worst. Can you create a self-contained test case that does this? regards, tom lane