31

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.

Halp!

Thanks, Joe


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
>
Joe Mastey
  • 26,809
  • 13
  • 80
  • 104

3 Answers3

38

Try this one:

\dt schema_2.
Szymon Lipiński
  • 27,098
  • 17
  • 75
  • 77
23

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

Community
  • 1
  • 1
Mitch
  • 652
  • 1
  • 8
  • 14
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 \?

eadsjr
  • 681
  • 5
  • 20