POSTGRESQL

Postgres List Schemas: 3 Different Approaches

intro

A single PostgreSQL database typically contains multiple schemas. In this guide, you will explore three different PostgreSQL list schemas approaches.

Tools used in the tutorial
Tool Description Link
Dbvisualizer DBVISUALIZER
TOP RATED DATABASE MANAGEMENT TOOL AND SQL CLIENT

When working with PostgreSQL, you will often need to list the schemas available in your selected database. This is a common task for PostgreSQL users and database administrators. There are several Postgres list schemas approaches, depending on your tools, preferences, and level of experience.

In this article, you will see three different methods:

  1. Using a command-line command
  2. Running an SQL query
  3. Viewing PostgreSQL schemas through a database client

Let’s dive into how to list schemas in PostgreSQL!

Listing Schemas with the psql Command-Line Tool

psql is the “PostgreSQL interactive terminal” that lets you interact with a PostgreSQL server via the command line. With psql, you can:

  • Create schemas, tables, and users.
  • Run SQL queries.
  • Execute internal commands to view database metadata.

In detail, psql provides the \dn command to list schemas in a PostgreSQL database. Follow the steps below to learn how to use psql to list schemas:

Step 1: Launch the terminal.

Step 2: Connect to your PostgreSQL server and database with the following psql command-line tool:

Copy
        
1 psql -U <username> -d <database_name>

Replace <username> with your PostgreSQL username and <database_name> with the name of the database you want to inspect. You will be prompted to enter the password. Type it and press Enter to connect to the database.

Security tip: Use a .pgpass file to avoid your credentials from being logged in the terminal history and to avoid typing them every time.

Step 3: List the schemas in the <database_name> database with:

Copy
        
1 \dn

This command will return a table containing all the Postgres schemas in the connected database, along with their owners:

The list of PostgreSQL schema with basic info
The list of PostgreSQL schema with basic info

Note: Non-local temporary schemas are automatically suppressed by the \dn command.

In this article, we will use a PostgreSQL database named company to demonstrate how to list schemas.

Use \dn+ to get additional information about each schema, such as access privileges and its description:

The list of PostgreSQL schema with detailed info
The list of PostgreSQL schema with detailed info

Keep in mind that the \dn (or \dn+) command accepts an optional regular expression as a parameter. If provided, only schemas whose names match the pattern will be listed.

For example, to list only schemas that start with the letter “e”, run:

Copy
        
1 \dn e*

The result will be as follows:

Note that only the schema that starts with e was returned
Note that only the schema that starts with “e” was returned

How to List All Schemas in Postgres with a Query

If you are not a fan of using the command line, do not worry. You can also list Postgres schemas by running an SQL query.

In particular, PostgreSQL stores schema metadata in the pg_catalog.pg_namespace system catalog. Each row in that table represents a schema in the current database.

Thus, to retrieve the list of schemas, run the following query:

Copy
        
1 SELECT * FROM pg_catalog.pg_namespace;

This returns a table containing details about all schemas, including their names, owners (nspowner is the Object Identifier — OID — of the owner of the namespace), and access privileges:

The schemas returned by the query
The schemas returned by the query

The column you should be most interested in is nspname, which is the column that holds the name of each schema.

However, this table also includes internal schemas like pg_catalog and information_schema, which are used by PostgreSQL for system operations. If you want to list only user-defined schemas, you can filter them out with the following query:

Copy
        
1 SELECT nspname 2 FROM pg_catalog.pg_namespace 3 WHERE nspname NOT IN ('pg_catalog', 'information_schema') 4 AND nspname NOT LIKE 'pg_toast%';

In this case, the result will be as follows:

The user-generated schemas returned by the query
The user-generated schemas returned by the query

Explore PostgreSQL Schemas in a Visual Database Client

The simplest way to view all schemas in PostgreSQL is by using a graphical database client like DbVisualizer. This powerful tool lets you visually connect to and manage your PostgreSQL databases.

In detail, DbVisualizer offers extended support for PostgreSQL-specific object types and features, and it works with over 50 other databases.

To list Postgres schemas in DbVisualizer, complete the following steps:

Step 1: Configure a connection to your PostgreSQL server as explained in the official docs.

Step 2: Select your target server in the “Connections” menu on the left, right-click on it, and choose the “Connect” option:

Connecting to the PostgreSQL database
Connecting to the PostgreSQL database

Step 3: Expand the “Databases” dropdown and select your database of interest (in this case, company):

Selecting the target database
Selecting the target database

Step 4: Open the “Schemas” dropdown to see all available schemas, or open them in a new tab:

Listing PostgreSQL schemas in DbVisualizer
Listing PostgreSQL schemas in DbVisualizer

Awesome! With just a few clicks, DbVisualizer makes it easy to list PostgreSQL schemas.

Conclusion

In this article, you learned that the Postgres list schemas task is straightforward, and there are at least three effective ways to do it:

  1. Using a command-line command.
  2. Running a SQL query.
  3. Leveraging a graphical database client.

In particular, a powerful PostgreSQL-compatible client like DbVisualizer lets you view and manage schemas visually. It also offers advanced features such as query optimization tools, ERD-style schema generation, and robust import/export options. Download DbVisualizer for free!

FAQ

How to list users in PostgreSQL?

To list users in PostgreSQL, you can connect to your database and run the following query:

Copy
        
1 SELECT usename FROM pg_catalog.pg_user;

This will return a list of all users in your PostgreSQL instance. For more practical methods, read our detailed guide on how to list users in PostgreSQL.

How to list databases in PostgreSQL?

To list databases in PostgreSQL, you can connect to your PostgreSQL server in psql and then launch the following psql command:

Copy
        
1 \l

This will display a list of all databases in your PostgreSQL instance. For other approaches, be sure to check out our tutorial on listing databases in Postgres.

How to list all tables in a schema in Postgres?

To list all tables in a specific PostgreSQL schema, run this query:

Copy
        
1 SELECT tablename FROM pg_catalog.pg_tables 2 WHERE schemaname = 'your_schema_name';

Where 'your_schema_name' is the name of your target schema. Instead, in psql, you can achieve the same result with:

Copy
        
1 \dt your_schema_name.*

How to use pgAdmin to view the list of schemas in PostgreSQL?

To view the list of schemas in PostgreSQL using pgAdmin:

  1. Open pgAdmin and connect to your PostgreSQL server.
  2. In the “Browser” panel, expand your database.
  3. Navigate to “Schemas” under the database.
  4. You will see a list of all schemas in that database, including system and user-defined schemas.

You can also right-click on Schemas to refresh or explore schema details further.

Are there any security concerns when listing schemas in PostgreSQL?

In PostgreSQL, users can only see schemas they have access to. If a user lacks privileges on certain schemas, those schemas will not appear in their listings. Granting broader access may expose schema names or metadata unintentionally, so it is best practice to always follow the principle of least privilege.

Dbvis download link img
About the author
Antonello Zanini

Antonello is a software engineer, and often refers to himself as a technology bishop. His mission is to spread knowledge through writing.

The Table Icon
Sign up to receive The Table's roundup
More from the table
Title Author Tags Length Published
title

SQL Boolean Type: How to Use It in All Major Relational Databases

author Antonello Zanini tags MySQL ORACLE POSTGRESQL SQL SQL SERVER 8 min 2025-09-23
title

pgvectorscale: An Extension for Improved Vector Search in Postgres

author Antonello Zanini tags AI POSTGRESQL Vectors 9 min 2025-09-03
title

PostgreSQL Index Mechanism: A Guide to Database Performance Optimization

author Leslie S. Gyamfi tags POSTGRESQL 8 min 2025-09-02
title

UUIDv7 in PostgreSQL 18: What You Need to Know

author Antonello Zanini tags POSTGRESQL 8 min 2025-09-01
title

PostgreSQL ISNULL Equivalent: COALESCE, CASE, and NULLIF

author TheTable tags POSTGRESQL 5 min 2025-08-19
title

SQL IS NOT NULL Condition: Definitive Guide

author Antonello Zanini tags MySQL ORACLE POSTGRESQL SQL SQL SERVER 6 min 2025-08-13
title

Can a Primary Key Be NULL in an SQL Table?

author TheTable tags MySQL ORACLE POSTGRESQL SQL SQL SERVER 5 min 2025-08-12
title

ISNULL vs COALESCE: Comparing NULL Handling Functions

author Antonello Zanini tags MySQL ORACLE POSTGRESQL SQL SQL SERVER 6 min 2025-08-06
title

The SELECT INTO TEMP TABLE Mechanism in SQL

author Antonello Zanini tags MySQL ORACLE POSTGRESQL SQL SQL SERVER 6 min 2025-08-05
title

PostgreSQL TRUNCATE TABLE Statement: A Guide

author Leslie S. Gyamfi tags POSTGRESQL 6 min 2025-07-30

The content provided on dbvis.com/thetable, including but not limited to code and examples, is intended for educational and informational purposes only. We do not make any warranties or representations of any kind. Read more here.