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 >
To show the name of the current schema, use the following simple command. >> SELECT current_schema(); This shows that the current schema is “public”.
If you want to see the entire database structure in one go, type \d * in the psql console. That gives schema of all tables in that database.
PostgreSQL is a relational database management system ( RDBMS ). That means it is a system for managing data stored in relations. Relation is essentially a mathematical term for table.
Try this one:
\dt schema_2.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With