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 1iKAsK-0002kL-Ar for pgsql-performance@arkaria.postgresql.org; Tue, 15 Oct 2019 00:39:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iKAsJ-00048i-3Z for pgsql-performance@arkaria.postgresql.org; Tue, 15 Oct 2019 00:39:43 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iKAsI-00048S-Mw for pgsql-performance@lists.postgresql.org; Tue, 15 Oct 2019 00:39:42 +0000 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iKAsF-00029T-VW for pgsql-performance@postgresql.org; Tue, 15 Oct 2019 00:39:41 +0000 Received: by mail-wm1-x342.google.com with SMTP id y21so18375747wmi.0 for ; Mon, 14 Oct 2019 17:39:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=qAl9fRTWGmqgOX5Hw6QDLdcb+w1n9Iw39i5sqMLNS1g=; b=karqu2R1sTH/5BPw5R5YGL8joHGReQILvrNSdtHi2N9odNxCXvXOuE+HnPfpI4w4lG Ok+debjgsjq4gja2fNH1IPoadbfRfhClAHgecIFVsNbR5gMdix6+rAyw31byc9x0qYyw tW15pO5gMEO4YTW2UyOmShKCCKYZ2S6UL4AEiRsDIzR33k63o7gjmGM8zciRmyP5YYnD Uo2UnZxBv7c2d2EkQjE7o93FGALEhUYf6BXdwMYvJveyBkF8vculPOcPfwgxupK68+1A 1WyRuyOp6TYe9uZhdulft1fXSqqvWOLbX2ux9UzC7DJ0EqPaBoVaZMo5zgO/e/xv5Edn VSsg== 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:content-transfer-encoding :in-reply-to:user-agent; bh=qAl9fRTWGmqgOX5Hw6QDLdcb+w1n9Iw39i5sqMLNS1g=; b=QOmdflsVdYHfL/CLEgN5LuXGET6gxNfc4UckatNihTPJ5zIlJ1Zdh5E+fOE+qdOlzP YdhVjlQn/WUoneG5KmpyYG/AxFsdBLWu6krrTiJOgd8Yg/KdkY+ZxcqMcgCJvzWzoRs6 YWC04JTPx3hwe3/XWmh/N32p/raM/vLzp3/uT/q/4lnDmJZIDDt00PRbi+SZiP/rgdLM IVjgisyjrmHaYCBFOF6VuALtR7dYkO40wZTuki234YKSepFod77D+kkiI1gtF7MohNF7 OK/Bi6qBDhxveHGBA6xyv05MfYTG2H/njLW/KECd2IdVgDhkTm3pTFancMDUZzQEal0I XzTw== X-Gm-Message-State: APjAAAWtRhPvsZ3t9kamZRlePMwpADP+fk9RpOgxAIS5gOsbiEkaIHYG hR9Up3kGDt90fKGK+KSI45MkQw== X-Google-Smtp-Source: APXvYqxiImvUt4ykJsGNQIrOSKPF8GU15U5eDv4rIkF5XIQyy7b1UROhcZ1J5PZu3JYObP6HBrkltQ== X-Received: by 2002:a7b:c3d2:: with SMTP id t18mr17995500wmj.66.1571099978312; Mon, 14 Oct 2019 17:39:38 -0700 (PDT) Received: from localhost (net-188-219-235-30.cust.vodafonedsl.it. [188.219.235.30]) by smtp.gmail.com with ESMTPSA id c4sm20293658wru.31.2019.10.14.17.39.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2019 17:39:37 -0700 (PDT) Date: Tue, 15 Oct 2019 02:39:35 +0200 From: Tomas Vondra To: dangal Cc: pgsql-performance@postgresql.org Subject: Re: pg_stat_bgwriter Message-ID: <20191015003935.u3rrh4jxwfknxnl3@development> References: <20191014181847.6lf5s3fwuh7ui25r@development> <1571083963570-0.post@n3.nabble.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1571083963570-0.post@n3.nabble.com> User-Agent: NeoMutt/20180716 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Mon, Oct 14, 2019 at 01:12:43PM -0700, dangal wrote: >Thanks a lot, always helping >I attached a snapshot that I take every 12 hours of the pg_stat_bgwriter > >select now,buffers_checkpoint,buffers_clean, buffers_backend from >pg_stat_bgwriter_snapshot; Please show us the deltas, i.e. subtract the preceding value (using a window function, or something). FWIW 12 hours may be a bit too coarse, but it's better than nothing. > now | buffers_checkpoint | buffers_clean | >buffers_backend >-------------------------------+--------------------+---------------+----------------- > 2019-10-07 12:00:01.312067-03 | 288343 | 1182944 | >520101 > 2019-10-08 00:00:02.034129-03 | 475323 | 3890772 | >975454 > 2019-10-08 12:00:01.500756-03 | 616154 | 4774924 | >1205261 > 2019-10-09 00:00:01.520329-03 | 784840 | 7377771 | >1601278 > 2019-10-09 12:00:01.388113-03 | 1149560 | 8395288 | >2456249 > 2019-10-10 00:00:01.841054-03 | 1335747 | 11023014 | >2824740 > 2019-10-10 12:00:01.354555-03 | 1486963 | 11919462 | >2995211 > 2019-10-11 00:00:01.519538-03 | 1649066 | 14400593 | >3360700 > 2019-10-11 12:00:01.468203-03 | 1979781 | 15332086 | >4167663 > 2019-10-12 00:00:01.343714-03 | 2161116 | 17791871 | >4525957 > 2019-10-12 12:00:01.991429-03 | 2323194 | 18324723 | >5139418 > 2019-10-13 00:00:01.251191-03 | 2453939 | 19059149 | >5306894 > 2019-10-13 12:00:01.677379-03 | 2782606 | 19391676 | >5878981 > 2019-10-14 00:00:01.824249-03 | 2966021 | 19915346 | >6040316 > 2019-10-14 12:00:01.869126-03 | 3117659 | 20675018 | >6184214 > >I tell you that we have a server with 24 gb of ram and 6gb of shared_buffers >When you tell me that maybe I am running too low of shared_buffers, the >query I run to see what is happening is the following: The question is how that compared to database size, and size of the active set (fraction of the database accessed by the application / queries). I suggest you also track & compute shared_buffers cache hit ratio. >The first 10 are insert, update and an autovaccum > >select calls, shared_blks_hit, shared_blks_read, shared_blks_dirtied >  from pg_stat_statements >  where shared_blks_dirtied> 0 order by shared_blks_dirtied desc >  limit 10 > > > calls | shared_blks_hit | shared_blks_read | shared_blks_dirtied >-----------+-----------------+------------------+--------------------- > 41526844 | 1524091324 | 74477743 | 40568348 > 22707516 | 1317743612 | 33153916 | 28106071 > 517309 | 539285911 | 24583841 | 24408950 > 23 | 23135504 | 187638126 | 15301103 > 11287105 | 383864219 | 18369813 | 13879956 > 2247661 | 275357344 | 9252598 | 6084363 > 13070036 | 244904154 | 5557321 | 5871613 > 54158879 | 324425993 | 5054200 | 4676472 > 24955177 | 125421833 | 5775788 | 4517367 > 142807488 | 14401507751 | 81965894 | 2661358 >(10 filas) > Unfortunately, this has the same issue as the data you shared in the first message - it's a snapshot with data accumulated since the database was created. It's unclear whether the workload changed over time etc. But I guess you can use this to identify queries producing the most dirty buffers and maybe see if you can optimize that somehow (e.g. by removing unnecessary indexes or something). >Another query > >SELECT pg_size_pretty(count(*) * 8192) as buffered, > round(100.0 * count(*) / > (SELECT setting FROM pg_settings WHERE name = 'shared_buffers') > ::integer, > 1) AS buffers_percent, > round(100.0 * count(*) * 8192 / pg_table_size(c.oid), 1) AS >percent_of_relation > FROM pg_class c > INNER JOIN pg_buffercache b > ON b.relfilenode = c.relfilenode > INNER JOIN pg_database d > ON (b.reldatabase = d.oid AND d.datname = current_database()) > GROUP BY c.oid, c.relname > ORDER BY 3 DESC LIMIT 10; > >buffered buffers_percent percent_of_relation >3938 MB; 64.1; 53.2 >479 MB; 7.8; 21.3 >261 MB; 4.3; 99.3 >163 MB; 2.6; 0.1 >153 MB; 2.5; 6.7 >87 MB; 1.4; 1.2 >82 MB; 1.3; 81.6 >65 MB; 1.1; 100.0 >64 MB; 1.0; 0.1 >53 MB; 0.9; 73.5 > It's generally a good idea to explain what a query is supposed to do, instead of just leaving the users to figure that out. In any case, this is a snapshot at a particular moment in time, it's unclear how how that correlates to the activity. The fact that you've removed names of tables and even queries is does not really help either. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services