当前位置:  首页>> 技术小册>> PostgreSQL入门教程

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

  1. postgres=#

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

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

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

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

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

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

该分类下的相关小册推荐: