Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eKmd2-0004eM-NZ for pgsql-bugs@arkaria.postgresql.org; Fri, 01 Dec 2017 14:49:24 +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 1eKmd1-0004xR-DA for pgsql-bugs@arkaria.postgresql.org; Fri, 01 Dec 2017 14:49:23 +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.84_2) (envelope-from ) id 1eKmd1-0004xG-4V for pgsql-bugs@lists.postgresql.org; Fri, 01 Dec 2017 14:49:23 +0000 Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eKmcy-0008W4-34 for pgsql-bugs@postgresql.org; Fri, 01 Dec 2017 14:49:21 +0000 Received: by mail-wr0-x243.google.com with SMTP id v22so10386295wrb.0 for ; Fri, 01 Dec 2017 06:49:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=t2pAGM3wCqtvMdrDcKK/d7D5IXhxclkNyiOYtIIEuXM=; b=qkfElMWjoN3d/O+WW+Xl+KR3YJNaTudPqDZinNvy8Ei0LIYPRZcalSirTx/xmexBvO QkFBRBFdgvCYEPKm6qCfHfWehzqHnWQQF+AY96SbUKUwEFXvgENbbHRDN1aUdTq+GqPH JNPq1uEIMxg3ScN/sJE2IsQ573ZzTRrof3QBWxMDsP1cd70Hgoq4PqPlUKkG5M+niyM9 k/XYYZxfBJScBxyt2/planecZi0+3hYHCLKrMLQpeIEH2fZ2EAOpNzzajLIClDzq//Y1 1yHDYTT6ihtO2RZv18AOQP7kRN13RmPBPuUDIcQYoVTEEw/MoQZU1I7cb0tqzoLzDPjC 6a+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=t2pAGM3wCqtvMdrDcKK/d7D5IXhxclkNyiOYtIIEuXM=; b=AsIxPhBf0wEM1dQMeE0s7clRzQpjTL8gnMtRUNXaiynHdW510e5fys9H9I876WN6Bx 6TFDDL/pXO9Ak33iQuSKVC39m4suvuhXEmQxm86Cuo/O9dsoam2tGwWVBVEcmAmM76m0 +iGfjztARs7jJR8E/un6ejfgoP7Sutdzd5c0pv9/azic6r9s5RXWq1sIvMFsZxUQcEfW cJ3KELPEOT5K69aiadDZqwsO7a/paKOEvwYEUs3xXOtxMPDvjaVPQ9cCLIR1WCH2b/o+ eEptqa9HtK4LKrji3bd6ytMdC7bPJDMvMRFyqsMZzsbJ2C78sezMih9fIQGZ4XQxbEAS Y24w== X-Gm-Message-State: AJaThX6Gnvp24jf02dpDxHIww0k01LQx5UsZilAf8ZFXHhDr0vfFUFWJ c/06HvN/ugD4RnuFOZiM0Hkf/lBki3/ExKyH58pMJsk70eTzXOavEzZmLq8vvOiTZVZCJklZcLM ZQMJUU7O2NVca3NxyM84JKLwN13E+e/Fg0YY6a8dBndpiBsBxfVjTTWm0dzOEStz2d5OsuWH3t2 x7jzFT X-Google-Smtp-Source: AGs4zMbXzXqAzupxzpY5outKv3A9+2fMMS1n2RsIUMLaXFaMhs9u58H0vVacruWYhS1Hnx9S431ozA== X-Received: by 10.223.138.246 with SMTP id z51mr5574272wrz.152.1512139757662; Fri, 01 Dec 2017 06:49:17 -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 l9sm4645270wrf.70.2017.12.01.06.49.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Dec 2017 06:49:16 -0800 (PST) Subject: Re: BUG #14938: ALTER TABLE hang/ poor performance To: dipesh.kamdar@gmail.com, pgsql-bugs@postgresql.org References: <20171130233056.27101.86374@wrigleys.postgresql.org> From: Tomas Vondra Message-ID: Date: Fri, 1 Dec 2017 15:49:14 +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: <20171130233056.27101.86374@wrigleys.postgresql.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 12/01/2017 12:30 AM, dipesh.kamdar@gmail.com wrote: > The following bug has been logged on the website: > > Bug reference: 14938 > Logged by: Dipesh Kamdar > Email address: dipesh.kamdar@gmail.com > PostgreSQL version: 9.5.3 > Operating system: Linux > Description: > > Postgres : 9.5.3 > Kernal : 3.10.0-327.13.1.el7.x86_64 > Linux : x86_64 x86_64 x86_64 GNU/Linux > RAM 128GB > DISK : 1.5TB > 9.5.3 was released more than a year ago, you might be hitting one of the bugs fixed since then. > > We have nightly job that removed millions of records from multiple table. > > We had following approach. > 1. Delete data from table in batch of 50000 > > Problem with above approach many time autovacuum on table and delete > statement on table create deadlock. > In order to avoid above problem, we have taken following approach. > What do you mean by deadlock? Moreover, autovacuum certainly should not deadlock with anything (certainly not with DELETE). In the worst case autovacuum should cancel itself automatically. I also don't quite understand why you do the delete in batches of 50k rows, to be honest. > 1 Turn off autovacuum on table by using ALTER TABLE SET ( > autovacuum_enabled=false); > 2. Delete data from table in batch of 50000 > 3. Turn On autovacuum on table by using ALTER TABLE SET ( > autovacuum_enabled=true); > > > Problem with second approach ALTER TABLE tablename SET ( > autovacuum_enabled=FALSE) get hang very often. I am not seeing > anything pg_lock that is waiting for resource and any other process > blocking. Process manytime take 12hour , 13hours etc. Are you sure there's nothing in pg_locks? What does SELECT pg_backend_pid(); ALTER TABLE tablename SET (autovacuum_enabled=FALSE); and then in ahother session (when the ALTER TABLE gets stuck) SELECT * FROM pg_locks WHERE pid = $PID; <- pg_backend_pid SELECT * FROM pg_locks WHERE NOT granted; show? If it really does not show any waiting locks, then you'll need to inspect it using gdb. Install debuginfo packages, and then do gdb -p $PID (gdb) bt FWIW I really doubt you really neet this process of disabling/enabling autovacuum. This should work just fine with autovacuum running. > > Found article on net regarding vacuum stuck > > http://rhaas.blogspot.com/2011/03/troubleshooting-stuck-vacuums.html > That is entirely unrelated. The article is about the autovacuum process getting stuck, while you're observing ALTER TABLE getting stuck. > Database monitoring script is not reporting any waiting, pg_log is not > reporting any error or deadlock. > Is there anyway we can figure out any process is blocking or waiting for > resource etc. > My basic understanding about this ALTER TABLE SET command it updated record > in pg_classs.reloptions column. > Does ALTER TABLE SET option block complete table? > It does need a lock on the table, yes. So if there are any long-running queries accessing that table, it may need to wait for them to complete. But that should be visible in pg_locks, and you claim there's nothing (no locks waiting). regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services