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 1f5X4G-0006bU-2Y for pgsql-general@arkaria.postgresql.org; Mon, 09 Apr 2018 13:42: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 1f5X4F-0005Bg-43 for pgsql-general@arkaria.postgresql.org; Mon, 09 Apr 2018 13:42:43 +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.89) (envelope-from ) id 1f5X4D-0005BX-8I for pgsql-general@lists.postgresql.org; Mon, 09 Apr 2018 13:42:42 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f5X49-0008T8-QV for pgsql-general@lists.postgresql.org; Mon, 09 Apr 2018 13:42:39 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id A1201213DB; Mon, 9 Apr 2018 09:42:36 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Mon, 09 Apr 2018 09:42:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; bh=LWK+QO8k/1ZKMoiRAk0T6b+MUk5RX UecQLTqMO+lJ2M=; b=e6tH0C3BcKKGT3UummpaZwURq6EnaK5+A4QcehvVrl/IQ voVsUMkGDxmhon4ODa8wP7J8kZIKaIb99ttrmyd2bQ9KTyMn86NEfBZx6cg0txMg Tlmgx2v4rwFI42hJNmuTumzsdekegw2xnKnCOPLv4/vMXzQUKiMK4CWNfx8b/kNc mNhFKCHYzF5cEmFKFUbQrk3lXOz2x7yO9uyfjgTEkVAtLJAvMiqLLc8hDE2rphp9 +4KvOpIEkMaQQrZy6+nwwcO5SnwtJ27F2NWk0V1TD7Cdbb4ps7o8k8MRb4fBYOZW fv8XUZKzO9HcgSYTnL/8J2G2AdS941HUNJ7GBJhMA== 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-sender:x-me-sender:x-sasl-enc; s=fm2; bh=LWK+QO 8k/1ZKMoiRAk0T6b+MUk5RXUecQLTqMO+lJ2M=; b=mVEpSLyWHHh3C+9ReUlHYZ FxvjxI97fQGXHPoqqE0PNkjCXifK0j5wgokfMLbEffqHlVcMrWGid14K00uch1J0 aJ+G+5WKsjSuOOP6e0ZpV/ZaHlVlEVs+gOGMB6KpSXtc1NczfavdBbDzlKRjFyd6 4sOnlPzsn5Bog4ybzZ8kt6YGArbemr5J2m/fbs2SS/sk4smvGxx4fDWBzYquNzSK zZOuZ+vwxYnyMugf+klxaekyOn9AeU958FhCuuOe+beiQ9H/8jk7OEx2pw1FORHf lFfAeZWsDXtKJD/CKVIKaEfT8O4wRknH73jC04oDop5WcLpKX8qxq51rXHwlzn2w == X-ME-Sender: Received: from [192.168.1.2] (71-35-123-124.tukw.qwest.net [71.35.123.124]) by mail.messagingengine.com (Postfix) with ESMTPA id 14F47E5082; Mon, 9 Apr 2018 09:42:35 -0400 (EDT) Subject: Re: pg_stat_all_tables not updated when VACUUM ANALYZE execution finishes To: Sebastien Arod , pgsql-general@lists.postgresql.org References: From: Adrian Klaver Message-ID: <21460d07-3dd0-cce1-8201-883cb1fa0a76@aklaver.com> Date: Mon, 9 Apr 2018 06:42:35 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 04/09/2018 03:37 AM, Sebastien Arod wrote: > Hi, > > I face a surprising behaviour with VACUUM ANALYZE. > > For a table with a structure like like this (and few records): > create table my_table ( >     my_column numeric > ); > > When I run the following: > VACUUM ANALYZE my_table; > SELECT relname, last_analyze, last_vacuum FROM pg_stat_all_tables where > relname='my_table'; > > The select returns null values for last_analyze and last_vacuum. > > However if I wait a little between the end of VACUUM command and the > execution of the select the last_xxx columns have non null values. > > So it looks like something is done asynchronously here but I'm not sure > what? https://www.postgresql.org/docs/10/static/monitoring-stats.html 28.2.2. Viewing Statistics "When using the statistics to monitor collected data, it is important to realize that the information does not update instantaneously. Each individual server process transmits new statistical counts to the collector just before going idle; so a query or transaction still in progress does not affect the displayed totals. Also, the collector itself emits a new report at most once per PGSTAT_STAT_INTERVAL milliseconds (500 ms unless altered while building the server). So the displayed information lags behind actual activity. However, current-query information collected by track_activities is always up-to-date. " > * Is it the vacuum itself that run asyncrhonously or the update of or > the content of the pg_stat_all_tables view? > * If I execute another query right after "VACUUM ANALYZE" is it expected > that this other query will benefit from the analyze done in the VACUUM > ANALYZE call? > * Is this a bug or a normal behaviour? (I'm using postgresql 9.6) > * Is there a way to wait for pg_stat_all_tables to be up to date? To > give a bit of context I was planning to use this information in the > assertion part of a test case I wrote to check vacuum were executed as > expected but my test is flaky because of this behaviour. > > > -Seb > > -- Adrian Klaver adrian.klaver@aklaver.com