To list the tables in a Postgres database you use the
\dt meta-command, short for “display tables”? First things first, in order to get a list of tables in your database you first login to the Postgres shell and connect to the database you’re interested in. You login to the Postgres shell with the
psql command. Afterwards, you can connect to a database with
$ psql psql (12.6 (Ubuntu 12.6-0ubuntu0.20.04.1)) Type "help" for help. postgres=# \c myproject You are now connected to database "myproject" as user "postgres". myproject=#
Now that we are connected to the right database we can show the tables with the
myproject=# \dt List of relations Schema | Name | Type | Owner --------+--------+-------+---------- public | users | table | postgres public | pizzas | table | postgres (2 rows) myproject=#
When you run this meta-command you might see a message saying “Did not find any relations”. You get this message when you have a database for which there aren’t any tables yet.
myproject=# \dt Did not find any relations.