Re: ALTER TABLE SET ACCESS METHOD on partitioned tables
Justin Pryzby <pryzby@telsasoft.com>
From: Justin Pryzby <pryzby@telsasoft.com>
To: Alvaro Herrera <alvherre@alvh.no-ip.org>
Cc: Michael Paquier <michael@paquier.xyz>, Peter Eisentraut <peter@eisentraut.org>, Soumyadeep Chakraborty <soumyadeep2007@gmail.com>, Zhihong Yu <zyu@yugabyte.com>, pgsql-hackers@postgresql.org, Ashwin Agrawal <ashwinstar@gmail.com>, vanjared@vmware.com, Alexander Lakhin <exclusion@gmail.com>
Date: 2024-05-21T13:33:51Z
Lists: pgsql-hackers
It occurred to me that psql \dP+ should show the AM of partitioned
tables (and other partitioned rels).
Arguably, this could've been done when \dP was introduced in v12, but
at that point would've shown the AM only for partitioned indexes.
But it makes a lot of sense to do it now that partitioned tables support
AMs. I suggest to consider this for v17.
regression=# \dP+
List of partitioned relations
Schema | Name | Owner | Type | Table | Access method | Total size | Description
--------+----------------------+---------+-------------------+----------------+---------------+------------+-------------
public | mlparted | pryzbyj | partitioned table | | heap2 | 104 kB |
public | tableam_parted_heap2 | pryzbyj | partitioned table | | | 32 kB |
public | trigger_parted | pryzbyj | partitioned table | | | 0 bytes |
public | upsert_test | pryzbyj | partitioned table | | | 8192 bytes |
public | trigger_parted_pkey | pryzbyj | partitioned index | trigger_parted | btree | 16 kB |
public | upsert_test_pkey | pryzbyj | partitioned index | upsert_test | btree | 8192 bytes |
---
src/bin/psql/describe.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
index f67bf0b8925..22a668409e7 100644
--- a/src/bin/psql/describe.c
+++ b/src/bin/psql/describe.c
@@ -4113,7 +4113,7 @@ listPartitionedTables(const char *reltypes, const char *pattern, bool verbose)
PQExpBufferData title;
PGresult *res;
printQueryOpt myopt = pset.popt;
- bool translate_columns[] = {false, false, false, false, false, false, false, false, false};
+ bool translate_columns[] = {false, false, false, false, false, false, false, false, false, false};
const char *tabletitle;
bool mixed_output = false;
@@ -4181,6 +4181,14 @@ listPartitionedTables(const char *reltypes, const char *pattern, bool verbose)
if (verbose)
{
+ /*
+ * Table access methods were introduced in v12, and can be set on
+ * partitioned tables since v17.
+ */
+ appendPQExpBuffer(&buf,
+ ",\n am.amname as \"%s\"",
+ gettext_noop("Access method"));
+
if (showNested)
{
appendPQExpBuffer(&buf,
@@ -4216,6 +4224,9 @@ listPartitionedTables(const char *reltypes, const char *pattern, bool verbose)
if (verbose)
{
+ appendPQExpBufferStr(&buf,
+ "\n LEFT JOIN pg_catalog.pg_am am ON c.relam = am.oid");
+
if (pset.sversion < 120000)
{
appendPQExpBufferStr(&buf,
--
2.42.0
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Add information about access method for partitioned relations in \dP+
- 978f38c771fb 18.0 landed
-
Fix dumps of partitioned tables with table AMs
- f46bee346c3b 17.0 landed
-
Don't use the pg_am system catalog in new test
- 13b3b62746ec 17.0 landed
-
ALTER TABLE: rework determination of access method ID
- e2395cdbe83a 17.0 landed
-
Allow specifying an access method for partitioned tables
- 374c7a229042 17.0 landed
-
Review wording on tablespaces w.r.t. partitioned tables
- ea299d782511 15.7 landed
- e6c4e01bf440 16.3 landed
- a0390f6ca6c7 17.0 landed
- 58efabdc0ce9 12.19 landed
- 520e7afa5732 13.15 landed
- 33bfbef1d60f 14.12 landed
-
Add support for DEFAULT in ALTER TABLE .. SET ACCESS METHOD
- d61a6cad6418 17.0 landed
-
Update comment of AlterTableCmd->name in parsenodes.h
- 4f8c1e7aaf11 17.0 landed