微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

postgresql学习--psql命令行常用命令

\l 列出数据库列表 \d 列出该库下的所有表名称 \d xx 列出xx表的所有列,数据类型,索引等信息 \d x? 通配符,?表示一个字符,即列出所有x字母带头的,只有两个字母的表信息 \d t* 通配符,*表示任意字符,即列出所有t字母带头的表 \c xx 切换到xx数据库 \d+ 显示更多的表信息,比如表大小和描述 \dn 列出所有的schema \db 列出所有的表空间 \du 列出所有用户的角色 \dp 列出表的权限分配 \encoding utf8 设置客户端的字符集为utf8 \x 行显示模式,也就是MysqL的\G \i xx.sql 运行xx.sql文件 \? 查看更多的\命令 如何显示sql执行时间 mydb=# select * from xx; id | name -----+------ 123 | asd (1 row) mydb=# \timing on Timing is on. mydb=# select * from xx; id | name -----+------ 123 | asd (1 row) Time: 0.330 ms 如果设置命令行输出格式 \pset border 0 无边框 \pset border 1 边框只在内部 \pset border 2 内外都有边框 mydb=# \pset border 2 Border style is 2. mydb=# \dp xx Access privileges +--------+------+-------+-------------------+--------------------------+ | Schema | Name | Type | Access privileges | Column access privileges | +--------+------+-------+-------------------+--------------------------+ | public | xx | table | | | +--------+------+-------+-------------------+--------------------------+ (1 row) mydb=# \pset border 0 Border style is 0. mydb=# \dp xx Access privileges Schema Name Type Access privileges Column access privileges ------ ---- ----- ----------------- ------------------------ public xx table (1 row) 实际这些简化的命令行执行的是什么具体的sql 运行psql添加-E参数 [postgresql@10-4-33-189 bin]$ ./psql -h127.0.0.1 -p 5432 -E mydb psql (9.4.1) Type "help" for help. mydb=# \d ********* QUERY ********** SELECT n.nspname as "Schema",c.relname as "Name",CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' WHEN 'm' THEN 'materialized view' WHEN 'i' THEN 'index' WHEN 'S' THEN 'sequence' WHEN 's' THEN 'special' WHEN 'f' THEN 'foreign table' END as "Type",pg_catalog.pg_get_userbyid(c.relowner) as "Owner" FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace WHERE c.relkind IN ('r','v','m','S','f','') AND n.nspname <> 'pg_catalog' AND n.nspname <> '@R_480_4045@ion_schema' AND n.nspname !~ '^pg_toast' AND pg_catalog.pg_table_is_visible(c.oid) ORDER BY 1,2; ************************** List of relations Schema | Name | Type | Owner --------+------+-------+------------ public | test | table | postgresql public | xd | table | postgresql public | xx | table | postgresql (3 rows)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