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 1h2Nd1-0006mn-6h for pgsql-hackers@arkaria.postgresql.org; Fri, 08 Mar 2019 22:06:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h2Ncy-0001wT-V0 for pgsql-hackers@arkaria.postgresql.org; Fri, 08 Mar 2019 22:06:04 +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 1h2Ncy-0001oN-Ep for pgsql-hackers@lists.postgresql.org; Fri, 08 Mar 2019 22:06:04 +0000 Received: from mail-yw1-xc44.google.com ([2607:f8b0:4864:20::c44]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h2Ncq-0006Ph-Jt for pgsql-hackers@lists.postgresql.org; Fri, 08 Mar 2019 22:06:02 +0000 Received: by mail-yw1-xc44.google.com with SMTP id k14so17500956ywe.4 for ; Fri, 08 Mar 2019 14:05:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=from:subject:to:cc:references:openpgp:autocrypt:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=Zq9KUxwMsnovCww/XcHNdsw6bC91XxNgst/QUCH3ojg=; b=mKwvbsswVISbWpII0L3ocDh9+7MZYo2YiNc2QU5twNwqHJtqJGwXSaoVexxFCLBBfT JkafDyA/rmUmT/EvrSXIqn2LsMQKIYClz3tbeRceDlhokHuoKWNZWf//mWGwjpiO/GEK 1lZW8QVBcQDJJ1/l6ZKVs3T0qqRI59GPAACQtZQWTb48ByvRsiGEkvmlzGnqDhPLgwqH 5M3Trwbu3tDpyHUVObTs1JiGkbVnGPHYfIVB4obtop3tro71C73iCH9V15w+L2fCO499 KA+wPrvaOsgbrVvqxrRxrd/Spp/6FSSV39/G38wDe1kt9nwQND78pma1ia95W/+5/fXe 3eyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:cc:references:openpgp:autocrypt :message-id:date:user-agent:mime-version:in-reply-to :content-transfer-encoding:content-language; bh=Zq9KUxwMsnovCww/XcHNdsw6bC91XxNgst/QUCH3ojg=; b=JPYsJEROAJbEaO4GyYSgH9X2Cp4oHXIavY0mTBKhm/0srWYSfu3F8r4dMvY+oVlo/1 8gXoVmIonwZA7yBkBBRUfgsXOLAhm3HUh2+W0LE4SOe1A4WkrOg06DNx/0IFNB32rc0r OTBiIcgeE6L2vWzbcI44wJvnp7K2d8dqYEogeaGaXy5MH+YU76XuzBn1ONy6Wsbs2rUP TBuBZ1eN0/oe+hwMb4Gt9fyTNJ07P8bqwjjp2EzL0FuW7q1Nb3tV3yscC3V3Sx2O6yH+ A4pvWdoyRN3S8joMDrbIY4bQ/5qjuGVtov0hG0j1IZN18HqWUV+/kchjfNDVnHEeqvgE BrcA== X-Gm-Message-State: APjAAAVLkBJHhre0hzb+Cm996T4rSk9vJh3mncoJNueOyBooyCPiQnsY 7Z9+eHBVTpt1C3FH7rSKOQ8ZQNS/UZYFOsSfQlGSfo2beu+svhcNNW9CsKCrKz2fqMkot5u8JXu iXA3zBhCQ5cuqijkpWJZVqpfkTRbvGjoiniSEM67hz4S0o0PBgFvlQnhrsyaSWZ2UsKlchp0icN Cths8lF7o2DgDWeEbpMzmz X-Google-Smtp-Source: APXvYqzVXns1OfefGMEze6t5y/DDh6MD9gTV90tvNgTf7DyCBTFfySNI3IV+HuOCZHRZbqUkVABRgw== X-Received: by 2002:a25:3f45:: with SMTP id m66mr7071127yba.238.1552082755370; Fri, 08 Mar 2019 14:05:55 -0800 (PST) Received: from [192.168.10.146] (99-10-92-30.lightspeed.rlghnc.sbcglobal.net. [99.10.92.30]) by smtp.gmail.com with ESMTPSA id x8sm7409524ywj.94.2019.03.08.14.05.53 (version=TLS1_3 cipher=AEAD-AES128-GCM-SHA256 bits=128/128); Fri, 08 Mar 2019 14:05:54 -0800 (PST) From: Andrew Dunstan X-Google-Original-From: Andrew Dunstan Subject: Re: pgsql: Improve autovacuum logging for aggressive and anti-wraparound ru To: Kyotaro HORIGUCHI , michael@paquier.xyz Cc: sawada.mshk@gmail.com, tgl@sss.pgh.pa.us, alvherre@2ndquadrant.com, sk@zsrv.org, nasbyj@amazon.com, andres@anarazel.de, robertmhaas@gmail.com, pgsql-hackers@lists.postgresql.org References: <20181005031603.GF1629@paquier.xyz> <20181005063504.GB14664@paquier.xyz> <20181009.181536.142257785.horiguchi.kyotaro@lab.ntt.co.jp> Openpgp: preference=signencrypt Autocrypt: addr=andrew.dunstan@2ndQuadrant.com; prefer-encrypt=mutual; keydata= xsBNBE7KWFkBCAClridxur2AIc7eW2AR7izbfp3EnNefie2HbLF0izW5Ik5UjX2HBXBx4syI gY6b0ugohXrr274+baoAlvSbq6cAoQuEVrk5IZFzt20b1Xkx65FwGSEj526yiKLocqkJceSq Xr9xcA5SGY+FZv441chh5SU92v4q6z+6LPpoHOh97ptAVXZYNTtU0LevyvD5lja0TzbvJm6C eFXitJfnm1pLEr0DGJCR/iUOl/N62Kh4855zZC7NHIjQHPOvV5Stz/l5ilDhvGVk+xkXFPys SjZoUr1rXhYLpiyi5sR0X9FHXT0KnGuz1F5ERO7ZTLSSQ6fJwPj6gOk9K+vvoKvoeql5ABEB AAHNL0FuZHJldyBEdW5zdGFuIDxhbmRyZXcuZHVuc3RhbkAybmRRdWFkcmFudC5jb20+wsCY BBMBAgBCAhsDBgsJCAcDAgYVCAIJCgsEFgIDAQIeAQIXgAUJDyV6hBYhBOQ+WEYd/Hy/RGkV pZn6f8tZ/DuBBQJcH/EVAh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ljbnaDbXPcnFsur1Oo9mIHFakgWgOBMuxoWfjONiLjjLh/9+ZIqSSLX Message-ID: <920b7f84-407c-005c-4b7d-e8266a17d22b@2ndQuadrant.com> Date: Fri, 8 Mar 2019 17:05:53 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 MIME-Version: 1.0 In-Reply-To: <20181009.181536.142257785.horiguchi.kyotaro@lab.ntt.co.jp> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Content-Language: en-MW List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 10/9/18 5:15 AM, Kyotaro HORIGUCHI wrote: > At Fri, 5 Oct 2018 15:35:04 +0900, Michael Paquier wrote in <20181005063504.GB14664@paquier.xyz> >> On Fri, Oct 05, 2018 at 12:16:03PM +0900, Michael Paquier wrote: >>> So, I have come back to this stuff, and finished with the attached >>> instead, so as the assertion is in a single place. I find that >>> clearer. The comments have also been improved. Thoughts? >> And so... I have been looking at committing this thing, and while >> testing in-depth I have been able to trigger a case where an autovacuum >> has been able to be not aggressive but anti-wraparound, which is exactly >> what should not be possible, no? I have simply created an instance with >> autovacuum_freeze_max_age = 200000, then ran pgbench with >> autovacuum_freeze_table_age=200000 set for each table, and also ran >> installcheck-world in parallel. This has been able to trigger the >> assertion pretty quickly. > I investigated it and in short, it can happen. > > It is a kind of race consdition between two autovacuum > processes. do_autovacuum() looks into pg_class (using a snapshot) > and vacuum_set_xid_limits() looks into relcache. If concurrent > vacuum happens and one has finished the relation, another gets > relcache invalidation and relfrozenxid is updated. If this > happens between do_autovacuum() and vacuum_set_xid_limits(), the > latter sees newer relfrozenxid than the former. The problem > happens when it moves by more than 5% of > autovacuum_freeze_max_age. > > If lazy_vacuum_rel() sees the situation, the relation is already > aggressively vacuumed by a cocurrent worker. We can just ingore > the state safely but also we know that the vacuum is useless. > > 1. Just allow the case there (and add comment). > Causes redundant anti-wraparound vacuum. > > 2. Skip the relation by the condition. > > I think that we can safely skip the relation in the > case. (attached) > > 3. Ensure that do_autovacuum always sees the same relfrozenxid > with vacuum_set_xid_limits(). > > 4. Prevent concurrent acuuming of the same relation rigorously, > somehow. > > Thoughts? > I notice that this seems never to have been acted on. I think we should apply this and remove the (confusing) message setting for the case we'll now be avoiding. If not we should at least comment there that this is a case we only expect to see in pathological cases. cheers andrew -- Andrew Dunstan https://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services