Skip to content

Navigating through your PostgreSQL database effectively requires familiarity with its structure, especially the tables it contains. Listing tables is a basic yet essential operation, enabling you to understand and manage your database more effectively. We’ll explore these techniques, allowing you to choose the most suitable one for your needs.

How to list tables in PostgreSQL?

Use the \\dt command in the psql command-line interface to see all tables within the current schema. This command helps you quickly identify the tables available:

\\dt

For a broader view, including tables from all schemas, execute the \\dt *.* command:

\\dt *.*

How to use SQL to list tables?

If you need to integrate the table listing into applications or scripts, execute SQL queries directly. For instance, to list all tables in the database, run the following SQL query against the information_schema.tables view:

SELECT table_schema, table_name
FROM information_schema.tables
WHERE table_type = 'BASE TABLE' AND table_schema NOT IN ('pg_catalog', 'information_schema');

This approach filters out system tables and shows only user-defined ones, simplifying your view.

How to filter tables by schema?

To concentrate on a specific schema’s tables, tailor your SQL query by setting the table_schema:

SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'your_schema_name';

Just replace your_schema_name with the actual schema name you’re interested in. This refined approach ensures you focus only on relevant tables, making your data management more targeted and efficient.

Written by

Robert Cooper avatar

Robert Cooper

Senior Engineer at Basedash

Robert Cooper is a senior engineer at Basedash who builds full-stack product systems across SQL data infrastructure, APIs, and frontend architecture. His work focuses on application performance, developer velocity, and reliable self-hosted workflows that make data operations easier for teams at scale.

View full author profile →

Looking for an AI-native BI tool?

Basedash lets you build charts, dashboards, and reports in seconds using all your data.