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 1iWhbw-00063M-K1 for pgsql-performance@arkaria.postgresql.org; Mon, 18 Nov 2019 14:02:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iWhbt-0007Ks-4h for pgsql-performance@arkaria.postgresql.org; Mon, 18 Nov 2019 14:02:33 +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 1iWhbs-0007Kl-NX for pgsql-performance@lists.postgresql.org; Mon, 18 Nov 2019 14:02:32 +0000 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iWhbg-0007gL-00 for pgsql-performance@lists.postgresql.org; Mon, 18 Nov 2019 14:02:29 +0000 Received: by mail-wm1-x331.google.com with SMTP id q70so17497810wme.1 for ; Mon, 18 Nov 2019 06:02:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zunibal-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=Pfk8UuBhbs8sNyWaNsENn9GASi8fUH5cB7A4mjXS3rk=; b=UE93M4SGF6IJrzDNb4Sj+vgNJhGJJ5/YiWUPRoiG5DXhIK+itE7p1HNZ44aCk2XG77 zLCch1b/kUTFZGUN/4re14+Pvy3wKra3FM4/lc8Pjb5TZUhyUG6TLXZXlGGt3Jr3AWNQ 5W1NVgH/hejDZJP9WB4A2qs0uG9P2rJsxA7wmEQQheSkv0R3mYGEJuOREt6ggOoiGsOL PpdtmTavF0Dd9bkM0trPXZIn7HgvwlQ/LPsXfRmzV/GZvZN2N2+ur3GTUujpb1qmc86Q 17tRmS7wre0gh7umPWlQfyZL6wL9a0PnKp1iQPx98u2Ygcu+Cc6Vjg/T/bKSh09d5K3E dL1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=Pfk8UuBhbs8sNyWaNsENn9GASi8fUH5cB7A4mjXS3rk=; b=okTieleQJlWH1hy1C/5a0y6Ooi1qd4XdHBm/MNyAd7vyJ/6WCmG7JKvLXW2U8H65lI gnlYnAdx8PODPoIiX9eD0afZCRrVVk+mlm8DkAMhAi+s0eqd/bqdq3LnaqwG7eY3kkcw UYvsmsnhi5L0o/kB5XcdmX+Pc6bPe5B94y8l6ZfNTsN6O3Ri9oB0OPq7iT0LM1FRRUSJ Y8Tysdg1Y8JqrC8vBCJI7IPK4Nu8LOCv7ewbOkDFdTqLkuJdmGiLIrIJja8hQYQsmSHU ba8SDvP7JaVMXSw4oivkr6mHDZKRNtf2oNugENRk2/q0PVEQ0RpOiJ0KcPT1OjfmBXKm zMnQ== X-Gm-Message-State: APjAAAXxpzcNLY5STiC66h/vTa48eELqjycrIjbd2iHH6yPbksZPrlDn C3F37jJMohRWi0pdLPtolN4HwS2ZoZU= X-Google-Smtp-Source: APXvYqw2CkbRZ1iTJ4ctnOSRUBQ9EZop4Wzjw8Ok0UhlWroArrXQmxGtOcSJACas52qhONiaKBiA4A== X-Received: by 2002:a7b:c088:: with SMTP id r8mr26296748wmh.24.1574085737732; Mon, 18 Nov 2019 06:02:17 -0800 (PST) Received: from [192.168.3.150] ([176.222.91.85]) by smtp.gmail.com with ESMTPSA id n23sm20120351wmc.18.2019.11.18.06.02.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Nov 2019 06:02:17 -0800 (PST) Subject: Re: Out of memory error on automatic vacuum To: Tomas Vondra Cc: pgsql-performance@lists.postgresql.org References: <20191118122528.45k3jpgaxevsyser@development> From: Ekaterina Amez Message-ID: Date: Mon, 18 Nov 2019 15:02:16 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <20191118122528.45k3jpgaxevsyser@development> Content-Type: multipart/alternative; boundary="------------B964C9291380C086E6D0D920" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------B964C9291380C086E6D0D920 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit El 18/11/19 a las 13:25, Tomas Vondra escribió: > On Mon, Nov 18, 2019 at 12:41:27PM +0100, Ekaterina Amez wrote: >> Hi all, >> >> This morning I was checking postgres servers logs, looking for errors >> (we've recently upgraded them and changed default config) and long >> running queries when I found one of the servers had really big logs >> since yesterday.  It was giving the error of this mail's subject: out >> of memory, failed on request of size XXX on automatic vacuum of table >> YYY. A quick search revealed me some postgresql-lists messages >> talking about work_mem and shared_buffers configuration options, some >> kernel config options too. Although all of them were messages from >> several years ago, I decided to cut my shared_buffers configured >> value and restart server: now it looks like error is gone. But I'd >> like to understand what's beyond the logged error (it's really long >> and refers to things about inner functionalities that I'm missing), >> how to detect what config options are possibly conflicting and, most >> important, I want to know if I've solved it right. >> > > Unfortunately that's hard to say, without further data. The "out of > memory" errors simply mean we called malloc() and it returned NULL, > because the kernel was unable to provide the memory. This (kernel unable to provide memory) was because no more RAM was available to allocate? It was because PG process did not have more memory assigned ready to use? Or is something unknown because it depends on the situations where the error is thrown? > > There probably were other processes using all the available RAM (the > limit depends on various config values, e.g. overcommit). What were > these processes doing we don't know :-( > > For example, there might be multiple complex queries, allocating > several work_mem each, using quite a bit of memory. Or there might be a > runaway query doing HashAgg allocating much more memory than predicted. > Or maybe there was running a completely separate job (say, backup) > allocating a lot of memory or dirtying data in page cache. I've looked at cron and I've seen a scheduled process that finished a bit before the error began to log (o couple of minutes or so). Errors began on Sunday morning and this machine doesn't have much workload on work days, and less on weekend. I'll keep an eye on this log and if the problem appears again I'll try to track database activity and machine activity. > > There are countless options what might have happened. The memory context > stats are nice, but it's just a snapshot from one particular process, > and it does not seem very interesting (the total is just ~1MB, so > nothing extreme). We still don't know what else was running. When you talk about ~1MB are you getting this size from log lines like this? : *1024* total in 1 blocks; 476 free (0 chunks); 548 used > > Lowering shared_buffers certainly does reduce the memory pressure in > general, i.e. there is 1GB of work for use by processes. It may be > sufficient, hard to guess. > > I don't know if work_mem 64MB is too low, becuase it depends on what > queries you're running etc. But you probably don't wat to increase that, > as it allows processes to use more memory when executing queries, i.e. > it increases memory pressure and makes OOM more likely. > > So you need to watch system monitoring, see how much memory is being > used (excluding page cache) and consider reducing work_mem and/or > max_connections if it's too close. I'll do, thanks for your suggestions. > > regards > Regards, Ekaterina --------------B964C9291380C086E6D0D920 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit


El 18/11/19 a las 13:25, Tomas Vondra escribió:
On Mon, Nov 18, 2019 at 12:41:27PM +0100, Ekaterina Amez wrote:
Hi all,

This morning I was checking postgres servers logs, looking for errors (we've recently upgraded them and changed default config) and long running queries when I found one of the servers had really big logs since yesterday.  It was giving the error of this mail's subject: out of memory, failed on request of size XXX on automatic vacuum of table YYY. A quick search revealed me some postgresql-lists messages talking about work_mem and shared_buffers configuration options, some kernel config options too. Although all of them were messages from several years ago, I decided to cut my shared_buffers configured value and restart server: now it looks like error is gone. But I'd like to understand what's beyond the logged error (it's really long and refers to things about inner functionalities that I'm missing), how to detect what config options are possibly conflicting and, most important, I want to know if I've solved it right.


Unfortunately that's hard to say, without further data. The "out of
memory" errors simply mean we called malloc() and it returned NULL,
because the kernel was unable to provide the memory.
This (kernel unable to provide memory) was because no more RAM was available to allocate? It was because PG process did not have more memory assigned ready to use? Or is something unknown because it depends on the situations where the error is thrown?

There probably were other processes using all the available RAM (the
limit depends on various config values, e.g. overcommit). What were
these processes doing we don't know :-(

For example, there might be multiple complex queries, allocating
several work_mem each, using quite a bit of memory. Or there might be a
runaway query doing HashAgg allocating much more memory than predicted.
Or maybe there was running a completely separate job (say, backup)
allocating a lot of memory or dirtying data in page cache.

I've looked at cron and I've seen a scheduled process that finished a bit before the error began to log (o couple of minutes or so). Errors began on Sunday morning and this machine doesn't have much workload on work days, and less on weekend. I'll keep an eye on this log and if the problem appears again I'll try to track database activity and machine activity.


There are countless options what might have happened. The memory context
stats are nice, but it's just a snapshot from one particular process,
and it does not seem very interesting (the total is just ~1MB, so
nothing extreme). We still don't know what else was running.

When you talk about ~1MB are you getting this size from log lines like this?

<index>: 1024 total in 1 blocks; 476 free (0 chunks); 548 used



Lowering shared_buffers certainly does reduce the memory pressure in
general, i.e. there is 1GB of work for use by processes. It may be
sufficient, hard to guess.

I don't know if work_mem 64MB is too low, becuase it depends on what
queries you're running etc. But you probably don't wat to increase that,
as it allows processes to use more memory when executing queries, i.e.
it increases memory pressure and makes OOM more likely.

So you need to watch system monitoring, see how much memory is being
used (excluding page cache) and consider reducing work_mem and/or
max_connections if it's too close.

I'll do, thanks for your suggestions.



regards

Regards,

Ekaterina

--------------B964C9291380C086E6D0D920--