# PostgreSQL Show All Tables in a Database with psql

> Run \dt in psql after connecting with \c, or query pg_catalog.pg_tables or the standard information_schema.tables for a database-agnostic option

**URL:** https://sentry.io/answers/how-to-show-tables-in-postgresql/

---

## The Problem

In PostgreSQL, how do you show all tables for a database?

## The Solution

Here are three solutions, ordered from fastest and most specific to PostgreSQL, to slowest but most generic.

### PSQL

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 (`\t`).

```psql
\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:

```bash
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 `\d`. Push `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.

```bash
psql -U postgres -c "\dt" db;
```

### PostgreSQL SQL

If you are using a general SQL app instead of psql, the following command will work. It will work in psql too.

```sql
SELECT * FROM pg_catalog.pg_tables WHERE schemaname='public';
```

### Generic SQL

Finally, this generic command will work across multiple database servers, including Postgres:

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

---

*Source: [sentry.io/answers/how-to-show-tables-in-postgresql/](https://sentry.io/answers/how-to-show-tables-in-postgresql/)*
