Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eKq5G-0008MT-At for pgsql-bugs@arkaria.postgresql.org; Fri, 01 Dec 2017 18:30:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eKq5F-0007UU-Pe for pgsql-bugs@arkaria.postgresql.org; Fri, 01 Dec 2017 18:30:45 +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_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eKq5F-0007UK-Fe for pgsql-bugs@lists.postgresql.org; Fri, 01 Dec 2017 18:30:45 +0000 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eKq5C-0003i5-2x for pgsql-bugs@postgresql.org; Fri, 01 Dec 2017 18:30:45 +0000 Received: by mail-wm0-x243.google.com with SMTP id n138so5127329wmg.2 for ; Fri, 01 Dec 2017 10:30:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=aRVyhEaQgBN/IrN35/uei6jBUpeFLGgbM0ZAdlbrzaM=; b=iT8PQDlwAZd//37QPbF7VNCg9eefUyJMZPOxgIu8IVtyojdZE24NBzLU68hV7arZJe oZI1YJHYiIEdHcNna3qFmxIzvrvFuV5/g6RF2fuPgcHqzNOICdiapx3xxF9zKbQpncYC YqlTncgmt64uEBPffEl3PBt4z5bzVoasOmO3/V1DVAqHiCeEsgYYGxzUcPzdvUmvub0s YSGNqJIYMf2FZAhvPuZdAdiXd3KhKhnAQQgq5WMtDUTI+8u25ph/qr6bn4vC8JwC5389 Du0bHcDomEARadRWu2FxOTSBcYDk+x1M7k1GtKA1XwvQfGXs5fk7jLAgpVkOosfG/5zx 5xMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=aRVyhEaQgBN/IrN35/uei6jBUpeFLGgbM0ZAdlbrzaM=; b=TkpPrK21bEESGBWRwSbUoLTsKJuuEnHEKuRW8Dj3SsPkrlIlWF2vm60BSKjy9nOMO5 cmA7Dft+RxctTrpvDKgei0WB/qMqNWBTXaaNS+3DOgtCa39U2cefpRFYijiPZ6XUyjgW MLjV5e2oToqrtShda3Dd+wxenh3Z50ZdAQQ4+Igfa6D0T5oJK4O72jcciDqoJ8irvm4K IAizu5DXm5SNtMIMsqy1mcjqijPtwWFrDwP9o+m+S+81EQTLcldelvtwaOCOwjIWQU9u cdXhCHyAqik/CNpfTTJ+uY9Cw8QRdKZ6yz6sD5H6KkHC4xDt4GLyPbIzN21Y3nPa91hZ +1yg== X-Gm-Message-State: AKGB3mK64ORf8W/fVV9I+jABeH1RsT7muq/4oBiu3WRAPLJ9AAyG3CdQ JqswKs5apaEQhKpTPHmqDESeR1wyUUzg7uCZYLdHfg9yMdLpMvK/ZqtGXsJDgNlc6PXKeVkt/G7 RUEQ0ZnzcWWTJUEGkbhvss0dLEni3vWuKgewS0kac0GPZoFZFvuoGlrpiCbIlGpeVIUGAZtTHet Jk8Fz5 X-Google-Smtp-Source: AGs4zMYZvWFLx0hP1a9cT3cqmuR4dqpoC9JyoQSxuIlUYnAaH3m+FHl/wCdwOrX+Fzpy3vnE023smw== X-Received: by 10.28.69.197 with SMTP id l66mr1927696wmi.67.1512153040969; Fri, 01 Dec 2017 10:30:40 -0800 (PST) Received: from [10.137.2.19] (ip-78-102-97-226.net.upcbroadband.cz. [78.102.97.226]) by smtp.gmail.com with ESMTPSA id p17sm1840513wma.23.2017.12.01.10.30.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Dec 2017 10:30:35 -0800 (PST) Subject: Re: BUG #14938: ALTER TABLE hang/ poor performance To: Dipesh Kamdar Cc: pgsql-bugs@postgresql.org References: <20171130233056.27101.86374@wrigleys.postgresql.org> From: Tomas Vondra Message-ID: <9e33cd3a-cada-ee2d-5f4f-160be257d6a3@2ndquadrant.com> Date: Fri, 1 Dec 2017 19:30:33 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 12/01/2017 06:37 PM, Dipesh Kamdar wrote: > #1    9.5.3 was released more than a year ago, you might be hitting one > of the > bugs fixed since then. > >>>> Do you know any bug related ? > No. Considering how little we know about the issue you're observing, it's quite impossible to point to any particular bugfix. But it's a good practice to run current version, and it's rather annoying to help people only to discover they've been hitting an issue fixed ages ago. To the extent that it's likely discouraging people from investigating the bug report. > #2 What do you mean by deadlock?Moreover, autovacuum certainly should not > deadlock with anything (certainly not with DELETE) > >>>> Please take a look of SEQ >    deleting  TAB1  data of    50K   ------   T1 >    autovacuum  check TAB1      -------  T2  ( Since delete is running > skipping table ) >    delete completed    ---- T3 >     before starting next delete on same table autovacuum started on > TAB1    ---- T4 >     DELETE statement is waiting for autovacuum to release lock.     >     after some time later reported deadlock in log and killed DELETE > process. > DELETE acquires ROW EXCLUSIVE lock VACUUM acquires SHARE UPDATE EXCLUSIVE lock These two lock modes do not conflict with each other, i.e. VACUUM (or autovacuum) will not wait for DELETE (and vice versa). Perhaps you're running the DELETE in a transaction, and that transaction has acquired other (stronger) locks? Those locks will be held until the end of the transaction, but that has nothing to do with DELETE. Show us what locks the two sessions hold. > #3  I also don't quite understand why you do the delete in batches of 50k > rows, to be honest > >>> It is client facing application with close to 1.5 billion records and has multiple FK other and indexes removing again millions of record in single statement means  >      putting entire online application on fire. > OK, so you're using this to throttle the DELETE process. > #4 I am running following SQL as monitoring point of every 10min.  > Let me know if anything is missing above monitor script. > > SELECT > >   COALESCE(blockingl.relation*::*regclass*::*text,blockingl.locktype) as > locked_item, > >   now() *-* blockeda.query_start AS waiting_duration, blockeda.pid AS > blocked_pid, > >   blockeda.query as blocked_query, blockedl.mode as blocked_mode, > >   blockinga.pid AS blocking_pid, blockinga.query as blocking_query, > >   blockingl.mode as blocking_mode > > FROM pg_catalog.pg_locks blockedl > >     INNER JOIN pg_stat_activity blockeda ON blockedl.pid *=* blockeda.pid > >     INNER JOIN pg_catalog.pg_locks blockingl ON( > >                 ( (blockingl.transactionid*=*blockedl.transactionid) OR > >                (blockingl.relation*=*blockedl.relation AND > blockingl.locktype*=*blockedl.locktype) > >       ) AND blockedl.pid *!=* blockingl.pid) > >     INNER JOIN pg_stat_activity blockinga ON blockingl.pid *=* > blockinga.pid  AND blockinga.datid *=* blockeda.datid > > WHERE NOT blockedl.granted > >       AND blockinga.datname *=* current_database() > I don't care about a monitoring query that runs every 10 minutes. The deadlock detection runs after 1 second lock wait by default, which means the monitoring query has pretty much no chance of observing that. You need to simulate the issue and collect data from pg_locks while it's happening. And collect everything from pg_locks - the lock dependencies may easily be more complex. It's also a good idea to share the deadlock log message, and info what the processes were doing. > > #5 It is production , We will not able to attach process to gdb. > OK. Assuming it's a locking issue, we should be able to debug it using just the pg_locks data. > > #6 My main concern is not coming in pg_locks table.  > > Is it advice to use update statement on pg_class.reloptions column > rather than using ALTER TABLE SET option. > No. Touching the catalogs directly is pretty bad idea. The locking is there for a reason. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services