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
to list tables and relations from connected database like below.
mydb=#d List of relations Schema | Name | Type | Owner --------+---------------------+----------+---------- public | employee | table | postgres public | employee_emp_id_seq | sequence | postgres (2 rows)