Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eRLP9-0005r0-Fi for pgsql-performance@arkaria.postgresql.org; Tue, 19 Dec 2017 17:10:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eRLP8-0005m8-HB for pgsql-performance@arkaria.postgresql.org; Tue, 19 Dec 2017 17:10:10 +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.84_2) (envelope-from ) id 1eRLP8-0005l3-1t for pgsql-performance@lists.postgresql.org; Tue, 19 Dec 2017 17:10:10 +0000 Received: from mail-io0-x234.google.com ([2607:f8b0:4001:c06::234]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eRLP0-0000PH-Gx for pgsql-performance@lists.postgresql.org; Tue, 19 Dec 2017 17:10:08 +0000 Received: by mail-io0-x234.google.com with SMTP id e204so14319268iof.12 for ; Tue, 19 Dec 2017 09:10:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=oN7qHBHnYyWVs9D4rK7eDJfpBVbRMCnVjXCwKrRi7Ug=; b=wIUo3qzATacVtG5kYybmfZo4RGsMQu2rDG20nWSnDnVovRtTMZv3zd1oDVEZ0zK5vM l1juDLo5nBdcw9fQwELxZx3Y/lniFIqEV3bPbSjJysvmkdOKv2hq9/ceM1Q7JaC7Fx74 bnS7OPql/k+/898WQeToFT5lDRur8vD4CDlPVZlXxIU+AMdSgb7vk4wWsL6ySrIp5vBr ybhGTNYrkeqNBC70ZCTo5a2mbb1dKqRumG13TSbEf9XNF8jDvR8wkTTCbxqoM/cqz6JE spEvM+E0SF8GhXT7AA2pPWj5z3zfIEarrkylAdwYCQYk57YovPDYGykbmZoT+9GTGucL 6U1w== 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:in-reply-to:user-agent; bh=oN7qHBHnYyWVs9D4rK7eDJfpBVbRMCnVjXCwKrRi7Ug=; b=D+qNCiURXjUpioOK5hcgfe9TFTlmd/FeXpDiHNyO+Tz50XqFp6SJ5oqpdwS0E8uzLa 8NVnNxTUH/2/BbBtzs9CDXGJYjTtfeFx2tfNKncQeuTdlcKR+yKki6L03RfBt4VWUVgn mtn9MV0S/i564gt9IP8uc+k4ESAr6Zj92UQ+DQjfkQ1pgTtOWU4A6jK/IoX2ernFx/uw oOzhkXQUXq6lP31AsQbgy6gQA4EkXNpnyuBGfq/D9h5ZA4CzOP1AkFADgXiYCzd6G1LT 9ECJv4f2yoQOCdA55MtyXUxsqq0k2zS3SMvp3ovN4QwNQacKuleCnABP8Vgt+MOPoJLz sT3Q== X-Gm-Message-State: AKGB3mJenumrtcMM6SVskAi0yihWnYr9Z+6jZ0HmKdR1L7Ikd4MjNdaH nYPuJJJLfuvbLBRy7Q2qwqBwWw== X-Google-Smtp-Source: ACJfBottuJCIHBiw42Y8kEohBT38NJoixX1zKvWwr3o1hVyUfXB2BUSNr/uC+QaVYCMEEKEGCiPLvA== X-Received: by 10.107.53.86 with SMTP id c83mr3188734ioa.41.1513703400744; Tue, 19 Dec 2017 09:10:00 -0800 (PST) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id a69sm1464892itc.18.2017.12.19.09.10.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Dec 2017 09:10:00 -0800 (PST) Received: by pryzbyj (Postfix, from userid 1000) id DF265801102; Tue, 19 Dec 2017 11:09:58 -0600 (CST) Date: Tue, 19 Dec 2017 11:09:58 -0600 From: Justin Pryzby To: Habib Nahas Cc: pgsql-performance@lists.postgresql.org Subject: Re: Autoanalyze CPU usage Message-ID: <20171219170958.GF18184@telsasoft.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Tue, Dec 19, 2017 at 08:47:52AM -0800, Habib Nahas wrote: > We operate an RDS postgres 9.5 instance and have periodic CPU spikes to > 100%. These spikes appear to be due to autoanalyze kicking on our larger > tables. Not sure if it'll help you, but for our large, insert-only tables partitioned by time, I made several changes from default: - near the end of month, report queries for previous day's data had poor statistics, because autoanalyze scale factor defaults to 0.1, so a table analyzed on the 24th of the month won't be analyzed again until the 26th, so the histogram shows that there's zero rows for previous day, causing nested loop over thousands of rows. - for separate reasons, I increased statistics target on our key columns (up to 3000 for one column). - large stats target on large tables caused (auto)analyze to use large amount of RAM. Therefor I changed our largest tables from monthly partition granuliarity (YYYYMM) to daily (YYYYMMDD). That creates what's traditionally considered to be an excessive number of partitions (and very large pg_attribute/attrdef and pg_statistic tables), but avoids the huge RAM issue, and works for our purposes (and I hope the traditional advice for number of child tables is relaxed in upcoming versions, too). One possibility is a cronjob to set deafult "scale factor" to a modest/default values (0.1) during business hours and an aggressive value (0.005) off-hours. You could do similar with autovacuum_max_workers ... but beware if they're causing high RAM use. I believe autovacuum workers try to "play nice" and the cost are shared between all workers. But I suspect that's not true for CPU cost or RAM use, so there's nothing stopping you from having 9 workers each looping around 2+GB RAM and 100% CPU doing MCV/histogram computation. Maybe that's of some use. Justin