Re: [patch] Have psql's \d+ indicate foreign partitions

From: Justin Pryzby <pryzby(at)telsasoft(dot)com>
To: Ian Lawrence Barwick <barwick(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [patch] Have psql's \d+ indicate foreign partitions
Date: 2022-10-24 13:03:24
Message-ID: 20221024130323.GB16921@telsasoft.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Oct 24, 2022 at 09:44:18PM +0900, Ian Lawrence Barwick wrote:
> Recently I have been working a lot with partitioned tables which contain a mix
> of local and foreign partitions, and find it would be very useful to be able to
> easily obtain an overview of which partitions are foreign and where they are
> located.

> Partitions: parttest_10_0 FOR VALUES WITH (modulus 10, remainder 0),
> parttest_10_1 FOR VALUES WITH (modulus 10, remainder 1), server: "fdw_node2",

> which is much more informative, albeit a little more cluttered, but

> @@ -3445,6 +3451,10 @@ describeOneTableDetails(const char *schemaname,
> if (child_relkind == RELKIND_PARTITIONED_TABLE ||
> child_relkind == RELKIND_PARTITIONED_INDEX)
> appendPQExpBufferStr(&buf, ", PARTITIONED");
> + else if (child_relkind == RELKIND_FOREIGN_TABLE && is_partitioned)
> + appendPQExpBuffer(&buf, ", server: \"%s\"", PQgetvalue(result, i, 4));
> + else if (child_relkind == RELKIND_FOREIGN_TABLE && !is_partitioned)
> + appendPQExpBuffer(&buf, " (server: \"%s\")", PQgetvalue(result, i, 4));
> if (strcmp(PQgetvalue(result, i, 2), "t") == 0)
> appendPQExpBufferStr(&buf, " (DETACH PENDING)");
> if (i < tuples - 1)

To avoid the clutter that you mentioned, I suggest that this should show
that the table *is* foreign, but without the server - if you want to
know the server (or its options), you can run another \d command for
that (or run a SQL query).

That's similar to what's shown if the child is partitioned: a suffix
like ", PARTITIONED", but without show the partition strategy.

I had a patch to allow \d++, and maybe showing the foreign server would
be reasonable for that. But the patch got closed, evidently lack of
interest.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Aleksander Alekseev 2022-10-24 13:53:20 Re: Pluggable toaster
Previous Message Nikita Malakhov 2022-10-24 12:59:44 Re: Pluggable toaster