PostgreSQL Select Database
In the previous chapter we discussed how to create a database; next we discuss how to select the database we created.
The 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 |
runoobdb | 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 enter a database:
postgres=# \c runoobdb
You are now connected to database "runoobdb" as user "postgres".
runoobdb=#
The system command-line window
At the system command line, we can add the database name after connecting to select the database:
$ psql -h localhost -p 5432 -U postgres runoobdb
Password for user postgres: ****
psql (11.3)
Type "help" for help.
You are now connected to database "runoobdb" as user "postgres".
runoobdb=#
pgAdmin tool
pgAdmin is even simpler: just click the database to select it, and you can also view additional database information:
