Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f48M5-00052W-DR for pgsql-hackers@arkaria.postgresql.org; Thu, 05 Apr 2018 17:07:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f48M4-0002xE-Bd for pgsql-hackers@arkaria.postgresql.org; Thu, 05 Apr 2018 17:07:20 +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.89) (envelope-from ) id 1f48M3-0002x4-Fu for pgsql-hackers@lists.postgresql.org; Thu, 05 Apr 2018 17:07:20 +0000 Received: from new1-smtp.messagingengine.com ([66.111.4.221]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f48M0-0002VD-2H for pgsql-hackers@postgresql.org; Thu, 05 Apr 2018 17:07:18 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailnew.nyi.internal (Postfix) with ESMTP id 31CFDA4C; Thu, 5 Apr 2018 13:07:15 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Thu, 05 Apr 2018 13:07:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:subject:to :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=du6WEy8u1CIHhrYGg 72t4sFwImfH3PLulNoehXEB4Sg=; b=FN4NiVTmzCbgnx7vBGcnQpqnzyC/Bv/2o 9CjgPEON+ijq63GT/VvqHCtfFRWNuQysXkeEsoXOfy3ObKkIHkCraldC6a7PmhwC It/ox8El9CB/LYHopt8uOxJcIsvW2T9zHcG+7EWI9qTBlbEmcKS2QXrjEKZ2SRVY yPrMhx5am2AmSo4IZh2MyfypdJ/5DSwqxVu4dmCfbWfWCttsic7A40nplmjLh8zJ /aWy+nYWrK3x7yy3YPaG2R6u+GEmIQn25Lu7UciaPU+2xsSJOwpnotxQwNWbU5RQ 10Yrr+t0jjsLlurEdMttXOb1aygzte522wDIZwC97MZWU3ZLkQbEw== X-ME-Sender: Received: from alvin.alvh.no-ip.org (unknown [179.56.29.253]) by mail.messagingengine.com (Postfix) with ESMTPA id 7FB0410256; Thu, 5 Apr 2018 13:07:14 -0400 (EDT) Received: by alvin.alvh.no-ip.org (Postfix, from userid 1000) id E157D71B; Thu, 5 Apr 2018 14:07:12 -0300 (-03) Date: Thu, 5 Apr 2018 14:07:12 -0300 From: Alvaro Herrera To: Peter Eisentraut Cc: Andres Freund , Marco Nenciarini , Petr Jelinek , Thomas Munro , Simon Riggs , PostgreSQL-development Subject: Re: [PATCH] Logical decoding of TRUNCATE Message-ID: <20180405170712.av633jvnnizmd5sn@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <2db06ddb-eb96-519a-4a83-59cf8eb9be01@2ndquadrant.com> User-Agent: NeoMutt/20170306-137-4415bd-dirty (1.8.0) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This sounds like a good approach. > +static void > +pg_decode_truncate(LogicalDecodingContext *ctx, ReorderBufferTXN *txn, > + int nrelations, Relation relations[], ReorderBufferChange *change) > +{ > + for (i = 0; i < nrelations; i++) > + { > + Oid relid = RelationGetRelid(relations[i]); > + > + if (i > 0) > + appendStringInfoString(ctx->out, ", "); > + > + appendStringInfoString(ctx->out, > + quote_qualified_identifier( > + get_namespace_name(get_rel_namespace(relid)), > + get_rel_name(relid))); Note that you start the loop having the Relation; yet you go extra length to grab the relnamespace and relname from syscache instead of just relations[i]->rd_rel->relname etc. pgoutput doesn't do it that way, so it doesn't affect logical replication, but I think it's best not to create awkward code in test_decoding, since it's so widely copied. > + else if (info == XLOG_HEAP_TRUNCATE) > + { > + xl_heap_truncate *xlrec = (xl_heap_truncate *) rec; > + > + if (xlrec->flags & XLH_TRUNCATE_CASCADE) > + appendStringInfo(buf, "cascade "); > + if (xlrec->flags & XLH_TRUNCATE_RESTART_SEQS) > + appendStringInfo(buf, "restart_seqs "); > + appendStringInfo(buf, "nrelids %u", xlrec->nrelids); > + /* skip the list of relids */ > + } Maybe not a big deal, but for future pg_waldump users I'm sure it'll be nice to have the OIDs here. > +void > +ExecuteTruncateGuts(List *explicit_rels, List *relids, List *relids_logged, > + DropBehavior behavior, bool restart_seqs) > +{ Please add a comment atop this function. > + /* > + * Write a WAL record to allow this set of actions to be logically decoded. > + * > + * Assemble an array of relids so we can write a single WAL record for the > + * whole action. > + */ > + if (list_length(relids_logged) > 0) > + { > + xl_heap_truncate xlrec; > + int i = 0; I wonder if this should happen only if logical decoding? (Maybe it already occurs because relids_logged would be empty? Worth a comment in that case) -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services