Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1emtF1-0005S0-6N for pgsql-general@arkaria.postgresql.org; Sat, 17 Feb 2018 03:32:47 +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 1emtEz-00078p-P2 for pgsql-general@arkaria.postgresql.org; Sat, 17 Feb 2018 03:32:45 +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 1emtEz-00078d-6z for pgsql-general@lists.postgresql.org; Sat, 17 Feb 2018 03:32:45 +0000 Received: from mail-wr0-x235.google.com ([2a00:1450:400c:c0c::235]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1emtEq-0002NP-DE for pgsql-general@postgresql.org; Sat, 17 Feb 2018 03:32:43 +0000 Received: by mail-wr0-x235.google.com with SMTP id s5so4698910wra.0 for ; Fri, 16 Feb 2018 19:32:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=e2euRlSfDaNMdhT9gvKDqG5zjc5NUTua/cG81LqmlOw=; b=Q1/SZPa8DyeOMMM2NN91QOU2x3aAJiOA3eWJ4nt0DnLI66uPA4DwxWE8BZrSwPVBCs B8VMzWlri/QNoG2bvWtjwXgzscfxoxT006F1dJPk3q1FAXbtWqSjOt4bvh/Rhcej0RoW behMczk4NEinaxKjkde32M4KM2TVS82pYeyWj9hFK9hyxVI1f8bciLwBzfMSXfRwOz3O lyWw/8kIxpQlMvBCI0mRYpClLbUDdbaKr/SwGyFdxsMXzvwdxgjICVDJ8Cvfa6vrvf6j v3JQfjAf5rHrqbafhFl1dNrQBTbDgSY4+bRjMIZYr0cm9Cnw536HI7LdMtcjjw2LNuAL 3cEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=e2euRlSfDaNMdhT9gvKDqG5zjc5NUTua/cG81LqmlOw=; b=fntAe3t+w1M6VdOxoRxQgNjZ/xK6fWdDsdPH+uCVQ94db4DVNTSzGIJeUQk8UZrI7Q zGZLJOhX3M91TCt127HdV+eljf1+9SrTuzb+o9OYmBn7EmuwL7hOsVsbKaAu1kILlGHH Cp1zwpk63xTG/j2e0RXz86qt0mWsyhbTp2NRuRQawJTSUsO1n9LsaVIS3ZK2NuOyzmqX ri4lC+dqdZex/tbG0qOqfw2OEYv2oekTwqge57eLAag07IK3IUDJHM+uSzrLx7C7V/9f 3KEf0ixw8pThnt70MUBbfUhs4EiChnukcI5g2KQK/NB7eyVNobqenf+MsR2/5akNoYUD huaA== X-Gm-Message-State: APf1xPA8wWVW/HdzwxiJLSc+MBo3WK7i/14movkPPWCTq7Do8/4A8zW+ WkoaGS076FAqJ3g4Jy+gNjsXa3OAMNl54YqbIndO6YEGDyv6ZuXxCI47S+ig9u7WVjXMeTtljcm 4oASP4PzMMrn4Xa53/6MaNlEO8MpenSWdIoDQTewfg3wwbUvqAgLGCQaoI5lbDrvAMWwxGI8vU5 VjEfZGif+V X-Google-Smtp-Source: AH8x225I4B9WZa6e9d2mPc21WKB/bN7wjI1IBU4n1tlEtAhw6FKtMvL/VgwWx8H+mU5iRfqdhhu/DA== X-Received: by 10.223.160.171 with SMTP id m40mr7817399wrm.32.1518838352940; Fri, 16 Feb 2018 19:32:32 -0800 (PST) Received: from [10.137.2.19] (ip-78-102-97-226.net.upcbroadband.cz. [78.102.97.226]) by smtp.gmail.com with ESMTPSA id 137sm3136528wml.3.2018.02.16.19.32.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Feb 2018 19:32:32 -0800 (PST) Subject: Re: shared_buffers 8GB maximum To: George Neuner , pgsql-general@postgresql.org References: <7tve8ddg1lcf4uejigos0j71kkjd488jad@4ax.com> From: Tomas Vondra Message-ID: <30ec3be0-a4b2-edb6-87f9-8874afe9d818@2ndquadrant.com> Date: Sat, 17 Feb 2018 04:32:30 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <7tve8ddg1lcf4uejigos0j71kkjd488jad@4ax.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 02/17/2018 02:56 AM, George Neuner wrote: > On Sat, 17 Feb 2018 00:36:57 +0200, Vitaliy Garnashevich > wrote: > ... > >> Could that be a reason for increasing the value of shared_buffers? >> >> - Could shared_buffers=128GB or more on a 250 GB RAM server be a >> reasonable setting? What downsides could there be? > > It depends. 8GB is pretty small for such a large server, but taking > 1/2 the RAM is not necessarily the right thing either. > I certainly wouldn't recommend using 1/2 of RAM right away. There's a good chance it would be a waste of memory - for example due to double buffering, which effectively reduces "total" cache hit ratio. Start with lower value, increment it gradually and monitor behavior of the server. > The size of shared buffers affects log size and the time to complete > checkpoints. If a large(ish) percentage of your workload is writes, > having a very large shared space could be bad for performance, or > bad for space on the log device. > The size of shared_buffers has pretty much no impact on the size of the WAL - that's flat out wrong. It also does not affect the time needed to perform a checkpoint. It may mean that the checkpoint has to write more dirty buffers, but that is actually a good thing because a checkpoint is about the most efficient way to do writes. By using smaller shared buffers you're making it more likely the database has to evict (dirty) buffers from shared buffers to make space for other buffers needed by queries/vacuum/whatever. Those evictions are performed either by backends or bgwriter, both of which are less efficient than checkpointer. Not only can checkpointer perform various optimizations (e.g. sorting buffers to make the writes more sequential), but it also writes each dirty buffer just once. With smaller shared_buffers the page may have be written multiple times. What actually *does* matter is the active part of the data set, i.e. the part of the data that is actually accessed regularly. In other words, your goal is to achieve good cache hit ratio - say, 95% or more. This also helps reducing the number of syscalls (when reading data from page cache). What is the right shared_buffers size? I have no idea, as it's very dependent on the application. It might be 1GB or 100GB, hard to say. The best thing you can do is set shared buffers to some conservative value (say, 4-8GB), let the system run for a day or two, compute the cache hit ratio using metrics in pg_stat_database, and then decide if you need to resize shared buffers. >> PS. Some background. We had shared_buffers=8GB initially. In >> pg_stat_bgwriter we saw that dirty buffers were written to disk more >> frequently by backends than during checkpoints (buffers_clean > >> buffers_checkpoint, and buffers_backend > buffers_checkpoint). According >> to pg_buffercache extension, there was very small percentage of dirty >> pages in shared buffers. The percentage of pages with usagecount >= 3 >> was also low. Some of our more frequently used tables and indexes are >> more than 10 GB in size. This all suggested that probably the bigger >> tables and indexes, whenever scanned, are constantly flushing pages from >> the shared buffers area. After increasing shared_buffers to 32GB, the >> picture started looking healthier. There were 1GB+ of dirty pages in >> shared buffers (vs 40-200MB before), 30-60% of pages with usagecount >= >> 3 (vs 10-40% before), buffers_checkpoint started to grow faster than >> buffers_clean or buffers_backend. There is still not all frequently used >> data fits in shared_buffers, so we're considering to increase the >> parameter more. I wanted to have some idea about how big it could >> reasonably be. > > So now you know that 32GB is better for your workload than 8GB. But > that is not necessarily a reason immediately to go crazy with it. Try > increasing it gradually - e.g., adding 16GB at a time - and see if the > additional shared space provides any real benefit. > Gradual increases are a good approach in general. And yes, having buffers_checkpoint > buffers_clean > buffers_backend is a good idea too. Together with the cache hit ratio it's probably a more sensible metric than looking at usagecount directly. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services