share.png

PostgreSQL 选择数据库

PostgreSQL 选择数据库

日期:2022-07-07

本文字数:130 字 阅读完需:约 1 分钟

PostgreSQL 选择数据库

上一章节我们讲了如何创建数据库,接下来我们来讨论如何去选择我们创建的数据库。

数据库的命令窗口

PostgreSQL 命令窗口中,我们可以命令提示符后面输入 SQL 语句:

1postgres=#

使用 \l 用于查看已经存在的数据库:

1postgres=# \l 2 List of databases 3 Name | Owner | Encoding | Collate | Ctype | Access privileges 4-----------+----------+----------+---------+-------+----------------------- 5 postgres | postgres | UTF8 | C | C | 6 runoobdb | postgres | UTF8 | C | C | 7 template0 | postgres | UTF8 | C | C | =c/postgres + 8 | | | | | postgres=CTc/postgres 9 template1 | postgres | UTF8 | C | C | =c/postgres + 10 | | | | | postgres=CTc/postgres 11(4 rows)

接下来我们可以使用 \c + 数据库名 来进入数据库:

1postgres=# \c runoobdb 2You are now connected to database "runoobdb" as user "postgres". 3runoobdb=#

系统命令行窗口

在系统的命令行查看,我么可以在连接数据库后面添加数据库名来选择数据库:

1$ psql -h localhost -p 5432 -U postgres runoobdb 2Password for user postgres: **** 3psql (11.3) 4Type "help" for help. 5You are now connected to database "runoobdb" as user "postgres". 6runoobdb=#

pgAdmin 工具

pgAdmin 工具更简单了,直接点击数据库选择就好了,还可以查看一些数据库额外的信息:

029E4150-C4C3-47BE-8CCE-9267335EDBBB.jpg