YouTip LogoYouTip

Postgresql Select Database

# PostgreSQL Select Database In the previous chapter, we discussed how to create a database. Now, let's discuss how to select the database we created. ### Database Command Window In the PostgreSQL command window, we can enter SQL statements after the command prompt: postgres=# Use `l` to view existing databases: postgres=# l List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -----------+----------+----------+---------+-------+----------------------- postgres | postgres | UTF8 | C | C | tutorialdb | postgres | UTF8 | C | C | template0 | postgres | UTF8 | C | C | =c/postgres + | | | | | postgres=CTc/postgres template1 | postgres | UTF8 | C | C | =c/postgres + | | | | | postgres=CTc/postgres (4 rows) Next, we can use `c + database_name` to connect to the database: postgres=# c tutorialdb You are now connected to database "tutorialdb" as user "postgres". tutorialdb=# ### System Command Line Window In the system command line, we can add the database name after the connection command to select the database: $ psql -h localhost -p 5432 -U postgres tutorialdb Password for user postgres: **** psql (11.3)Type "help" for help.You are now connected to database "tutorialdb" as user "postgres". tutorialdb=# ### pgAdmin Tool The pgAdmin tool is even simpler; you can directly click to select the database and also view some additional database information: !(#)
← Postgresql Create TableData Element β†’