Back to all posts

Show Tables in PostgreSQL: psql, SQL Queries, and Schema Filters

For SQL users who know MySQL's SHOW TABLES and need the PostgreSQL equivalent, in psql or in any other SQL client.

On this page

You type SHOW TABLES; out of MySQL habit, and PostgreSQL answers ERROR: unrecognized configuration parameter "tables". PostgreSQL's SHOW reads settings, not tables. In psql, list the tables with the \dt meta-command:

\dt

From any other client, such as an application or a GUI, query information_schema.tables:

SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'public'
  AND table_type = 'BASE TABLE'
ORDER BY table_name;

Every result below comes from PostgreSQL 18.6, on a database named shop. A schema is a named group of tables inside one database. The shop database has three tables in public, the default schema, and one in sales:

CREATE TABLE customers (customer_id int PRIMARY KEY, name text NOT NULL);
CREATE TABLE orders (order_id int PRIMARY KEY, customer_id int NOT NULL REFERENCES customers);
CREATE TABLE products (product_id int PRIMARY KEY, name text NOT NULL);

CREATE SCHEMA sales;
CREATE TABLE sales.invoices (invoice_id int PRIMARY KEY, order_id int NOT NULL);

Show tables in psql with \dt

\dt works only in psql. psql turns \dt into a query on the system catalog, the tables where PostgreSQL describes its own objects. Connect to the database first:

psql -U postgres -d shop

Inside psql, \l lists the databases on the server, and \c switches to another one. Then list the tables:

\dt
SchemaNameTypeOwner
publiccustomerstablepostgres
publicorderstablepostgres
publicproductstablepostgres

The invoices table is missing. Without a pattern, \dt lists only the tables of the schemas on the search path. The search path is the list of schemas where PostgreSQL looks up a table name that has no schema. By default, the search path holds public. How to Create a Database in PostgreSQL and Essential PostgreSQL Commands cover the rest of a psql session.

Tables in one schema or in every schema

To list the tables of another schema, give \dt a pattern. The pattern sales.* matches every table in sales:

\dt sales.*
SchemaNameTypeOwner
salesinvoicestablepostgres

The part after the dot matches table names, so \dt public.order* returns only the orders table.

\dt *.* matches every schema. A pattern also matches the system tables that \dt hides by default. On the shop database, \dt *.* returned 113 rows: the four tables above, 64 tables in pg_catalog, 4 in information_schema, and 41 TOAST tables in pg_toast. A TOAST table holds the large values of another table's columns.

The shop database with five schemas: public with customers, orders and products, sales with invoices, pg_catalog with 64 catalog tables, information_schema with 4 tables and pg_toast with 41 TOAST tables. The dt command without a pattern reaches public through the search path, the pattern sales.* reaches sales, and the pattern *.* reaches all five

To include the system tables without a pattern, add S: \dtS lists the tables of pg_catalog beside those of public.

Table sizes with \dt+

Add + to see how much disk space each table takes:

\dt+
SchemaNameTypeOwnerPersistenceAccess methodSizeDescription
publiccustomerstablepostgrespermanentheap8192 bytes
publicorderstablepostgrespermanentheap0 bytes
publicproductstablepostgrespermanentheap8192 bytes

Size counts the table and its TOAST table, and leaves out the table's indexes. The tables are empty. Customers and products each have a text column, and so a TOAST table, whose index takes the 8192 bytes.

List tables with a SQL query

In any client other than psql, query a catalog view, a view that reads the system catalog. information_schema.tables is the view that the SQL standard defines. To list the tables of every schema, leave out the system schemas:

SELECT table_schema, table_name
FROM information_schema.tables
WHERE table_type = 'BASE TABLE'
  AND table_schema NOT IN ('pg_catalog', 'information_schema')
ORDER BY table_schema, table_name;
table_schematable_name
publiccustomers
publicorders
publicproducts
salesinvoices

information_schema.tables also lists views, temporary tables and foreign tables, with the table_type VIEW, LOCAL TEMPORARY and FOREIGN. The condition table_type = 'BASE TABLE' keeps only the permanent tables. For the current schema only, replace the schema condition with table_schema = current_schema().

pg_tables

pg_tables is PostgreSQL's own view of the same tables. It adds the owner, the tablespace, and flags such as hasindexes:

SELECT schemaname, tablename, tableowner
FROM pg_tables
WHERE schemaname NOT IN ('pg_catalog', 'information_schema')
ORDER BY schemaname, tablename;
schemanametablenametableowner
publiccustomerspostgres
publicorderspostgres
publicproductspostgres
salesinvoicespostgres

