Re: [Proposal] Add \dAt [AMPTRN [TBLPTRN]] to list tables by Table Access Method in psql

From: Mahendra Singh Thalor <mahi6run(at)gmail(dot)com>
To: Srinath Reddy <srinath2133(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [Proposal] Add \dAt [AMPTRN [TBLPTRN]] to list tables by Table Access Method in psql
Date: 2025-04-15 09:52:20
Message-ID: CAKYtNApLpP-NNDm-LeOAqXNSyhh2TAW=TfsWccUEUOaer8GZAQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, 15 Apr 2025 at 14:27, Srinath Reddy <srinath2133(at)gmail(dot)com> wrote:
>
> Hi all,
>
> I'd like to propose adding a new `psql` meta-command:
>
> \dAt [AMPTRN [TBLPTRN]]
>
> This would list all user tables that are using a specific Table Access Method (TAM), optionally filtered by table name pattern.
>
> Why?
> - Table Access Methods are increasingly used.
> - There's currently no native `\d`-style way to explore which tables are using a given TAM.
> - Users often need to check or debug TAM-based extensions and it'd be useful to have a shortcut.
>
> Example usage:
>
> \dAt sometam -- list all tables using sometam TAM
> \dAt sometam auto% -- filter to tables starting with 'auto'
>
> Would love to hear if this sounds like a useful addition — if so, I’d be happy to work on a patch. Also, please let me know if something similar has been discussed before.

I think we can get both the details by SELECT command. Additionally,
this info should be visible by the admin only because there is no use
case for the user to know all the tables from one TAM.

postgres=# select * from pg_am;
oid | amname | amhandler | amtype
------+--------+----------------------+--------
2 | heap | heap_tableam_handler | t
403 | btree | bthandler | i
405 | hash | hashhandler | i
783 | gist | gisthandler | i
2742 | gin | ginhandler | i
4000 | spgist | spghandler | i
3580 | brin | brinhandler | i
(7 rows)

postgres=#
postgres=# select relname from pg_class where relam = (select relam
from pg_am where amname = 'heap');
relname
------------------------------------------------
test
pg_statistic
pg_type
pg_toast_1255
pg_toast_1255_index
pg_toast_1247
pg_toast_1247_index
pg_toast_2604
pg_toast_2604_index
pg_toast_2606
pg_toast_2606_index
pg_toast_2610
pg_toast_2610_index
pg_toast_2612
-------------------------

In the above command, we can add FILTER also to SELECT only pattern
matching table only.

--
Thanks and Regards
Mahendra Singh Thalor
EnterpriseDB: http://www.enterprisedb.com

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrei Lepikhov 2025-04-15 10:00:53 Re: A modest proposal: make parser/rewriter/planner inputs read-only
Previous Message Ilia Evdokimov 2025-04-15 09:44:13 Re: Add estimated hit ratio to Memoize in EXPLAIN to explain cost adjustment