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 1iCS2I-00075S-Ad for pgsql-general@arkaria.postgresql.org; Mon, 23 Sep 2019 17:22: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 1iCS2G-00011h-Tf for pgsql-general@arkaria.postgresql.org; Mon, 23 Sep 2019 17:22: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 1iCS2E-00011S-W1 for pgsql-general@lists.postgresql.org; Mon, 23 Sep 2019 17:22:04 +0000 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iCS26-0004Dg-LU for pgsql-general@postgresql.org; Mon, 23 Sep 2019 17:22:01 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id E3B835A7; Mon, 23 Sep 2019 13:21:52 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Mon, 23 Sep 2019 13:21:53 -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=fm1; bh=s n0idoRMXh5nBUOIZYg9f1EIxH1iV9J0JkbP4NtM3PI=; b=s9LUbvydS6A39Yj4t p+DTMyJX5tgt0f/jRvFkEX0jHf4F86rZ7aa4OjYXfMJjfqPgpq7vZqaeYOzYYLot g/8goYB5ka8HLkztOsOuccUoeI8q7MQMnIitO7uCYMVy2tYaYr0lvG9wi8GScFAs rNJ/BZpDDeD0yJDlL+YHC6TDeQ+m/E8AJ17rSJGo5RSGnWG8hhzI3RvWIMk0TaEk AA7p/jF8bbLWy4mh949E0hCh9MCjkXBo+kreaBfzT1qkc1mMpksn61IfOddP0trz OJCAuddt/Q1M/QjiLGUJHrN3eeSTQSZzolcFpR4si+2mdzhBHa7IIBAykbP+DFhY ghQCw== 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=fm3; bh=sn0idoRMXh5nBUOIZYg9f1EIxH1iV9J0JkbP4NtM3 PI=; b=en2rCqb70M+iteuQ+WTHjJa4hFn/DOfPkO5CVtNh2lZWCc5iu/eWDWATT SPmueslsWIngvaUclwzJPSF+GGf0xDq7gRsLdkOvwB77yeSqwKsI+WJS5AXTkv24 fUOefTpj0CI4GZNgwTJvh4ycPxnkScpLa4yKfN6bfup7KCllHyK718C5CsLBs0GY jAys38AhDcG9+ndcwle3iFOF5lBwNMZmb4Z4ByC+z/CRSBYP9tr77zHKVCaFwAkv akY6deh0Pd17qVe49EsHEa0CvSna69uDiRoZsx8REI1qCkfjxfZcxBZdv7K58CxC 7RxoS/mR0e37ZhFUqAccNsGxRNJ+g== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrvdekgdduudduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepuffvfhfhkffffgggjggtgfesthejredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucffohhmrghinhepphhoshhtghhrrdgvshdpphhoshhtghhrvghsqhhlrdhorhhg necukfhppeejgedrleefrddutdehrddukeeinecurfgrrhgrmhepmhgrihhlfhhrohhmpe grughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhmnecuvehluhhsthgvrhfu ihiivgeptd X-ME-Proxy: Received: from ranger.suse (74-93-105-186-washington.hfc.comcastbusiness.net [74.93.105.186]) by mail.messagingengine.com (Postfix) with ESMTPA id E4127D60073; Mon, 23 Sep 2019 13:21:51 -0400 (EDT) Subject: Re: Autovacuum lock conflict To: Christophe Escobar , pgsql-general@postgresql.org References: From: Adrian Klaver Message-ID: <831a0e2e-e6b2-e12b-8ba4-bfed20a99775@aklaver.com> Date: Mon, 23 Sep 2019 10:21:50 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 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 9/23/19 8:09 AM, Christophe Escobar wrote: > Hi, > > I am using PostgreSQL 9.6.13. > > I have some questions about auto vacuums. > > I find it quite hard to have some info about vacuum locking in the > documentation, > but from what I found running the command myself is that simple vacuum > will hold a Share Update Exclusive lock. > > We are using auto vacuums on our database and recently we had an issue > when rolling out a new version of our solution. > The new version included a migration creating a new index for a big table. > > We do try to have no maintenance when migrating, thus we generally use > CREATE INDEX CONCURRENTLY to avoid locking a table for reading and > writing. > > We went across an issue with our index creation being locked by an > auto vacuum, as both processes hold a Share Update Exclusive lock. > > Thankfully for us, we run our database migration with a small lock > timeout so it was not too dangerous, but we are left with some doubt > about our "smooth" process. > > In these cases, we want to have our migration run in priority as it > blocks our release and everything that goes along. > > I've read - but I cannot find it anywhere - that a vacuum process > "should" kill itself if it finds out that it is blocking any other > query; > but only if the notice "to prevent wraparound" is not present. (have I > missed official documentation somewhere..?) It will be, courtesy of PostgreSQL Weekly News - September 22, 2019: https://www.postgresql.org/message-id/20190922194743.GA24367%40fetter.org Amit Kapila pushed: - Doc: document autovacuum interruption. It's important users be able to know (without looking at the source code) that running DDL or DDL-like commands can interrupt autovacuum which can lead to a lot of dead tuples and hence slower database operations. Reported-by: James Coleman Author: James Coleman Reviewed-by: Amit Kapila Backpatch-through: 9.4 Discussion: https://postgr.es/m/CAAaqYe-XYyNwML1=f=gnd0qWg46PnvD=BDrCZ5-L94B887XVxQ@mail.gmail.com https://git.postgresql.org/pg/commitdiff/82fa3ff867219a212a467317a77011df29cb5903 And the diff: https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=70377cf4c6bf4eb4b2d1209752a300d5f3571145 > > We would like to have inputs on how to cleanly prevent these issues in > the future. > > 1) What's the actual answer about a vacuum killing itself if it blocks > a query? Is that true? > How fast is it to kill itself? As we have a 2s lock timeout, if it > takes 5s to check that it should kill itself, we won't benefit from > this behaviour. > > 2) What can we do to prevent any concurrent index creation from being > locked out by auto vacuums? > We have thought of a dirty solution consisting of: > - disabling auto vacuums before a migration > - kill current pids with a vacuum > - do our migration > - enable back auto vacuum. > We find this solution awful, error-prone and "complex" to have. > Are there any other way except having manuals vacuum being played > during the night? > > Thanks in advance for your help, > > Regards, > -- Adrian Klaver adrian.klaver@aklaver.com