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 1hfoEc-0006rt-Fp for pgsql-performance@arkaria.postgresql.org; Tue, 25 Jun 2019 16:23:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hfoEZ-0002bJ-OO for pgsql-performance@arkaria.postgresql.org; Tue, 25 Jun 2019 16:23:51 +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 1hfoEZ-0002bC-FX for pgsql-performance@lists.postgresql.org; Tue, 25 Jun 2019 16:23:51 +0000 Received: from mail-io1-xd32.google.com ([2607:f8b0:4864:20::d32]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hfoER-00038R-54 for pgsql-performance@lists.postgresql.org; Tue, 25 Jun 2019 16:23:50 +0000 Received: by mail-io1-xd32.google.com with SMTP id h6so2840543ioh.3 for ; Tue, 25 Jun 2019 09:23:42 -0700 (PDT) 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=0bGuZUKQK/4Fjk/G/30+oJgljqYEYhyOkuurEd4dX6E=; b=ujnwHHTpaJAFIueiHzKdfzlOCV90impNAGYG0iO3JfxPFAtw29+x+xnzkgpWwhuo+d IY3CI6MPx7AGe2XY09MJL46905s4AWIcjlirN3Hq8V0CNMQ8ivxQi5Z8bzCbDlsz7iLD Re/5ml49pVd6+SFVKPvhNEcfWucethTstYrvRrolnJ1aXiL/IN106t8ptfBgUnZMdMoc N8Vj/jovkjVsn2+pnO4MJDYCq2dFvStdr34DHSTE0M6GQg8uK5Sgu1NV1wMtaiI5+nLB 7gVi50xmvJN1o2ARCrO3NEtjaQdPWqTnrf7VVC9xJ6JbRAPmK7Jflp6gc/ru9AD1ilLh OGbg== 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=0bGuZUKQK/4Fjk/G/30+oJgljqYEYhyOkuurEd4dX6E=; b=OC+ska7mhP36bxfWzTHg2smyLcxyLSeGJhDoRL/5Jyl62pNlCfhUvhiHBGcpD6j8Q5 Sca7F8s2QFCSP34UzQixehKLgvOhnMKXWcPAd3aK5r0KD7p1oouopAM+pkfhbKA92eiW 2V/iYIMe2s7AvsejzKSmesb9OrJDEJY1p3PR58kLk0528PkJKKvP2mXcYfgUgQ97PvbG 5e61O3bKL3WwrCHTshg7dwEa88++wvRSyJ/TqzH3/oVdzcwRdfCFQj6FQQBEQFc3wAUY R04zJ7Lo6ra81n6ALHIPvKabUGiscaelWU60matP8KpISpmw+tYVMuCgZ3uVgqxfdeSV k/vg== X-Gm-Message-State: APjAAAUkQPYhpgaM38fCyVol1XEXHEAtQvfHEZga6nhbG5pwtL5R5qWy Je2H41lxqH8LHKkqBF2anQzTJ4SuS6M= X-Google-Smtp-Source: APXvYqz+G6JWNKXX+36jzwr/MpgY6KzqZqEWo+kR+OeWneWqGOSDFm4xKfxd7yGXQEowHvNJBEajag== X-Received: by 2002:a6b:e61a:: with SMTP id g26mr21285855ioh.300.1561479820309; Tue, 25 Jun 2019 09:23:40 -0700 (PDT) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id o7sm13185161ioo.81.2019.06.25.09.23.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Jun 2019 09:23:39 -0700 (PDT) Received: by pryzbyj (Postfix, from userid 1000) id AC3978006DE; Tue, 25 Jun 2019 11:23:38 -0500 (CDT) Date: Tue, 25 Jun 2019 11:23:38 -0500 From: Justin Pryzby To: Hugh Ranalli Cc: pgsql-performance@lists.postgresql.org Subject: Re: Perplexing, regular decline in performance Message-ID: <20190625162338.GF18602@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.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Tue, Jun 25, 2019 at 11:49:03AM -0400, Hugh Ranalli wrote: > I'm hoping people can help me figure out where to look to solve an odd > PostgreSQL performance problem. What kernel? Version? OS? If Linux, I wonder if transparent hugepages or KSM are enabled ? It seems possible that truncating the table is clearing enough RAM to mitigate the issue, similar to restarting the DB. tail /sys/kernel/mm/ksm/run /sys/kernel/mm/transparent_hugepage/khugepaged/defrag /sys/kernel/mm/transparent_hugepage/enabled /sys/kernel/mm/transparent_hugepage/defrag https://www.postgresql.org/message-id/20170718180152.GE17566%40telsasoft.com 11.2 would have parallel query, and enabled by default. Are there other settings you've changed (or not changed)? https://wiki.postgresql.org/wiki/Server_Configuration It's possible that the "administrative" queries are using up lots of your shared_buffers, which are (also/more) needed by the customer-facing queries. I would install pg_buffercache to investigate. Or, just pause the admin queries and see if that the issue goes away during that interval ? SELECT 1.0*COUNT(1)/sum(count(1))OVER(), COUNT(1), COUNT(nullif(isdirty,'f')), datname, COALESCE(c.relname, b.relfilenode::text), d.relname TOAST, 1.0*COUNT(nullif(isdirty,'f'))/count(1) dirtyfrac, avg(usagecount) FROM pg_buffercache b JOIN pg_database db ON b.reldatabase=db.oid LEFT JOIN pg_class c ON b.relfilenode=pg_relation_filenode(c.oid) LEFT JOIN pg_class d ON c.oid=d.reltoastrelid GROUP BY 4,5,6 ORDER BY 1 DESC LIMIT 9; Could you send query plan for the slow (customer-facing) queries? https://wiki.postgresql.org/wiki/Slow_Query_Questions#EXPLAIN_.28ANALYZE.2C_BUFFERS.29.2C_not_just_EXPLAIN > A bit of background: We have a client with a database of approximately 450 > GB, that has a couple of tables storing large amounts of text, including > full HTML pages from the Internet. Last fall, they began experiencing > dramatic and exponentially decreasing performance. We track certain query > times, so we know how much time is being spent in calls to the database for > these functions. When this began, the times went from about an average of > approximate 200 ms to 400 ms, rapidly climbing each day before reaching 900 > ms, figures we had never seen before, within 4 days, with no appreciable > change in usage. It was at this point that we restarted the database server > and times returned to the 400 ms range, but never back to their > long-running original levels. From this point onward, we had to restart the > database (originally the server, but eventually just the database process) > every 3-4 days, otherwise the application became unusable. > > As they were still on PostgreSQL 8.2, we persuaded them to finally > undertake our long-standing recommendation to upgrade, as there was no > possibility of support on that platform. That upgrade to 11.2 was completed > successfully in mid-May, and although times have not returned to their > original levels (they now average approximately 250 ms), the application > overall seems much more responsive and faster (application servers were not > changed, other than minor changes --full text search, explicit casts, > etc.-- to conform to PostgreSQL 11's requirements). > > What we continued to notice was a milder but still definite trend of > increased query times, during the course of each week, from the mid to high > 200 ms, to the high 300 ms to low 400 ms. Some years ago, someone had > noticed that as the number of "raw_page" columns in a particular table > grew, performance would decline. They wrote a script that once a week locks > the table, deletes the processed large columns (they are not needed after > processing), copies the remaining data to a backup table, truncates the > original table, then copies it back. When this script runs we see an > immediate change in performance, from 380 ms in the hour before the drop, > to 250 ms in the hour of the drop. As rows with these populated columns are > added during the course of a week, the performance drops, steadily, until > the next week's cleaning operation. Each week the performance increase is > clear and significant. > > What is perplexing is (and I have triple checked), that this table is *not* > referenced in any way in the queries that we time (it is referenced by > ongoing administrative and processing queries). The operation that cleans > it frees up approximately 15-20 GB of space each week. Our system > monitoring shows this change in free disk space, but this is 20 GB out of > approximately 300 GB of free space (free space is just under 40% of volume > size), so disk space does not seem to be an issue. The table in question is > about 21 GB in size, with about 20 GB in toast data, at its largest. > > Even odder, the queries we time *do* reference a much larger table, which > contains very similar data, and multiple columns of it. It is 355 GB in > size, with 318 GB in toast data. It grows continually, with no cleaning. > > If anyone has any suggestions as to what sort of statistics to look at, or > why this would be happening, they would be greatly appreciated.