关于set sql_trace=ture 的一些用法

本文介绍了Oracle提供的SQL Trace工具的基本用法,包括全局启用、在当前会话启用及跟踪其他用户的进程。此外还介绍了如何查看追踪记录数据及其存储路径。

一, 基本介绍

        sql_trace Oracle 提供用于进行sql语句追踪的工具。

        下面介绍一些简单用法:

 

二, 启用方法

2. 1 在全局中使用

          在参数文件(pfile/spfile)中指定:

           sql_trace = true

          在全局启用sql_trace会令到所有进程都会被追踪,包括后台进程以及所有用户进程。会导致比较明显的性能下降。所以在production环境一般不使用。

 

2.2  在当前session启用

           大多数时候我们使用sql_trace 追踪当前进程。前提是当前账号具有alter session的系统权限。

           启用命令为alter session set sql_trace=true;           

如下图:


2.3  跟踪其他用户的进程

          很多时候我们需要跟踪的是其他用户的进程,而不是当前用户(进程),这可以通过Oracle的系统包DBMS_SYSTEM.SET_SQL_TRACE_IN_SESSION来完成。


SET_SQL_TRACE_IN_SESSION 要求用户提供3个参数:SID, SERIAL#, SQL_TRACE(开关)

执行

desc dbms_system


解释一下

Sid:  Session identifier    # session 的标识符

SERIAL#
Session serial number. Used to identify uniquely a session's objects. Guarantees that session-level commands are applied to the correct session objects if the session ends and another session begins with the same session ID.

#Session 的序列号。作为唯一标示符用于标识session的对象。(当1个session结束而另1个新的session使用了旧session相同的sid时)保证在session层面上的命令能应用在正确的session对象身上。


我们可以通过查看v$session来获得sid,serial#等信息

如上图,可以见到有3个session,  我们尝试跟踪 用户为SCOTT的session

执行