pg_tables has no type column, so a temporary table shows up in it too, under a schema named like pg_temp_11.

Tables sorted by size

The catalog table pg_class holds every table, index and view. Join it to pg_namespace for the schema names, and sort the tables by the space they take:

SELECT n.nspname AS table_schema,
       c.relname AS table_name,
       pg_size_pretty(pg_total_relation_size(c.oid)) AS total_size
FROM pg_class c
JOIN pg_namespace n
  ON n.oid = c.relnamespace
WHERE c.relkind IN ('r', 'p')
  AND n.nspname NOT IN ('pg_catalog', 'information_schema')
ORDER BY pg_total_relation_size(c.oid) DESC, c.relname;
table_schematable_nametotal_size
publiccustomers16 kB
publicproducts16 kB
salesinvoices8192 bytes
publicorders8192 bytes

pg_total_relation_size also counts the indexes. Each table here is 8 kB larger than in \dt+, because its primary key index takes 8 kB. The relkind column is r for an ordinary table and p for a partitioned table. A partitioned table splits its rows into smaller tables, called partitions.

Partitioned tables

Add a partitioned table with one partition to the sales schema, then list the tables of sales again:

CREATE TABLE sales.events (event_date date NOT NULL) PARTITION BY RANGE (event_date);
CREATE TABLE sales.events_2026 PARTITION OF sales.events
  FOR VALUES FROM ('2026-01-01') TO ('2027-01-01');
\dt sales.*
SchemaNameTypeOwner
saleseventspartitioned tablepostgres
salesevents_2026tablepostgres
salesinvoicestablepostgres

\dt lists events as a partitioned table, and the partition events_2026 as a table. information_schema.tables and pg_tables list both as tables. To leave out the partitions, filter pg_class on relispartition, which is true for a partition:

SELECT c.relname AS table_name
FROM pg_class c
JOIN pg_namespace n
  ON n.oid = c.relnamespace
WHERE n.nspname = 'sales'
  AND c.relkind IN ('r', 'p')
  AND NOT c.relispartition
ORDER BY c.relname;
table_name
events
invoices

Views, indexes and other objects

The letter after \d names the kind of object: t stands for tables. Other letters list other kinds:

Objectspsql command
Views\dv
Materialized views\dm
Indexes\di
Sequences\ds
Foreign tables\dE
Schemas\dn

You can combine the letters: \dti lists tables and indexes together. \d alone is short for \dtvmsE: tables, views, materialized views, sequences and foreign tables in one list. List All Schemas in PostgreSQL covers \dn and its SQL equivalents.

Describe one table

\d customers describes the customers table: its columns, its indexes, and the other tables that reference it with a foreign key.

\d customers

Describe Table in PostgreSQL goes through the output.

Why \dt shows no tables

Three things hide a table from the list:

  • You are connected to another database. A connection sees one database only. In the postgres database, \dt printed "Did not find any tables." Switch with \c shop.
  • The table's schema is not on the search path. SHOW search_path; prints the search path, "$user", public by default. Use the pattern \dt sales.*. Or run SET search_path TO public, sales;. Then \dt lists invoices too.
  • You hold no privilege on the table. information_schema.tables shows only the tables you own or have a privilege on. A new role, PostgreSQL's word for a user, got 0 rows from the information_schema query above. pg_tables still listed all four tables.

Show tables in DbSchema

A table list shows no foreign keys. DbSchema reads the tables and draws them on a diagram, with a line for each foreign key. To connect to the database:

  1. Choose File → New Model, keep Connect to Database selected, and click PostgreSQL.
  2. Press Connect to PostgreSQL, fill in the connection dialog, and press Connect.
  3. In Reverse Engineer the Database, tick the schemas public and sales, and press Import.
The shop database in DbSchema: the schemas public and sales in the tree on the left and as diagram tabs, and the public diagram with customers, orders and products and a foreign key line from orders to customers

DbSchema draws each schema on a diagram of its own, so sales.invoices sits on the sales tab.

DbSchema reads the schemas into a model and changes nothing in the database. To run the queries above on the same connection, open the SQL Editor from Editor in the toolbar.

Download DbSchema at https://dbschema.com/download.html, connect it to the PostgreSQL database you were listing, and read its tables off the diagram. Connecting, reverse-engineering, the diagrams and the SQL Editor are in the free Community Edition.

DbSchema ER diagram designer DbSchema ER diagram designer

Design and visualize
your database schema

Edit referenced records
in related tables

Query your data
visually too

Reuse the SQL
generated

Free Download