存档
本博客已经有一篇关于的:Sybase ASE 统计当前执行的SQL语句的存储过程!
现在提供另外一种方法:使用系统存储过程sp_monitor查看当前数据库连接中正在执行的SQL语句信息!
sp_monitor connection
在执行上面语句之前需要启用对connection的监控, 执行:sp_monitor enable,connection。可以在监控完成后关闭该选项。
设置参数:max SQL text monitored为2048,该参数为静态参数,需要重启ASE。
sp_monitor connection的结果默认按照连接占用的cpu时间和等待时间的总和进行逆序排序。
sp_monitor connection的第二个参数有:cpu , diskio , elapsed time 分别表示按照cpu时间、物理读取次数、cpu时间+等待时间 进行逆序排序。
在查看完正在执行的SQL语句内容后,关闭对connection的监控以减少对生产服务器的影响。
执行的语句如下:
sp_configure "max SQL text monitored",2048
go
--reboot ASE
--...
sp_monitor enable,connection
go
sp_monitor connection
go
-- some SQL statement
-- ...
sp_monitor disable,connection
go
Job Scheduler 提供了定义和调度数据库管理和维护任务的能力,从而简化了 ASE 的管理。有了 Job Scheduler,就可以将通常需要数据库管理员干预的作业安排为在合适的时间以无人值守的方式运行,从而让数据库管理员腾出手来关注其它问题。
先介绍四个属于:作业、日程表、作业历史、预定作业、Job Scheduler任务、Job Scheduler代理、目标服务器、模板。
作业:在一次数据库操作中,例如备份、更新统计信息和转储数据库,对数据库执行的一个或多个系列操作。
日程表:定义了执行作业的时间以及如何重复执行作业。
作业历史:曾经执行过的预定作业。
预定作业:是指已绑定到某个日程表的作业。只有经过调度的作业才会执行。
Job Scheduler 任务(JS 任务):是功能性组件,负责管理日程表和及时通知 Job Scheduler 代理执行某个特定作业。
Job Scheduler 代理(JS 代理):是功能性组件,负责在接到 JS 任务通知时执行某个作业。
重复执行的日程表:是将要多次执行的日程表。所有重复执行的日程表都必须有开始和结束时间。
目标服务器:是预定要在其上运行业务的 Adaptive Server。
模板:是一组带有参数的 Transact-SQL (T-SQL) 语句,可用于在 Job Scheduler 中创建作业。
当您手边没有Sybase ASE服务器或者客户端环境时,当您想查看一些命令或参数而又不方便接触ASE服务器时,您可以考虑使用这台互联网上的ASE测试服务器。
本博客为Sybase初学者或者DBA完全免费提供此ASE15.0.3测试服务器。ASE所在的服务器为本博主自费购买的美国VPS虚拟机。
目前,ASE测试服务器仅支持php页面访问。使用ASE客户端直连服务器的方式后续可能会开通。
试用方法:
直接访问该页面:
试用说明:
1.本测试服务器版本为:ASE 15.0.3 ESD#4.1 / ASE 15.7 SP101,部署在Centos 5.6 64bit上;
2.本测试服务器使用免费版本:Express Edition,最多支持1 CPU,2G 内存,5G 数据库空间;
3.使用登录tpchuser连接服务器,登录tpchuser为数据库megaphone的属主,登录tpchuser不拥有sa_role角色;
4.数据库megaphone中有几张表:service、month、residential_customer(10万行)、telco_facts(120万行);
5.SQL语句执行结果有两种显示方法:表格和文本形式,表格形式使用PHP的sybase_query等函数,文本形式使用isql调用SQL文件;
6.PHP中函数sybase_query只能返回一个结果集,对于返回多个结果集的存储过程或者SQL语句块 请使用文本形式查看执行结果;
7.对于不熟悉的命令,可以使用语法数据库sybsyntax,比如:sp_syntax 'update statistics'会显示更新统计信息的相关语法;
8.请不要执行具有破坏性的语句或命令,一些示例SQL语句请参考:queries.sql
9.有问题或者建议请发邮件:dbainfo(c)126.com
Sybase ASE对null is null的处理结果是什么呢?
下面的SQL语句会返回所有的对象名吗?
select name from sysobjects where type=null or null is null
答案是:根据ASE版本不同,结果也不同。
在ASE v15.0.3之前的版本中会报下面的错误:
Invalid operator for datatype op: is null type: VOID TYPE.
在v15.0.3及以后的版本中,对is null的处理结果和我们平时直观的想法相同,
上面SQL语句会返回所有的对象名称。
Sybase ASE 15.0.3新特性
Operating System |
Sol Sparc32 |
Sol Sparc 64 |
HP PA RISC 64 |
AIX64 |
Linux x86 |
Windows x86 |
Linux Power |
Linux x64 |
Solaris x64 |
HP UX Itanium || |
Windows x64 |
Options |
|||||||||||
High Availability |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
|
✔ |
|
✔ |
|
Security & Directory Services |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
Secure Socket Layer |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
|
✔ |
✔ |
✔ |
✔ |
Cybersafe Kerboros |
✔ |
✔ |
|
|
|
✔ |
|
|
|
|
|
MIT Kerberos |
✔ |
✔ |
✔ |
✔ |
✔ |
|
✔ |
✔ |
✔ |
✔ |
|
Platform Native Kerberos |
✔ |
✔ |
|
|
|
|
|
|
|
|
|
Fine Grained Access Control |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
Pluggable Authentication Module |
✔ |
✔ |
|
✔ |
✔ |
|
✔ |
✔ |
✔ |
✔ |
|
LDAP Server Directory |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
LDAP User Authentication |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
Encrypted Columns |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
|
✔ |
✔ |
✔ |
✔ |
Enhanced Full Text Search |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
|
✔ |
|
|
|
Partitions |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
Features Included with ASE |
|||||||||||
Cross Platform Dump and Load |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
Distributed Transaction |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
JobScheduler |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
ASE Replicator |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
IPv6 |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
Java Option |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
Native XML |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
Web Services |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
|
Content Management |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
Archived Database Access |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
IMPORTANT NOTES
生成响应记录文件:
setupConsole.exe -options-record c:\ase1503responsefile-record.txt
根据响应记录文件的内容进行ASE 15.0.3的静默安装:
setupConsole.exe -silent -options c:\ase1503responsefile-record.txt -W SybaseLicense.agreeToLicense=true -G replaceExistingResponse="yesToALL"
响应记录文件c:\ase1503responsefile-record.txt内容在此下载
响应记录文件中对ASE 15.0.3默认安装过程进行的改动有:
1.安装目录:d:\sybase
2.定制安装
3.追加了3个组件选项:Job Scheduler、Chinese Language Module、Shared
4.安装开发版
5.启用remember password选项
6.不配置新服务器
Sybase ASE自15.0.2后增加了用户自定义函数的功能。
在Sybase中,以 2010-10-18 12:30:01格式显示日期数据时,用convert函数不能实现,需要替换一下字符。
select convert(varchar,getdate(),117)
go
------------------------------
2010/10/18 20:51:10
(1 row affected)
利用函数str_replace替换上面返回的日期字符串中的/为-
str_replace(convert(char(19),getdate(),117),'/','-')
1> select str_replace(convert(char(19),getdate(),117),'/','-')
2> go-------------------
2010-10-18 20:53:13(1 row affected)
Sybase 在ASE v15.0.2 中新增了“应用程序”跟踪这个特性。
您可以利用“应用程序”跟踪功能收集一个正在运行中的客户会话的有用诊断信息,包括:执行查询、IO 消耗等;并且ASE 会自动把收集到的跟踪信息写到一个文本文件中。可以很方便得用这个特性来诊断一些系统性能瓶颈。
您只需要知道想要跟踪的会话的SPID(Server Process ID) 就可以对那个会话进行跟踪监控。应用系统的用户只需要被授予“set tracing ”权限就可以利用“应用程序”跟踪对自己的会话信息进行跟踪。
执行“应用程序”跟踪需要具有 set tracing 的权限。主要有两类用户:第一:具有sa或者sso角色的用户(默认具有set tracing权限);第二:被赋予了set tracing 执行权限的用户。下面会分别予以介绍。
(1) 具有管理员特权的用户(属于 sa 或者 sso 角色)
对其他用户连接会话启用“应用程序”跟踪,执行:
set tracefile "<file-path>" for <spid>
关闭刚才打开的针对其他用户连接会话的跟踪,需要执行:
set tracefile off for <spid>
备注:
(1) 针对某个用户会话启用跟踪时,需要知道它的SPID 并填写跟踪结果文件保存的路径。如果没有指定跟踪结果文件保存的路径,那么ASE 会自动保存到$SYBASE 目录下。
(2) 在一个会话中,只能有一个set tracefile 为启用状态;并且,某一个SPID 不能被多个会话同时跟踪。
(3) 当被跟踪的会话自己退出,或者跟踪被手动关闭时,ASE 会生成跟踪结果文件。
(4) 在“应用程序”跟踪的过程中,如果跟踪结果文件所在的磁盘空间被耗尽,那么ASE 会自动保存跟踪文件并结束本次“应用程序”跟踪。
(5) 用sp_helpapptrace 存储过程来查看当前正在执行中的所有应用程序跟踪信息。
(2) 被赋予“set tracing” 权限的应用程序用户
对自己的会话启用跟踪,执行:
set tracefile "<file-path>"
结束对自己的会话上的跟踪,使用:
set tracefile off
备注: 不能使用sp_helpapptrace过程来查看正在被跟踪的会话。
(3 ) 哪些信息可被用来跟踪?
在“应用程序”跟踪中可以追踪以下的set option 命令。
set show_sqltext <on/off>
set showplan <on/off>
set statistics io <on/off>
set statistics time <on/off>
set statistics plancost <on/off>
set option 的子命令也可被用来跟踪。
set option show_lop <normal/brief/long/on/off> ---显示使用的逻辑操作数量
set option show_managers <normal/brief/long/on/off> --- 显示使用的数据结构管理器的数量
set option show_log_props <normal/brief/long/on/off> --- 显示所用的逻辑属性
set option show_parallel <normal/brief/long/on/off> --- 显示并行查询优化器信息
set option show_histograms <normal/brief/long/on/off> --- 显示直方图统计信息处理过程
set option show_abstract_plan <normal/brief/long/on/off> --- 显示虚拟查询计划具体信息
set option show_search_engine <normal/brief/long/on/off> --- 显示搜索引擎的详细信息
set option show_counters <normal/brief/long/on/off> --- 显示优化器找到的计划的数量
set option show_best_plan <normal/brief/long/on/off> --- 显示最优计划信息
set option show_code_gen <normal/brief/long/on/off> --- 显示代码产生器的信息
set option show_pio_costing <normal/brief/long/on/off> --- 显示估计的物理IO数
set option show_lio_costing <normal/brief/long/on/off> --- 显示估计的逻辑IO数
set option show_elimination <normal/brief/long/on/off> --- 显示分区消除信息
(4) 例子 (使用具有sa 和sso 角色的用户)
在一个会话中执行如下的命令:
set tracefile "c:/tmp/trace-spid-16.txt" for 16
set show_sqltext on
set showplan on
go
sp_helpapptrace
go
traced_spid tracer_spid trace_file
----------- ----------- ----------------------------
16 19 c:/tmp/ase-trace-spid-16.txt
(1 row affected)
(return status = 0)
上面的输出结果表明该会话的spid为16。
在另外一个会话中,在被监控的用户会话spid=16中执行sp_helpdb过程。
set tracefile off for 16
go
sp_helpapptrace
go
traced_spid tracer_spid trace_file
----------- ----------- ----------
(0 rows affected)
(return status = 0)
跟踪结果信息如下:
================================================================================
Application Tracing report for spid -1 from application "isql"
run by login "sa" on host "TEST"
Tracing started on 2010/04/24 17:08:10.23
================================================================================
No useful sqltext available.
QUERY PLAN FOR STATEMENT 1 (at line 1).
STEP 1
The type of query is EXECUTE.
2010/04/24 17:08:10.23
No useful sqltext available.
Sproc: sp_helpdb, Line: 0
QUERY PLAN FOR STATEMENT 1 (at line 0).
STEP 1
The type of query is DECLARE.
Sproc: sp_helpdb, Line: 38
QUERY PLAN FOR STATEMENT 2 (at line 38).
STEP 1
The type of query is COND.
1 operator(s) under root
|ROOT:EMIT Operator (VA = 1)
|
| |SCALAR Operator (VA = 0)
Sproc: sp_helpdb, Line: 40
QUERY PLAN FOR STATEMENT 3 (at line 40).
STEP 1
The type of query is SET OPTION OFF.
Sproc: sp_helpdb, Line: 43
QUERY PLAN FOR STATEMENT 4 (at line 43).
STEP 1
The type of query is SET OPTION ON.
Sproc: sp_helpdb, Line: 45
QUERY PLAN FOR STATEMENT 5 (at line 45).
STEP 1
The type of query is SELECT.
1 operator(s) under root
|ROOT:EMIT Operator (VA = 1)
|
| |SCALAR Operator (VA = 0)
Sproc: sp_helpdb, Line: 47
QUERY PLAN FOR STATEMENT 6 (at line 47).
STEP 1
The type of query is COND.
1 operator(s) under root
|ROOT:EMIT Operator (VA = 1)
|
| |SCALAR Operator (VA = 0)
Sproc: sp_helpdb, Line: 49
QUERY PLAN FOR STATEMENT 7 (at line 49).
STEP 1
The type of query is COND.
3 operator(s) under root
|ROOT:EMIT Operator (VA = 3)
|
| |RESTRICT Operator (VA = 2)(0)(0)(0)(4)(0)
| |
| | |SCALAR AGGREGATE Operator (VA = 1)
| | | Evaluate Ungrouped ANY AGGREGATE.
| | | Scanning only up to the first qualifying row.
| | |
| | | |SCAN Operator (VA = 0)
| | | | FROM TABLE
| | | | master.dbo.sysmessages
| | | | Index : ncsysmessages
| | | | Forward Scan.
| | | | Positioning by key.
| | | | Index contains all needed columns. Base table will not be read.
| | | | Keys are:
| | | | error ASC
| | | | Using I/O Size 2 Kbytes for index leaf pages.
| | | | With LRU Buffer Replacement Strategy for index leaf pages.
Sproc: sp_helpdb, Line: 53
QUERY PLAN FOR STATEMENT 8 (at line 53).
STEP 1
The type of query is SELECT.
1 operator(s) under root
|ROOT:EMIT Operator (VA = 1)
|
| |SCALAR Operator (VA = 0)
Sproc: sp_helpdb, Line: 55
QUERY PLAN FOR STATEMENT 9 (at line 55).
STEP 1
The type of query is COND.
3 operator(s) under root
|ROOT:EMIT Operator (VA = 3)
|
| |RESTRICT Operator (VA = 2)(0)(0)(0)(4)(0)
| |
| | |SCALAR AGGREGATE Operator (VA = 1)
| | | Evaluate Ungrouped ANY AGGREGATE.
| | | Scanning only up to the first qualifying row.
| | |
| | | |SCAN Operator (VA = 0)
| | | | FROM TABLE
| | | | master.dbo.sysmessages
| | | | Index : ncsysmessages
| | | | Forward Scan.
| | | | Positioning by key.
| | | | Index contains all needed columns. Base table will not be read.
| | | | Keys are:
| | | | error ASC
| | | | Using I/O Size 2 Kbytes for index leaf pages.
| | | | With LRU Buffer Replacement Strategy for index leaf pages.
Sproc: sp_helpdb, Line: 59
QUERY PLAN FOR STATEMENT 10 (at line 59).
STEP 1
The type of query is SELECT.
1 operator(s) under root
|ROOT:EMIT Operator (VA = 1)
|
| |SCALAR Operator (VA = 0)
Sproc: sp_helpdb, Line: 0
QUERY PLAN FOR STATEMENT 11 (at line 0).
STEP 1
The type of query is GOTO.
Sproc: sp_helpdb, Line: 0
QUERY PLAN FOR STATEMENT 12 (at line 0).
STEP 1
The type of query is GOTO.
Sproc: sp_helpdb, Line: 62
QUERY PLAN FOR STATEMENT 13 (at line 62).
STEP 1
The type of query is SET OPTION ON.
Sproc: sp_helpdb, Line: 69
QUERY PLAN FOR STATEMENT 14 (at line 69).
STEP 1
The type of query is COND.
1 operator(s) under root
|ROOT:EMIT Operator (VA = 1)
|
| |SCALAR Operator (VA = 0)
Sproc: sp_helpdb, Line: 70
QUERY PLAN FOR STATEMENT 15 (at line 70).
STEP 1
The type of query is SELECT.
2 operator(s) under root
|ROOT:EMIT Operator (VA = 2)
|
| |SCALAR AGGREGATE Operator (VA = 1)
| | Evaluate Ungrouped COUNT AGGREGATE.
| |
| | |SCAN Operator (VA = 0)
| | | FROM TABLE
| | | master.dbo.sysdatabases
| | | Index : ncsysdatabases
| | | Forward Scan.
| | | Positioning at index start.
| | | Index contains all needed columns. Base table will not be read.
| | | Using I/O Size 2 Kbytes for index leaf pages.
| | | With LRU Buffer Replacement Strategy for index leaf pages.
Sproc: sp_helpdb, Line: 73
QUERY PLAN FOR STATEMENT 16 (at line 73).
STEP 1
The type of query is SELECT.
3 operator(s) under root
|ROOT:EMIT Operator (VA = 3)
|
| |SCALAR AGGREGATE Operator (VA = 2)
| | Evaluate Ungrouped COUNT AGGREGATE.
| |
| | |RESTRICT Operator (VA = 1)(0)(0)(0)(6)(0)
| | |
| | | |SCAN Operator (VA = 0)
| | | | FROM TABLE
| | | | master.dbo.sysdatabases
| | | | Using Clustered Index.
| | | | Index : cdatabases
| | | | Forward Scan.
| | | | Positioning at index start.
| | | | Index contains all needed columns. Base table will not be read.
| | | | Using I/O Size 2 Kbytes for index leaf pages.
| | | | With LRU Buffer Replacement Strategy for index leaf pages.
Sproc: sp_helpdb, Line: 80
————————————————————————————————-
—- 本文为andkylee个人原创,请在尊重作者劳动成果的前提下进行转载;
—- 转载务必注明原始出处 : http://www.dbainfo.net
—- 关键字:tracefile showplan statistics 跟踪 会话
————————————————————————————————-