PostgreSQL psql 终端命令
程序员文章站
2024-03-21 10:26:10
...
- 命令行登录数据库
$ psql -U username -h ipaddress -d dbname
- 在命令行下切换数据库
wzz=# \c dbname
- 查看帮助
wzz=# help
You are using psql, the command-line interface to PostgreSQL.
Type: \copyright for distribution terms
\h for help with SQL commands
\? for help with psql commands
\g or terminate with semicolon to execute query
\q to quit
常用命令
. 列出所有的数据库
wzz=# \l
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
wzz | wzz | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
(4 rows)
. 切换数据库
wzz=# \c dbname
. 列出当前书库库下的表
wzz=# \d
. 显示当前数据库
wzz=# select current_database();
. 列出表的所有字段
wzz=# \d tablename
. 查看表的基本情况
wzz=# \d+ tablename
. 退出登录
wzz=# \q
. 退出登录
wzz=# \q