PostgreSQL SHOW TABLES Equivalent (psql)

MySQL and MariaDB have a SHOW TABLES statement, which outputs a list of tables and views in a database. PostgreSQL doesn’t have a SHOW TABLES statement, but it does have a command that produces a similar result.

In Postgres, you can use the \dt command to show a list of tables. This is a psql command (psql is the interactive terminal for PostgreSQL).

Example

Here’s an example of listing all tables in PostgreSQL:

\dt

Result:

              List of relations
 Schema |       Name       | Type  |  Owner   
--------+------------------+-------+----------
 public | albums           | table | barney
 public | artists          | table | barney
 public | customers        | table | barney
 public | employees        | table | barney
 public | genres           | table | barney
 public | owners           | table | postgres
 public | petbyid          | table | postgres
 public | pets             | table | postgres
 public | pets2            | table | postgres
 public | pets3            | table | postgres
 public | petstypesowners  | table | postgres
 public | petstypesowners2 | table | postgres
 public | pettypecount     | table | postgres
 public | pettypes         | table | postgres
 public | students         | table | barney
 public | t1               | table | barney
 public | teachers         | table | barney
(17 rows)

In this case, it’s displaying all tables.

We could have used \d without the t if required. Using \d alone is the equivalent of using \dtvmsE which shows a list of all visible tables, views, materialised views, sequences and foreign tables. The t in the \dt is what limits the output to just tables.

Specify a Table Name

We can append the command with a pattern to return just those tables that match the pattern.

Example:

\dt pet*

Result:

              List of relations
 Schema |       Name       | Type  |  Owner   
--------+------------------+-------+----------
 public | petbyid          | table | postgres
 public | pets             | table | postgres
 public | pets2            | table | postgres
 public | pets3            | table | postgres
 public | petstypesowners  | table | postgres
 public | petstypesowners2 | table | postgres
 public | pettypecount     | table | postgres
 public | pettypes         | table | postgres
(8 rows)

Return More Details about the Table

We can append \dt with a + sign to get it to output more information about each table:

\dt+ pet*

Result:

                            List of relations
 Schema |       Name       | Type  |  Owner   |    Size    | Description 
--------+------------------+-------+----------+------------+-------------
 public | petbyid          | table | postgres | 0 bytes    | 
 public | pets             | table | postgres | 8192 bytes | 
 public | pets2            | table | postgres | 8192 bytes | 
 public | pets3            | table | postgres | 8192 bytes | 
 public | petstypesowners  | table | postgres | 16 kB      | 
 public | petstypesowners2 | table | postgres | 16 kB      | 
 public | pettypecount     | table | postgres | 8192 bytes | 
 public | pettypes         | table | postgres | 8192 bytes | 
(8 rows)

This time we can see the size of each table.