Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to list schemas in PostgreSQL?

How to fetch a list of schema from the current database. The result which we get using \dn. This query fetches all schema

SELECT table_schema,table_name 
FROM information_schema.tables 
ORDER BY table_schema,table_name;

But I want only the schema which is defined in the current database. And then how to fetch all tables corresponding to that particular schema?


1 Answers

These list all schemas including system's in the current database:

\dnS
\dn *

These list all schemas including system's in the current database in detail:

\dnS+
\dn+ *

This lists all schemas excluding system's in the current database:

\dn

This lists all schemas excluding system's in the current database in detail:

\dn+

These also list all schemas including system's in the current database:

SELECT * FROM pg_namespace;
SELECT * FROM information_schema.schemata;
like image 65
Kai - Kazuya Ito Avatar answered Sep 14 '25 22:09

Kai - Kazuya Ito