PostgreSQL Tutorial: How To Connect Or Switch To A Database In PostgreSQL

By Nicholas Brown

If you’re using the PostgreSQL command line interface (CLI), you can select the database while at the Postgres prompt by typing the following command:

\connect database name


\c databasename

You can now list tables within that database using the ‘\dt’ command and list all other databases with the ‘\l’ command.

If you are not at a PostgreSQL command prompt, but rather a Linux command prompt, you’d use the following command:

psql dbname