PostgreSQL – SELECT DATABASE

In PostgreSQL c database_name statement is used for connecting or using database server. After connecting to database all queries will be executed on that database. Login to PostgreSQL database command prompt using command ‘sudo -u postgres psql‘ from terminal.

Syntax :-

postgres=# c database_name

Example :-

Login to your PostgreSQL server using command line. You will get PostgreSQL database prompt like postgres=#. Now use c DATABASE_NAME statement to connect to database.

postgres=# c mydb

If everything goes successfully, you will get output like You are now connected to database “mydb” as user “postgres”. and your prompt will be changed like “mydb=# ”

Now use d to list tables and relations from connected database like below.