PostgreSQL – SELECT Database or Connect to a Database

You can have multiple databases in PostgreSQL. And to run SQL queries on a specific database, you can select the database by making a connection to the database.

Select Database using psql

To select a database or make a connection to the database, run the select/connect command as shown below.

\c databasename

where databasename is the name of your database.

PostgreSQL - Select Database or Connect to Database

A connection has been made to the database mydb and you can see the prompt changed to mydb-#.

Select Database using pgAdmin

You can also select the database and open SQL Query window in pgAdmin UI.

Step 1: Select the database, by clicking on it.

PostgreSQL Select Database

Now, click on the Tools drop down menu and click on Query Tool.

PostgreSQL - Select Database - Tools - Query Tool

Now, a new window appears with a connection make to the database you selected. You can run SQL queries here.

PostgreSQL - Select Database - Connection made


In this PostgreSQL Tutorial, we have learnt how to connect or select a specific database in PostgreSQL.