【PostgreSQL-9.6.3】如何得到psql中命令的实际执行SQL
当我们在psql界面执行以“\”开头的命令时,数据库会立刻返回执行结果,而不会返回命令的实际执行过程。通过两种方式可以实现执行过程的查看:
方法一:启动psql命令时加“-E”参数
postgres@lgr-pc:~$ psql -E test
psql (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.relnamespace
WHERE 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 on
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.relnamespace
WHERE 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 off
test=# \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)
【PostgreSQL-9.6.3】如何得到psql中命令的实际执行SQL的更多相关文章
- springboot中使用mybatis显示执行sql
springboot 中使用mybatis显示执行sql的配置,在properties中添加如下 logging.你的包名=debug 2018-11-27 16:35:43.044 [DubboSe ...
- oracle存储过程中使用execute immediate执行sql报ora-01031权限不足的问题
oracle存储过程中使用execute immediate执行sql报ora-01031权限不足的问题 学习了:http://blog.csdn.net/royzhang7/article/deta ...
- Oracle中如何停止正在执行SQL语句
oracle的用P/SQL客户端中,如何停止正在执行的SQL语句? 我们使用oracle语句查询某个表时,如果查询的表数据太多,如何停止正在执行操作 如查询的表数据超过上万条时,如何停止查询操作
- 使用Hive或Impala执行SQL语句,对存储在HBase中的数据操作
CSSDesk body { background-color: #2574b0; } /*! zybuluo */ article,aside,details,figcaption,figure,f ...
- 使用Hive或Impala执行SQL语句,对存储在Elasticsearch中的数据操作(二)
CSSDesk body { background-color: #2574b0; } /*! zybuluo */ article,aside,details,figcaption,figure,f ...
- 使用Hive或Impala执行SQL语句,对存储在Elasticsearch中的数据操作
http://www.cnblogs.com/wgp13x/p/4934521.html 内容一样,样式好的版本. 使用Hive或Impala执行SQL语句,对存储在Elasticsearch中的数据 ...
- SSIS中执行SQL任务组件参数传递的问题
原文:SSIS中执行SQL任务组件参数传递的问题 症状: 执行SQL任务,传递参数到子查询中,执行报错. 错误: 失败,错误如下:"无法从使用 sub-select 查询的 SQL 语句中派 ...
- 如何在脚本中执行SQL语句并获得结果输出?
这里需要用到的工具叫做sqlcmd.exe, 它随SQL server的安装而安装. 该可执行程序的位置在: C:\Program Files\Microsoft SQL Server\xxx\Too ...
- qt中执行 sql文件的方法
由于qt中没有原生的执行sql文件的方法.因此我们需要根据sql文件中的流的特点,将其分解成一个个语句单独执行. 1.首先通过Qfile读取sql文件 2.将sql文件中的内容通过“:”进行拆解 3. ...
随机推荐
- 第十五节:pandas之concat()级联
Pandas 提供了concat()函数可以轻松的将Series.DataFrame对象进行合并在一起. pandas.concat(obj , axis=0 , join="inner&q ...
- c# 异步执行
c#异步执行 Action logAction = () => {////执行的操作 }; logAction.BeginInvoke(null, null);
- python正则匹配——中文字符的匹配
# -*- coding:utf-8 -*- import re '''python 3.5版本 正则匹配中文,固定形式:\u4E00-\u9FA5 ''' words = 'study in 山海大 ...
- Codeforces Round #418 (Div. 2) C. An impassioned circulation of affection
C. An impassioned circulation of affection time limit per test 2 seconds memory limit per test 256 m ...
- Mac下OpenCV开发
1. 环境搭建 a) 安装Homebrew i. 下载地址:http://github.com/mxcl/homebrew/tarball/maste ...
- POJ-2201-Cartesian Tree(笛卡尔树)
Description Let us consider a special type of a binary search tree, called a cartesian tree. Recall ...
- iOS开发一行代码系列:一行搞定数据库
原理 iOS 和 SQL的相应关系 Model类结构 => SQL表结构 Model实例 => SQL表中的一行 Model实例的属性 => S ...
- Hilbert曲线简单介绍及生成算法
Hilbert曲线 Hilbert曲线是一种填充曲线,相似的填充曲线还包含Z曲线.格雷码等其它方法.Hilbert曲线根据自身空间填充曲线的特性,能够线性地贯穿二维或者更高维度每一个离散单元.而且只穿 ...
- Extjs grid 设置行字体颜色
CustSuppGrid = Ext.create('Ext.grid.Panel', { title : '', // 标题头 iconCls : 'icon-grid', // 标题图标 stor ...
- Modern Qt Development: The Top 10 Tools You Should Be Using
Published Friday October 12th, 2018Leave a comment Posted in Biz Circuit & Dev Loop, C++, QtCrea ...