加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

PostgreSQL学习第七篇--psql常用命令

发布时间:2020-12-13 17:00:45 所属栏目:百科 来源:网络整理
导读:1)d :显示数据库中有哪些表d tab_name :查看表的定义查看索引信息:postgres=# d txx_pkey Index "public.txx_pkey" Column | Type | Definition--------+---------+------------ id | integer | idprimary key,btree,for table "public.txx"d+ 命令
1)d   :显示数据库中有哪些表
d tab_name  :查看表的定义
查看索引信息:
postgres=# d txx_pkey
    Index "public.txx_pkey"
 Column |  Type   | Definition
--------+---------+------------
 id     | integer | id
primary key,btree,for table "public.txx"

d+ 命令:将会显示比d命令更详细的信息,除了前面介绍的那些,它还会显示任何与表列相关的注释,以及表中出现的OID。
postgres=# d+ txx
                             Table "public.txx"
 Column |      Type      | Modifiers | Storage  | Stats target | Description
--------+----------------+-----------+----------+--------------+-------------
 id     | integer        | not null  | plain    |              |
 name   | character(100) |           | extended |              |
Indexes:
    "txx_pkey" PRIMARY KEY,btree (id)

postgres=# d txx
         Table "public.txx"
 Column |      Type      | Modifiers
--------+----------------+-----------
 id     | integer        | not null
 name   | character(100) |
Indexes:
    "txx_pkey" PRIMARY KEY,btree (id)



2)PG中无dual表。
select 1+1;

postgres=# select 1+1;
 ?column?
----------
        2
(1 row)

3)显示sql执行的时间,可以使用timing参数
postgres=# timing on
Timing is on.
postgres=# select * from txx;
 id | name
----+------
(0 rows)

Time: 0.795 ms

4)列出所有的schema
dn
postgres=# dn
  List of schemas
  Name  |  Owner   
--------+----------
 public | postgres
(1 row)

5)显示所有的表空间可以使用db命令
postgres=# db
       List of tablespaces
    Name    |  Owner   | Location
------------+----------+----------
 pg_default | postgres |
 pg_global  | postgres |
(2 rows)

实际上postgresSQL中的表空间就是对应一个目录,放在这个表空间中的表,就是把表的数据文件放到这个目录下。

6)如果想列出数据库中所有的角色或者用户,可以使用du   dg,这两个命令等价,因为postgresSQL中用户和角色不区分。

postgres=# du
                                   List of roles
 Role name |                         Attributes                         | Member of
-----------+------------------------------------------------------------+-----------
 postgres  | Superuser,Create role,Create DB,Replication,Bypass RLS | {}

postgres=# dg
                                   List of roles
 Role name |                         Attributes                         | Member of
-----------+------------------------------------------------------------+-----------
 postgres  | Superuser,Bypass RLS | {}

7)指定字符集编译的命令
encoding命令
设定gbk 
encoding gbk
encoding utf8

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读