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 1ga6Mv-0003Ni-E7 for pgsql-hackers@arkaria.postgresql.org; Thu, 20 Dec 2018 22:00:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ga6Ms-0000tE-Dp for pgsql-hackers@arkaria.postgresql.org; Thu, 20 Dec 2018 22:00:34 +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 1ga6Mr-0000su-V9 for pgsql-hackers@lists.postgresql.org; Thu, 20 Dec 2018 22:00:34 +0000 Received: from mail-qt1-x82c.google.com ([2607:f8b0:4864:20::82c]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ga6Mj-0007NH-K6 for pgsql-hackers@lists.postgresql.org; Thu, 20 Dec 2018 22:00:32 +0000 Received: by mail-qt1-x82c.google.com with SMTP id e5so3557262qtr.12 for ; Thu, 20 Dec 2018 14:00:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:subject:message-id:mime-version:content-disposition :content-transfer-encoding:user-agent; bh=IuKVIOHsFi4UlyicJ8yvOgxpnjZ/l+looB75C4tOlt0=; b=MUuIRZGul8LJhC1YB+1/ZSNDn3ZxisAS09Ep+sjXhQtzyvrTFaEQqguB5yqf4qQW0p Vad7xAe3NZvyrLOs0gQGOE4SEalqG9ZnlE2nqKM4M37aSIw3nO8Hwzno87Ee/RquhTfI vcKKUWSCYURr12h1suWZsYWEviWHIzX6yWi4Pb9lkVdY6BaJm/a3K/YrJmVv1EYVBCAq kIVmZagjJr2wLHPo3cOrJmkNMVWyP5QZO/GLWuix7wrjskvO71sR2IyOHtr/JsqLTq2N xzazQHv2x9ExNkiDN8eIkPoB1FY/HQoiFwkV6ybWU8l5cvVvn4Vls21qktnbeKc01nTu OyoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition:content-transfer-encoding:user-agent; bh=IuKVIOHsFi4UlyicJ8yvOgxpnjZ/l+looB75C4tOlt0=; b=YZGCEoYeLZU5MCBlkonbdVCkIwwki6RIKUIDcR6ukXxR582CJAL+QBP6COSDik0JZo gBNUh4gklWANkPnqNmZm1NFfYDoe5YH/xsKbXom7qg1PwqiLCL7GfpMClrWJlBq2jGfz IrZj8GJ5hfQpEwQE0AhjeYWIX5geVuuoKugW2OKAiUVOfYx1pONU19IGxV8LzxKnx5Vk 8vAa7uHBwM46CbzhDVPwqWyR8jbPuq8/H6OAAjrVbCBE1TPFJn0WaCL0IlMIHWuwKdHn 6XMP4MN3TvEpiMznrB1Wk9kNokQYCzFKphnJacGTo7CQnjRretp68Qf+MQV953exqo9A SfQw== X-Gm-Message-State: AA+aEWZimopJupFakl750cyAixKDoOwURINMoWbO+c9sKwgi7NT9/One ZOQNchUEa0s6WZPmtY5CB5mdC188qY8SXn5bVxDtBxeaOOEOBid1zwJgEMdP9ls+y+B5GcE2zk7 +WLHXrTs5hixuMyX4v0wen3Eu7v/0VgRj1XFRwiKXrfjnKlJM/6QD1Z20yFg5Wpl8fpVEgre8mP knmrPcjYsQBZ/jEvYG X-Google-Smtp-Source: AFSGD/VE+AqXLoCNAyxeHq6P2v4s9M5NTwDmVwkJMGoe4o0UE4z4nl/u8n/q+r4lOCUAYQuO+1QUyQ== X-Received: by 2002:ad4:510f:: with SMTP id g15mr28376797qvp.46.1545343224491; Thu, 20 Dec 2018 14:00:24 -0800 (PST) Received: from alvin.alvh.no-ip.org ([190.121.29.3]) by smtp.gmail.com with ESMTPSA id j33sm3984577qte.38.2018.12.20.14.00.23 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 20 Dec 2018 14:00:24 -0800 (PST) Received: by alvin.alvh.no-ip.org (Postfix, from userid 1000) id 2B1E584D; Thu, 20 Dec 2018 19:00:22 -0300 (-03) Date: Thu, 20 Dec 2018 19:00:22 -0300 From: Alvaro Herrera To: Pg Hackers Subject: monitoring CREATE INDEX [CONCURRENTLY] Message-ID: <20181220220022.mg63bhk26zdpvmcj@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit User-Agent: NeoMutt/20180716 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Monitoring progress of CREATE INDEX [CONCURRENTLY] is sure to be welcome, so here's a proposal. There are three distinct interesting cases. One is straight CREATE INDEX of a standalone table; then we have CREATE INDEX CONCURRENTLY; finally, CREATE INDEX on a partitioned table. Note that there's no CONCURRENTLY for partitioned tables. A non-concurrent build is a very straightforward: we call create_index, which does index_build, done. See below for how to report for index_build, which is the interesting part. I propose not to report anything else than that for non-concurrent build. There's some preparatory work that's identical than for CIC (see below). Like VACUUM, it seems a bit pointless to report an initial phase that's almost immediate, so I propose we just don't report anything until the actual index building starts. CREATE INDEX CONCURRENTLY does these things first, which we would not report (this is just like VACUUM, which only starts reporting once it starts scanning blocks): a. lock rel. No metrics to report. b. other prep; includes lots of catalog access. Unlikely to lock, but not impossible. No metrics to report. c. create_index. CIC skips index_build here, so there's no reason to report it either. We would start reporting at this point, with these phases: 1. WaitForLockers 1. Report how many xacts do we need to wait for, how many are done. 2. index_build. See below. 3. WaitForLockers 2. Report how many xacts do we need to wait for, how many are done. 4. validate_index. Scans the whole rel again. Report number of blocks scanned. 5. wait for virtual XIDs. Like WaitForLockers: report how many xacts we need to wait for, how many are done. We're done. (Alternatively, we could have an initial "prep" phase for a/b/c for the concurrent case and a/b for non-concurrent. I'm just not sure it's useful.) index_build ----------- The actual index building is an AM-specific undertaking, and we report its progress separately from the AM-agnostic code. That is, each AM has freedom to define its own list of phases and counters, separate from the generic code. This avoids the need to provide a new AM method or invoke callbacks. So when you see that CREATE_INDEX_PHASE is either "index build" you'll have a separate BTREE_CREATE_PHASE value set to either "scanning heap" or "sorting" or "building upper layers"; equivalently for other AMs. Partitioned indexes ------------------- For partitioned indexes, we only have the index build phase, but we repeat it for each partition. In addition to the index_build metrics described above, we should report how many partitions we need to handle in total and how many partitions are already done. (I'm avoiding getting in the trouble of reporting *which* partition we're currently handling and have already handled.) Thoughts? -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services