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

来源:互联网 发布:visio mac版下载 编辑:程序博客网 时间:2024/06/07 19:44
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+ 命令:将会显示比\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 onTiming is on.postgres=# select * from txx; id | name----+------(0 rows)Time: 0.795 ms4)列出所有的schema\dnpostgres=# \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, Create role, Create DB, Replication, Bypass RLS | {}7)指定字符集编译的命令\encoding命令设定gbk \encoding gbk\encoding utf8

0 0
原创粉丝点击