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 1j4pDp-0005um-OW for pgsql-hackers@arkaria.postgresql.org; Thu, 20 Feb 2020 17:02:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1j4pDo-0000vm-HD for pgsql-hackers@arkaria.postgresql.org; Thu, 20 Feb 2020 17:02:44 +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 1j4pDn-0000vf-Vd for pgsql-hackers@lists.postgresql.org; Thu, 20 Feb 2020 17:02:44 +0000 Received: from mail-qk1-x743.google.com ([2607:f8b0:4864:20::743]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1j4pDl-0007ut-Bk for pgsql-hackers@postgresql.org; Thu, 20 Feb 2020 17:02:42 +0000 Received: by mail-qk1-x743.google.com with SMTP id c188so4235055qkg.4 for ; Thu, 20 Feb 2020 09:02:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=smHtCnxCz/fkPSBNikwVvndrF2rSAaHwTiEIbIKUFcU=; b=di/EK62t0KBo6GcZqcRNEglvcpfA09q970V5nBYNHqWrdqhhsx1OU8Hf3S0Toft2qW xUPYAa6tWdxeZiidPmhOyOj9lKao5BPBdKQZ71tmYRcE5KcZbl3NYOOoYUq5C5iaNf3n ni/whgx0VcMuHeUrEOFrRofqfpbAFj0zX1eh092RiDSclrf2al+GZVVAOmOd6BBCFQ8L 0tjxuDvduKk5UTG065s2zXnoSDHxQ1Z6VTbaDXg6j+bTLb0bnU9EVkimHEc3KzhE+FmT MRrBeTxK3ze94HHVPcsQ/l3/72RgxkvcEPopabAb0mR7FY8QVJ86rxm8ogPIWLwhbRUY h2dQ== 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:cc:subject:message-id:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=smHtCnxCz/fkPSBNikwVvndrF2rSAaHwTiEIbIKUFcU=; b=tqa5qJAd9YYATbbCmEWdcQYRyROtDe/rKnoX5upwY2TxAblq2BBgq1OHDGRiT9gdO/ /wqdfc7RhHqO2BRbcUad5j0tJwwSn73mvrlKacCgBbUV+euK0c1+WyS1revx7BBlJjzi JtYh6GP7k/7O6oEaVn8/WLOa6BLe60G1SIacrqFng35GG9TWARe+dpd5R15qwYJEkJDQ AZnDWRX13FG6FFQqwq+JlzzFifSDxrmYRMVBbrBT4to8sknZWPy7+sIKuDbkBDFg7aQt wMBJAsnRMIasDkvAGdUOfs0KqAkX1uqPg8RQGoNNeC/ub42TzFdd9sOZ0Kycx+enh47o jz9Q== X-Gm-Message-State: APjAAAXB0ZSrf12f0eEsiqoD1lBBnWrfugoR8ndz4KgLppCG8neoCANF TqiYFgoC9SCNYaMrH7HceIoV+A== X-Google-Smtp-Source: APXvYqxLSzYTcx98DzAgXpDrsamDIpA/wtrhyfp5kHdnodcXDMs1THNmAvlzlKx84lw1ERW3OxEw4g== X-Received: by 2002:a05:620a:41b:: with SMTP id 27mr29709803qkp.349.1582218160396; Thu, 20 Feb 2020 09:02:40 -0800 (PST) Received: from nimloth.alvh.no-ip.org ([201.186.80.105]) by smtp.gmail.com with ESMTPSA id i4sm71591qkf.111.2020.02.20.09.02.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Feb 2020 09:02:38 -0800 (PST) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id 887783007E6; Thu, 20 Feb 2020 14:02:36 -0300 (-03) Date: Thu, 20 Feb 2020 14:02:36 -0300 From: Alvaro Herrera To: Justin Pryzby Cc: Masahiko Sawada , Andres Freund , Michael Paquier , pgsql-hackers@postgresql.org Subject: Re: error context for vacuum to include block number Message-ID: <20200220170236.GA16805@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200219203821.GA10914@telsasoft.com> User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is, by far, the most complex error context callback we've tried to write ... Easy stuff first: In the error context function itself, you don't need the _() around the strings: errcontext() is marked as a gettext trigger and it does the translation itself, so the manually added _() is just cruft. When reporting index names, make sure to attach the namespace to the table, not to the index. Example: case PROGRESS_VACUUM_PHASE_INDEX_CLEANUP: - errcontext(_("while cleaning up index \"%s.%s\" of relation \"%s\""), - cbarg->relnamespace, cbarg->indname, cbarg->relname); + errcontext("while cleaning up index \"%s\" of relation \"%s.%s\"", + cbarg->indname, cbarg->relnamespace, cbarg->relname); I think it would be worthwhile to have the "truncate wait" phase as a separate thing from the truncate itself, since it requires acquiring a possibly taken lock. This suggests that using the progress enum is not a 100% solution ... or maybe it suggests that the progress enum too needs to report the truncate-wait phase separately. (I like the latter myself, actually.) On 2020-Feb-19, Justin Pryzby wrote: > Also, I was thinking that lazy_scan_heap doesn't needs to do this: > > + /* Pop the error context stack while calling vacuum */ > + error_context_stack = errcallback.previous; > ... > + /* Set the error context while continuing heap scan */ > + error_context_stack = &errcallback; > > It seems to me that's not actually necessary, since lazy_vacuum_heap will just > *push* a context handler onto the stack, and then pop it back off. So if you don't pop before pushing, you'll end up with two context lines, right? I find that arrangement a bit confusing. I think it would make sense to initialize the context callback just *once* for a vacuum run, and from that point onwards, just update the errcbarg struct to match what you're currently doing -- not continually pop/push error callback stack entries. See below ... (This means you need to pass the "cbarg" as new argument to some of the called functions, so that they can update it.) Another point is that this patch seems to be leaking memory each time you set relation/index/namespace name, since you never free those and they are changed over and over. In init_vacuum_error_callback() you don't need the "switch(phase)" bit; instead, test rel->rd_rel->relkind, and if it's RELKIND_INDEX then you put the relname as indexname, otherwise set it to NULL (after freeing the previous value, if there's one). Note that with this, you only need to set the relation name (table name) in the first call! IOW you should split init_vacuum_error_callback() in two functions: one "init" to call at start of vacuum, where you set relnamespace and relname; the other function is update_vacuum_error_callback() (or you find a better name for that) and it sets the phase, and optionally the block number and index name (these last two get reset to InvalidBlkNum/ NULL if not passed by caller). I'm not really sure what this means for the parallel index vacuuming stuff; probably you'll need a special case for that: the parallel children will need to "init" on their own, right? -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services