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.
databasename is the name of your database.
A connection has been made to the database
mydb and you can see the prompt changed to
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.
Now, click on the
Tools drop down menu and click on
Now, a new window appears with a connection make to the database you selected. You can run SQL queries here.
In this PostgreSQL Tutorial, we have learnt how to connect or select a specific database in PostgreSQL.