exec dbms_system.set_sql_trace_in_session(sid,serial#,true)
如下图


接着去对应session执行一些sql语句
其实那个session是在另1台机器用sqldeveloper连接的,如下图

接着去查看记录文件:


就见到相应的信息了, 下面介绍如下查看记录文件。

三, 查看追踪的记录数据

         一般来讲,被追踪的数据会存放在这个目录下 $ORACLE_BASE/diag/rdbms/orcl/orcl/trace/

               具体位置可以由下面sql语句查询出来:

 select d.value || '/' ||

lower(rtrim(i.instance, chr(0))) || '_ora_' || p.spid || '.trc' trace_file_name
from
    -- spid
   ( select p.spid
     from sys.v$mystat m,
             sys.v$session s,
             sys.v$process p
     where m.statistic# = 1
         and s.sid = m.sid ——由于连接了sys.v$mystat这里只能搜索当前session的sid

         and p.addr = s.paddr) p,
    -- instance name    
   ( select t.instance
      from sys.v$thread  t,
              sys.v$parameter  v
     where v.name = 'thread'
     and (v.value = 0 or
             t.thread# = to_number(v.value))) i,
    --path
   ( select value
    from sys.v$parameter
    where name = 'user_dump_dest') d
 /

上面这个语句只能用于查看当前用户当前进程的记录文件,

如果要用于其他session, 就必须指定sid, 如下:

select d.value || '/'

|| lower(rtrim(i.instance, chr(0))) || '_ora_' || p.spid || '.trc' trace_file_name
from
   ( select p.spid
     from
             sys.v$session s,
             sys.v$process p
     where
         s.sid = 15 --这里指定sid 在sys.v$session就可以找出其他session的sid

参考2.3  跟踪其他用户的进程
         and p.addr = s.paddr) p,
         
   ( select t.instance
      from sys.v$thread  t,
              sys.v$parameter  v
     where v.name = 'thread'

--下面只不过保证字符转换数字不会出错
     and translate(v.value,'a1234567890.-','a') is null  --必须由数字和"."和"-"组成
   and translate(v.value,'1.-','1') is not null        --去掉"."和"-"后至少1个字符,也就是至少有1个数字啦
   and length(v.value) - length(replace(v.value,'.','')) < 2 --"."的个数必须少于2
   and (instr(v.value,'-',0)= 0 or (                         --没有"-"
                                     --或者只有1个"-"字符,而且用"-"开头
                                    (length(v.value) - length(replace(v.value,'-','')) = 1)
                                     and  substr(v.value,1,1) ='-'))

     and (v.value = '0' or
             t.thread# = to_number(v.value))) i,
    --path
   ( select value
    from sys.v$parameter
    where name = 'user_dump_dest') d
 /





如上图,得到记录文件
/u01/app/oracle/project/diag/rdbms/orcl/orcl/trace/orcl_ora_15744.trc
命名是有规则的,实列名_ora_对应进程名(pid).trc

打开该文件
会见到如下信息, 会追踪到用户执行的sql语句
Failed to load resource: the server responded with a status of 500 (Internal Server Error)/dev-api/login:1 Failed to load resource: the server responded with a status of 500 (Internal Server Error)我f12前后端都看出了这个问题'use strict' const path = require('path') function resolve(dir) { return path.join(__dirname, dir) } const CompressionPlugin = require('compression-webpack-plugin') const name = process.env.VUE_APP_TITLE || '知识汇博客论坛' // 网页标题 const port = process.env.port || process.env.npm_config_port || 80 // 端口 // vue.config.js 配置说明 //官方vue.config.js 参考文档 https://cli.vuejs.org/zh/config/#css-loaderoptions // 这里只列一部分,具体配置参考文档 module.exports = { // 部署生产环境和开发环境下的URL。 // 默认情况下,Vue CLI 会假设你的应用是被部署在一个域名的根路径上 // 例如 https://www.ruoyi.vip/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.ruoyi.vip/admin/,则设置 baseUrl 为 /admin/。 publicPath: process.env.NODE_ENV === "production" ? "/" : "/", // 在npm run build 或 yarn build 时 ,生成文件的目录名称(要和baseUrl的生产环境路径一致)(默认dist) outputDir: 'dist', // 用于放置生成的静态资源 (js、css、img、fonts) 的;(项目打包之后,静态资源会放在这个文件夹下) assetsDir: 'static', // 是否开启eslint保存检测,有效值:ture | false | 'error' lintOnSave: process.env.NODE_ENV === 'development', // 如果你不需要生产环境的 source map,可以将其设置为 false 以加速生产环境构建。 productionSourceMap: false, // webpack-dev-server 相关配置 devServer: { host: '0.0.0.0', port: port, open: true, proxy: { // detail: https://cli.vuejs.org/config/#devserver-proxy [process.env.VUE_APP_BASE_API]: { target: `http://localhost:8080`, changeOrigin: true, pathRewrite: { ['^' + process.env.VUE_APP_BASE_API]: '' } }, "/queryProjectForTest": { target: `http://10.48.254.155/default/`, changeOrigin: true, pathRewrite: { '^/queryProjectForTest': '' } } }, disableHostCheck: true }, css: { loaderOptions: { sass: { sassOptions: { outputStyle: "expanded" } } } }, configureWebpack: { name: name, resolve: { alias: { '@': resolve('src') } }, plugins: [ // http://doc.ruoyi.vip/ruoyi-vue/other/faq.html#使用gzip解压缩静态文件 new CompressionPlugin({ cache: false, // 不启用文件缓存 test: /\.(js|css|html|jpe?g|png|gif|svg)?$/i, // 压缩文件格式 filename: '[path][base].gz[query]', algorithm: 'gzip', // 使用gzip压缩 // threshold: 10240, // 只有大于 10kb 的文件会被压缩 minRatio: 0.8, // 压缩比例,小于 80% 的文件不会被压缩 deleteOriginalAssets: false // 压缩后删除原文件 }) ], }, chainWebpack(config) { config.plugins.delete('preload') // TODO: need test config.plugins.delete('prefetch') // TODO: need test // set svg-sprite-loader config.module .rule('svg') .exclude.add(resolve('src/assets/icons')) .end() config.module .rule('icons') .test(/\.svg$/) .include.add(resolve('src/assets/icons')) .end() .use('svg-sprite-loader') .loader('svg-sprite-loader') .options({ symbolId: 'icon-[name]' }) .end() config.when(process.env.NODE_ENV !== 'development', config => { config .plugin('ScriptExtHtmlWebpackPlugin') .after('html') .use('script-ext-html-webpack-plugin', [{ // `runtime` must same as runtimeChunk name. default is `runtime` inline: /runtime\..*\.js$/ }]) .end() config.optimization.splitChunks({ chunks: 'all', cacheGroups: { libs: { name: 'chunk-libs', test: /[\\/]node_modules[\\/]/, priority: 10, chunks: 'initial' // only package third parties that are initially dependent }, elementUI: { name: 'chunk-elementUI', // split elementUI into a single package test: /[\\/]node_modules[\\/]_?element-ui(.*)/, // in order to adapt to cnpm priority: 20 // the weight needs to be larger than libs and app or it will be packaged into libs or app }, commons: { name: 'chunk-commons', test: resolve('src/components'), // can customize your rules minChunks: 3, // minimum common number priority: 5, reuseExistingChunk: true } } }) config.optimization.runtimeChunk('single') }) } } 看看这个'use strict' const path = require('path') function resolve(dir) { return path.join(__dirname, dir) } const CompressionPlugin = require('compression-webpack-plugin') const name = process.env.VUE_APP_TITLE || '博客论坛系统' // 网页标题 const port = process.env.port || process.env.npm_config_port || 90 // 端口 // vue.config.js 配置说明 //官方vue.config.js 参考文档 https://cli.vuejs.org/zh/config/#css-loaderoptions // 这里只列一部分,具体配置参考文档 module.exports = { // 部署生产环境和开发环境下的URL。 // 默认情况下,Vue CLI 会假设你的应用是被部署在一个域名的根路径上 // 例如 https://www.ruoyi.vip/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.ruoyi.vip/admin/,则设置 baseUrl 为 /admin/。 publicPath: process.env.NODE_ENV === "production" ? "/" : "/", // 在npm run build 或 yarn build 时 ,生成文件的目录名称(要和baseUrl的生产环境路径一致)(默认dist) outputDir: 'dist', // 用于放置生成的静态资源 (js、css、img、fonts) 的;(项目打包之后,静态资源会放在这个文件夹下) assetsDir: 'static', // 是否开启eslint保存检测,有效值:ture | false | 'error' lintOnSave: process.env.NODE_ENV === 'development', // 如果你不需要生产环境的 source map,可以将其设置为 false 以加速生产环境构建。 productionSourceMap: false, // webpack-dev-server 相关配置 devServer: { host: '0.0.0.0', port: port, open: true, proxy: { // detail: https://cli.vuejs.org/config/#devserver-proxy [process.env.VUE_APP_BASE_API]: { target: `http://localhost:8080`, changeOrigin: true, pathRewrite: { ['^' + process.env.VUE_APP_BASE_API]: '' } }, "/queryProjectForTest": { target: `http://10.48.254.155/default/`, changeOrigin: true, pathRewrite: { '^/queryProjectForTest': '' } } }, disableHostCheck: true }, css: { loaderOptions: { sass: { sassOptions: { outputStyle: "expanded" } } } }, configureWebpack: { name: name, resolve: { alias: { '@': resolve('src') } }, plugins: [ // http://doc.ruoyi.vip/ruoyi-vue/other/faq.html#使用gzip解压缩静态文件 new CompressionPlugin({ cache: false, // 不启用文件缓存 test: /\.(js|css|html|jpe?g|png|gif|svg)?$/i, // 压缩文件格式 filename: '[path][base].gz[query]', algorithm: 'gzip', // 使用gzip压缩 // threshold: 10240, // 只有大于 10kb 的文件会被压缩 minRatio: 0.8, // 压缩比例,小于 80% 的文件不会被压缩 deleteOriginalAssets: false // 压缩后删除原文件 }) ], }, chainWebpack(config) { config.plugins.delete('preload') // TODO: need test config.plugins.delete('prefetch') // TODO: need test // set svg-sprite-loader config.module .rule('svg') .exclude.add(resolve('src/assets/icons')) .end() config.module .rule('icons') .test(/\.svg$/) .include.add(resolve('src/assets/icons')) .end() .use('svg-sprite-loader') .loader('svg-sprite-loader') .options({ symbolId: 'icon-[name]' }) .end() config.when(process.env.NODE_ENV !== 'development', config => { config .plugin('ScriptExtHtmlWebpackPlugin') .after('html') .use('script-ext-html-webpack-plugin', [{ // `runtime` must same as runtimeChunk name. default is `runtime` inline: /runtime\..*\.js$/ }]) .end() config.optimization.splitChunks({ chunks: 'all', cacheGroups: { libs: { name: 'chunk-libs', test: /[\\/]node_modules[\\/]/, priority: 10, chunks: 'initial' // only package third parties that are initially dependent }, elementUI: { name: 'chunk-elementUI', // split elementUI into a single package test: /[\\/]node_modules[\\/]_?element-ui(.*)/, // in order to adapt to cnpm priority: 20 // the weight needs to be larger than libs and app or it will be packaged into libs or app }, commons: { name: 'chunk-commons', test: resolve('src/components'), // can customize your rules minChunks: 3, // minimum common number priority: 5, reuseExistingChunk: true } } }) config.optimization.runtimeChunk('single') }) } } 还有这个,以及会不会是数据库的问题DONE Compiled successfully in 14097ms 13:35:08 App running at: - Local: http://localhost:90/ - Network: http://10.225.73.250:90/ Note that the development build is not optimized. To create a production build, run npm run build. (node:14604) [DEP0060] DeprecationWarning: The `util._extend` API is deprecated. Please use Object.assign() instead. (Use `node --trace-deprecation ...` to show where the warning was created) Proxy error: Could not proxy request /captchaImage from localhost:90 to http://localhost:8080/. See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (ECONNREFUSED). Proxy error: Could not proxy request /login from localhost:90 to http://localhost:8080/. See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (ECONNREFUSED). Proxy error: Could not proxy request /login from localhost:90 to http://localhost:8080/. See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (ECONNREFUSED). Proxy error: Could not proxy request /login from localhost:90 to http://localhost:8080/. See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (ECONNREFUSED).这个呢 DONE Compiled successfully in 12082ms 13:37:38 App running at: - Local: http://localhost:80/ - Network: http://10.225.73.250:80/ Note that the development build is not optimized. To create a production build, run npm run build. (node:27848) [DEP0060] DeprecationWarning: The `util._extend` API is deprecated. Please use Object.assign() instead. (Use `node --trace-deprecation ...` to show where the warning was created) Proxy error: Could not proxy request /captchaImage from localhost to http://localhost:8080/. See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (ECONNREFUSED). Proxy error: Could not proxy request /login from localhost to http://localhost:8080/. See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (ECONNREFUSED). Proxy error: Could not proxy request /login from localhost to http://localhost:8080/. See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (ECONNREFUSED). 解析一下以上是我遇到的问题的一部分报错情况和一些代码,我在idea上运行的这个项目
09-29
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

nvd11

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值