Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to list relations in postgres schema

Tags:

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 > 
like image 910
Joe Mastey Avatar asked Nov 05 '10 18:11

Joe Mastey


People also ask

What is the psql command to show the schema of a relation?

To show the name of the current schema, use the following simple command. >> SELECT current_schema(); This shows that the current schema is “public”.

How do I find the Postgres database schema?

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.

What is relation in Postgres?

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.


2 Answers

Try this one:

\dt schema_2. 
like image 73
Szymon Lipiński Avatar answered Sep 28 '22 09:09

Szymon Lipiński


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

like image 37
Mitch Avatar answered Sep 28 '22 10:09

Mitch