38

I need help with a pretty basic Postgres command, but I cannot find a reference anywhere. My cluster is set up like this:

database_1
   \- schema_1
   \- schema_2
        \- relation_1
        \- relation_2
        \- ...
   \- relation_3
   \- relation_4
   \- ...

I know how to list databases (\l), and I know how to list relations in the "default" schema (\dt). Heck, I can even list schemas (\dn), but I cannot, for the life of me, list the relations within a schema.

To pre-clarify, what I'm looking for is this:

> \c database_1
You are now connected to database_1
> \somecommand
relation_1
relation_2
>

3 Answers 3

41

Try this one:

\dt schema_2.
Sign up to request clarification or add additional context in comments.

2 Comments

perfect, thanks :) At the same time I also discovered that asterisk will work with this as well (\dt schema_2.* or \dt schema_. etc etc)
this answer appears out of date
26

I'll clarify since this is the first result of a google search.

\dt schema_2 will not list all the relations for schema_2.

The correct answer is in the comments of the answer.

\dt schema_2.* 

A more thorough answer can be found here, List tables in a PostgreSQL schema

1 Comment

This lists tables. Relations also include views and materialized views, which aren't listed with this command.
4

As of PostgresQL version 11.2 I find that this performs as expected. It lists views and sequences as well, not just tables.

\d schema_2.

If you replace schema_2 with your schema name and leave the dot it appears to work fine.

Some further command instructions are available in a psql connection via \?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.