【PostgreSQL-9.6.3】如何得到psql中命令的实际执行SQL
来源:互联网 发布:php社交网站论文 编辑:程序博客网 时间:2024/06/14 23:01
当我们在psql界面执行以“\”开头的命令时,数据库会立刻返回执行结果,而不会返回命令的实际执行过程。通过两种方式可以实现执行过程的查看:
方法一:启动psql命令时加“-E”参数
postgres@lgr-pc:~$ psql -E testpsql (9.6.3)Type "help" for help.test=# \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.relnamespaceWHERE c.relkind IN ('r','v','m','S','f','') AND n.nspname <> 'pg_catalog' AND n.nspname <> 'information_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 | people | table | postgres public | persons | table | postgres public | students | table | postgres public | t1 | table | postgres public | t11 | table | postgres public | t2 | table | postgres public | tmp12 | table | postgres public | tmp15 | table | postgres
这种方式只能在启动psql时使用,如果想关闭查询功能只能重新启动psql。
方法二:在psql中执行“\set ECHO_HIDDEN on|off”命令。on为开启,off为关闭,“ECHO_HIDDEN”必须为大写。
test=# \set ECHO_HIDDEN ontest=# \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.relnamespaceWHERE c.relkind IN ('r','v','m','S','f','') AND n.nspname <> 'pg_catalog' AND n.nspname <> 'information_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 | people | table | postgres public | persons | table | postgres public | students | table | postgres public | t1 | table | postgres public | t11 | table | postgres public | t2 | table | postgres public | tmp12 | table | postgres public | tmp15 | table | postgres(8 rows)test=# \set ECHO_HIDDEN offtest=# \d List of relations Schema | Name | Type | Owner --------+----------+-------+---------- public | people | table | postgres public | persons | table | postgres public | students | table | postgres public | t1 | table | postgres public | t11 | table | postgres public | t2 | table | postgres public | tmp12 | table | postgres public | tmp15 | table | postgres(8 rows)
阅读全文
0 0
- 【PostgreSQL-9.6.3】如何得到psql中命令的实际执行SQL
- 【PostgreSQL-9.6.3】psql常用命令
- PostgreSQL学习笔记---3 psql命令
- PostgreSQL psql 终端命令
- postgresql中如何Kill掉正在执行的SQL语句
- HGDB批量执行psql命令的脚本
- PostgreSQL 使用psql插入参数到sql脚本文件中
- PostgreSQL客户端交互命令psql
- 【PostgreSQL】PostgreSQL操作-psql基本命令
- 如何使用psql命令去调试含参的sql文件
- PostgreSQL:psql工具的使用
- Postgresql psql文件执行与批处理
- HGDB psql中\g执行上一条SQL
- crontab 无法执行psql命令
- psql --c 执行SQL语句
- 如何查看bat,bash的实际执行命令
- PostgreSQL - psql(客户端交互命令)
- postgresql数据库psql控制台操作命令
- javascript 对象与字符串相互转换函数 JSON.stringify 和 JSON.parse 的使用
- OpenCV3.1丢失Nonfree模块
- 九度oj-1068-球的半径和体积
- 论文笔记:Residual Attention Network for Image Classification
- mybatis和hibernate的区别(keep update)
- 【PostgreSQL-9.6.3】如何得到psql中命令的实际执行SQL
- 学生信息管理系统问题集锦(一)
- CSS中伪类及伪元素用法详解
- gdb回退调试
- SQLyog导入数据报错总结
- 1715 大斐波数
- 循环日程表问题
- 单片机脚本语言移植lua到stm32MDK
- Apache Kafka 入门