Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jgskJ-0005Fe-Se for pgsql-general@arkaria.postgresql.org; Thu, 04 Jun 2020 16:29:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jgskI-0002Oz-Ml for pgsql-general@arkaria.postgresql.org; Thu, 04 Jun 2020 16:29:34 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jgskG-0002Lj-VF for pgsql-general@lists.postgresql.org; Thu, 04 Jun 2020 16:29:34 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jgskD-0001iZ-TL for pgsql-general@lists.postgresql.org; Thu, 04 Jun 2020 16:29:31 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id A1A645C0080; Thu, 4 Jun 2020 12:29:28 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 04 Jun 2020 12:29:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm3; bh=x s8bK+U7jEzUK3nXZzHC8hP931RxPDCO9pXhaRXdOLc=; b=Qe+QGi+HZSvvpB5Ez /ynDWQAZNDdyGr+TLPc8O7ah2WbYqMphrt5oWx2XqFKfdW7uU6VMYBpNMXMK6Ubr G7zjHOzpCpSxT1k69PedqwxX/bGXqqwKnUijwYNb0veNor3mmOKVFD0Kv9b2lM4o QCV8ATH0j6QDJkraQQjBTGz0tmgluGeviLw0PAM5yq8iYjGI9yBzOmnY6P7tTfyr C7r8AYC0ndd2KlbdiKqbQ4TX5uf6uTByAcq5JGzaLVM0NAjIsKJngrBgkD2LztVJ 6hLKknqSK9Hh0KnJO1PjuLUDHFFCXRFpSD6Rv61t7J8uiC9Q9BnaI3OXcZW8F6a6 uWEFA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=xs8bK+U7jEzUK3nXZzHC8hP931RxPDCO9pXhaRXdO Lc=; b=oDk8TQvthSO1jHyzl6lyvNVOx9cLIXk9Ui4D/B2tHLrDNiS1bGxdLe9// 84lCSRUbiiXzNUFgxPJKjINDFpjamr3k/4r+fDMqEAD/haDKYViV9Iz6zs37yKfV mA27K9hbsvdn2Y5weuVxdL4foiv0Xd6uR51WSgsnnzfXH3762n5sW34rOmPGQxuQ xXwK2aN+R9RS9sqnTHVJsM6A/Kmre24Z150W90JgdDD7bkCLP9EILm4uBDBWp473 y+XoRHxtCGUsZ4Ru9Th8W4hzAzd2dXWcYbdJv6TXG0GTRJzxK4mccH8voSaM7GFa bLepmO8zyQI+U0Kd37ploTrZwLjQg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduhedrudeguddgleefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefuvfhfhffkffgfgggjtgfgsehtje ertddtfeejnecuhfhrohhmpeetughrihgrnhcumfhlrghvvghruceorggurhhirghnrdhk lhgrvhgvrhesrghklhgrvhgvrhdrtghomheqnecuggftrfgrthhtvghrnhepudduvdefvd ejueegueefhfdtudekjeetvedugefgffetgeffgeehgefhheffleelnecuffhomhgrihhn pehsthgrtghkvgigtghhrghnghgvrdgtohhmpdguvghpvghsiidrtghomhenucfkphepje ehrddujedvrdehrddvfedunecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehm rghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomh X-ME-Proxy: Received: from [192.168.1.3] (75-172-5-231.tukw.qwest.net [75.172.5.231]) by mail.messagingengine.com (Postfix) with ESMTPA id 2AB65328005E; Thu, 4 Jun 2020 12:29:28 -0400 (EDT) Subject: Re: Index no longer being used, destroying and recreating it restores use. To: Koen De Groote , pgsql-general@lists.postgresql.org References: From: Adrian Klaver Message-ID: <0ac3b92f-d4da-5b10-ac11-a73b4c4116a3@aklaver.com> Date: Thu, 4 Jun 2020 09:29:27 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 6/4/20 8:37 AM, Koen De Groote wrote: > Greetings, > > The following is using version 11.2 of PostgreSQL. > > I've got a table with about 30 million rows and a particular index that > up until recently was actively being used. > > And then it stopped being used and the query that the index was made > for, is now doing sequential scans. Did you ANALYZE the table at that point? > > Deleting the index and creating it again, seems to fix the problem. The > new index, which is identical in composition, is being used and the > query in question no longer uses sequential scans. > > > It's the exact same query and the index is identical in composition. Yet > after a while the database stops using it. I'd like to find out why that > is and how to prevent it. > > > Also, I'm assuming this is the correct list for such a question? > > > In the past, I had asked this somewhere else, but then no longer had > time to spend on it: https://dba.stackexchange.com/questions/264237/ > > Some data I gathered then: > > 1. Size of the index not being used is 101MB. > 2. Size of the index being used is 16MB. > > The query takes the form of: > > "select * from myTable where bool1 = true and bool2 = false and > timestamp <= ('timestampField'::timestamp without time zone) order by > stringField asc, id asc limit 100 offset 30000;" > > 30000 is an example value. > # > > Here is the "explain analyze" for index used: > https://explain.depesz.com/s/H5X9y > > # > > Here is the "explain analyze" for index not used: > https://explain.depesz.com/s/n6bP > > > And I'm frankly stumped.An index growing from 16MB to 101MB isn't that > big of an increase, I would think? Is that the reason it's no longer > being used? Or is something else going on here? > > The entire database, in which this table belongs, undergoes a "vacuum > analyze" every single night, which takes about 8 minutes. Do I perhaps > need to do something additional in terms of cleanup/maintenance? > > I've tried altering statistics, to very large values even, but no > changes there either. > > Any help or suggestion would be appreciated. > > Kind regards, > Koen De Groote > -- Adrian Klaver adrian.klaver@aklaver.com