In PostgreSQL Database, we can select the database through which we want to connect and the same can be performed using the Database SQL prompt using the psql utility or from the OS prompt using the UNIX command-line interface.

In this section, we will see both ways to connect to a particular PostgreSQL database.

1. Select Database Using psql PostgreSQL Utility

We can use the \c dbname to connect to the particular database. In the following example as we know the postgres is by default created and in the previous database creation section we already created a new database named cloudduggu_db.

Now we have to select the cloudduggu_db and the command will be as below.


   postgresql=# \c cloudduggu_db


In the following output, we can see that the database cloudduggu_db has been selected.

postgresql select database psql command

2. Select Database Using UNIX command-line

We can select the PostgreSQL database from the UNIX command-line interface during login time.

In the following example, we are login in using the postgres username and connecting to the cloudduggu_db database on port number 5432.


   cloudduggu@ubuntu:~$ psql -h localhost -p 5432 -U postgres cloudduggu_db


We can see in the following output, that the connection is made to the cloudduggu_db database using the postgres user.

postgresql select database unix command line