In PostgreSQL, how do you show all tables for a database?
Here are three solutions, ordered from fastest and most specific to PostgreSQL, to slowest but most generic.
Assume your database is called
db and you are running psql. First, choose (
\c) the database to work with, then display (
\d) all its tables (
\c db; \dt;
To run psql you can start it from a terminal. The command below assumes your username is
postgres and logs into the
db database directly:
psql db -U postgres;
You can also use the command
\d in psql, instead of
\dt, to show all tables, views, sequences, roles, and other database objects. For help on the command, enter
\? and page down to see all the variants of
q to quit the help.
You might want to show all tables in a terminal. This can be of use when running shell scripts to automate database tasks. The following terminal command (
-c) will display all tables in the
db database without having to type in psql.
psql -U postgres -c "\dt" db;
If you are using a general SQL app instead of psql, the following command will work. It will work in psql too.
SELECT * FROM pg_catalog.pg_tables WHERE schemaname='public';
Finally, this generic command will work across multiple database servers, including Postgres:
SELECT table_schema || '.' || table_name FROM information_schema.tables WHERE table_type = 'BASE TABLE' AND table_schema NOT IN ('pg_catalog', 'information_schema');
Loved by over 4 million developers and more than 90,000 organizations worldwide, Sentry provides code-level observability to many of the world’s best-known companies like Disney, Peloton, Cloudflare, Eventbrite, Slack, Supercell, and Rockstar Games. Each month we process billions of exceptions from the most popular products on the internet.
Here’s a quick look at how Sentry handles your personal information (PII).×
We collect PII about people browsing our website, users of the Sentry service, prospective customers, and people who otherwise interact with us.
What if my PII is included in data sent to Sentry by a Sentry customer (e.g., someone using Sentry to monitor their app)? In this case you have to contact the Sentry customer (e.g., the maker of the app). We do not control the data that is sent to us through the Sentry service for the purposes of application monitoring.Am I included?
We may disclose your PII to the following type of recipients:
You may have the following rights related to your PII: