PostgreSQL is a powerful, open-source database system. It is a relational database management system (RDBMS) based on the SQL language. PostgreSQL is one of the most popular database systems in the world. It is the go-to database for many developers and companies.
In this post, I will show you how to list all tables in PostgreSQL using the
psql command-line tool.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
To follow along with this tutorial, you will need:
psqlcommand-line tool installed on your computer.
Step 1 — Connect to the PostgreSQL database
To connect to the PostgreSQL database, run the following command:
-Uflag specifies the username to connect to the database. In this case, we are connecting to the default
-hflag specifies the hostname of the database server. In this case, we are connecting to the database server running on the same computer, so we use
-pflag specifies the port number of the database server. In this case, we are connecting to the default port number
Step 2 — Switch to a specific database
To check the list of all databases, run the following command:
That is the equivalent of running
SHOW DATABASES;in MySQL.
To switch to a specific database, run the following command:
\ccommand is used to switch to a specific database.
\ccommand is similar to the
USEcommand in MySQL.
Step 3 — List all tables in the database
To list all tables in the database, run the following command:
\dtcommand is used to list all tables in the database in the public schema.
\dtcommand is similar to the
SHOW TABLES;command in MySQL.
To list all tables in the database in all schemas, run the following command:
*.*specifies that we want to list all tables in all schemas.
In this tutorial, you learned how to list all tables in PostgreSQL using the
To learn more about SQL, check out this free SQL eBook: