From: Alvaro Herrera <alvherre@alvh.no-ip.org>
To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
Cc: Andres Freund <andres@anarazel.de>
Cc: Marco Nenciarini <marco.nenciarini@2ndquadrant.it>
Cc: Petr Jelinek <petr.jelinek@2ndquadrant.com>
Cc: Thomas Munro <thomas.munro@enterprisedb.com>
Cc: Simon Riggs <simon@2ndquadrant.com>
Cc: PostgreSQL-development <pgsql-hackers@postgresql.org>
Subject: Re: [PATCH] Logical decoding of TRUNCATE
Date: Thu, 5 Apr 2018 14:07:12 -0300
Message-ID: <20180405170712.av633jvnnizmd5sn@alvherre.pgsql> (raw)
In-Reply-To: <2db06ddb-eb96-519a-4a83-59cf8eb9be01@2ndquadrant.com>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: alvherre@alvh.no-ip.org, peter.eisentraut@2ndquadrant.com, andres@anarazel.de, marco.nenciarini@2ndquadrant.it, petr.jelinek@2ndquadrant.com, thomas.munro@enterprisedb.com, simon@2ndquadrant.com, pgsql-hackers@postgresql.org
Subject: Re: [PATCH] Logical decoding of TRUNCATE
In-Reply-To: <20180405170712.av633jvnnizmd5sn@alvherre.pgsql>
References: <2db06ddb-eb96-519a-4a83-59cf8eb9be01@2ndquadrant.com> <20180405170712.av633jvnnizmd5sn@alvherre.pgsql>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox