“help”操作语法:
sp_spaceusage 'help'[, 'all']
sp_spaceusage 'help'[, {'display' | 'display summary' | 'report' | 'report summary' | 'archive'}[, {'table' | 'index' | 'tranlog'}]]
“display”操作语法:
sp_spaceusage 'display summary [using unit= {KB | MB | GB | PAGES}]',
{'table' | 'index'},<name>
[, <where_clause>[, order_by[,<command>]]]
sp_spaceusage 'display [using unit= {KB | MB | GB | PAGES} ]',
{'table' | 'index'}, <name>
[, <select_list>
[, <where_clause>[, order_by[, <command>]]]]
sp_spaceusage 'display [using unit={KB | MB | GB | PAGES}]',
'tranlog'[, <name>[, <select_list>[, <where_clause> [, order_by]]]]
sp_spaceusage 'display [using unit=<unit>]',
'sysimrslogs' [,{'sysimrslogs'|NULL}
[,<select_list> [,<where_clause> [,order_by]]]]
display database 操作语法:
sp_spaceusage 'display [summary] [using unit={KB | MB | GB | PAGES}]', 'database'
[, <db_name>]
sp_spaceusage 'display [using unit={KB | MB | GB | PAGES}]', 'database' [, <db_name>]
“archive”操作语法:
sp_spaceusage 'archive [using {<using_item> [,<using_item>]
', {'table' | 'index'}, <name>[, <where_clause>[, <command>]]
sp_spaceusage 'archive [using {<using_item> [,<using_item>]...} ]
', 'sysimrslogs' [,{'sysimrslogs'|NULL}[, <where_clause>]]
sp_spaceusage 'archive [using {<using_item> [,<using_item>]...} ]
', 'syslogs' [,{'syslogs'|NULL} [, <where_clause>]]
<using_item> = { unit={ KB | MB | GB | PAGES }
| dbname=<database_name> | prefix=<string>}
“report”操作语法:
sp_spaceusage 'report summary [using {<using_item> [,<using_item>]...}',
{'table' | 'index'}, <name>
[, <where_clause> [, order_by[, <from_date> [, <to_date>]]]]
sp_spaceusage 'report [using {<using_item> [,<using_item>]...}',
{'table' | 'index'}, <name>
[,<select_list>[, <where_clause> [, order_by[,<from_date> [,<to_date>]]]]]
sp_spaceusage 'report [using {<using_item> [,<using_item>]...}',
'tranlog'[, <name>
[,<select_list>[, <where_clause>[, order_by
[,<from_date>[, <to_date>]]]]]]
<using_item> = { unit={ KB | MB | GB | PAGES }
| dbname=<database_name> | prefix=<string>}
help
显示完整的 sp_spaceusage 语法。help <action> 显示受支持的各项操作的语法。
display
显示指定对象的当前空间使用信息。database 允许您在位于任何其它数据库中时显示任何数据库的信息。这表示,当前可以在 user_db 数据库中工作,并显示 sybsystemprocs 数据库的使用信息。
display summary
显示指定对象的当前空间使用信息摘要。
archive
将空间使用报告存档到表中。如果存档表尚不存在,sp_spaceusage 将创建一个。新数据将附加到现有数据中。使用 <using> 子句可为存档表名和存档表所在的数据库指定前缀。存档需要您启用 select into/bulkcopy/pllsort 数据库选项。
report
根据以前存档的数据,报告指定对象的空间使用信息。该输出与 display 操作相同。包括可选的 using 子句,用以指定存档表。
report summary
根据以前存档的数据,报告指定对象的空间使用信息摘要。该输出与 display summary 操作相同。包括可选的 using 子句,用以指定存档表。
<using_item>
为存档表指定单位、存档数据库名称和前缀字符串。可以使用千字节 (KB)、兆字节 (MB)、千兆字节 (GB) 和页表示 <unit> 大小。缺省情况下,<unit> 大小为 KB,当前数据库是存档数据库,并且不使用前缀字符串。
<name>
是实体的名称。根据实体类型,可以包括由多个部分组成的名称,如 <owner_name.table_name> 或 <owner_name.table_name.index_name>。对于实体类型 tranlog、syslogs 和 sysimrslogs,名称必须为 syslogs、sysimrslogs 或 NULL。在由多个部分组成的名称中,每个部分都允许使用模式指示符,以支持在一次传递中报告多个对象。
<select_list>
是以逗号分隔的一组列,要在输出列中选择这些列供 display 和 report 操作使用。使用 * 将包括输出中的所有列。可使用 alias=<name> 表示法对列进行重命名。
<where_clause>
是应用于结果集的过滤器。与 display、report 或 archive 操作一起使用可选择性地过滤掉不必要的数据。
order_by
按排序顺序返回指定列中的查询结果。
<command>
在收集空间使用信息之前为限定对象对所选实体(表、列等)运行的命令。支持以下命令:update statistics、update table statistics 和 update index statistics。
<from_date>
指定您感兴趣的时间范围的开始时间。
<to_date>
指定您感兴趣的时间范围的结束时间。
显示 display 操作的简要说明、语法和用法信息:
sp_spaceusage 'help', 'display'
Display the space usage information for an entity in the current database.
Usage:
sp_spaceusage 'display', 'database' [, '<dbname>' ]
sp_spaceusage 'display', {'table'|'index'}, <name>
[,<select_list> [,<where_clause> [, order_by [,<command>]]]]
sp_spaceusage 'display summary', {'table'|'index'}, <name>
[,<where_clause> [, order_by [, <command>]]]
sp_spaceusage 'display', 'syslogs' [,{'syslogs'|NULL}
[,<select_list> [, <where_clause> [, order_by]]]]
sp_spaceusage 'display', 'sysimrslogs' [,{'sysimrslogs'|NULL}
[,<select_list> [, <where_clause> [,order_by]]]]
For more information, use:
sp_spaceusage 'help', 'display', 'database'
sp_spaceusage 'help', 'display', 'table'
sp_spaceusage 'help', 'display', 'index'
sp_spaceusage 'help', 'display', 'syslogs'
sp_spaceusage 'help', 'display', 'sysimrslogs'
显示 titles 表的空间使用摘要:
sp_spaceusage 'display summary', 'table', 'titles'
All the page counts in the result set are in the unit 'KB'.
OwnerName TableName Type UsedPages RsvdPages ExpRsvdPages PctBloatRsvdPages
--------- --------- ---- --------- -------- ------------ -----------------
dbo titles DATA 6.0 30.0 16.0 87.50
dbo titles INDEX 8.0 64.0 32.0 50.00
显示 titles 表的空间使用信息:
sp_spaceusage 'display', 'table', 'titles'
All the page counts in the result set are in the unit 'KB'.
OwnerName TableName IndId NumRows UsedPages RsvdPages
ExtentUtil ExpRsvdPages PctBloatUsePages PctBloatRsvdPages
----------- ----------- ------ ----------- ---------- --------------
---------- ------------ ---------------- -----------------
dbo titles 0 18.0 6.0 30.0
20.00 16.0 0.0 87.50
dbo titles 1 NULL 4.0 32.0
12.50 16.0 0.00 100.00
dbo titles 2 NULL 4.0 32.0
12.50 16.0 0.00 100.00
显示 titles 表中名称以 title 开始的索引条目:
sp_spaceusage 'display using unit=MB', 'index', 'titles.title%'
All the page counts in the result set are in the unit 'MB'.
OwnerName TableName IndId IndexName UsedPages RsvdPages
ExtentUtil ExpRsvdPages PctBloatUsedPages PctBloatRsvdPages
-------- -------- ----- ---------- ---------- ---------
---------- ------------ ----------------- ----------------
dbo titles 0 titles .005859375 .029296875
20.00 .015625 0.00 87.50
dbo titles 1 titleidind .00390625 .03125
12.50 .015625 0.00 100.00
dbo titles 2 titleind .00390625 .03125
12.50 .015625 0.00 100.00
(1 row affected)
(return status = 0)
显示 titles 表中名称以
sp_spaceusage 'display summary', 'index', 'titles.title%'
All the page counts in the result set are in the unit of 'KB'.
OwnerName TableName IndexName IndId UsedPages RsvdPages ExpRsvdPages
PctBloatRsvdPages
-------- --------- --------- ----- --------- ---------- ------------
-----------------
dbo titles titles 0 6.0 30.0 16.0
46.67
dbo titles titleidind 1 4.0 32.0 16.0
50.00
dbo titles titleind 2 4.0 32.0 16.0
50.00
显示 titles 表中以 <title> 开头并且 PctBloatRsvdPages 值小于 50 的所有索引的空间使用摘要:
sp_spaceusage 'display summary', 'index', 'titles.title%',
'where PctBloatRsvdPages < 50'
All the page counts in the result set are in the unit 'KB'.
OwnerName TableName IndexName IndId UsedPages RsvdPages ExpRsvdPages
PctBloatRsvdPages
--------- --------- --------- ----- --------- --------- ----------
-----------------
dbo titles titles 0 6.0 30.0 16.0
46.67
按 PctBloatRsvdPages 的降序显示 titles 表中 PctBloatRsvdPages 值大于 30 的所有索引的空间使用摘要:
sp_spaceusage 'display summary', 'index', 'titles.title%',
'where PctBloatRsvdPages > 30', 'order by PctBloatRsvdPages desc'
All the page counts in the result set are in the unit 'KB'.
OwnerName TableName IndexName IndId UsedPages RsvdPages ExpRsvdPages
PctBloatRsvdPages
--------- --------- --------- ----- --------- --------- ----------
-----------------
dbo titles titleidind 1 4.0 32.0 16.0
50.00
dbo titles titleind 2 4.0 32.0 16.0
50.00
dbo titles titles 0 6.0 30.0 16.0
46.67
对 authors 表运行 update table statistics 并以 <pages> 为单位汇总其空间使用信息:
sp_spaceusage 'display summary using unit=pages', 'table', 'authors', null, null, null,
'update table statistics'
All the page counts in the result set are in the unit 'pages'.
OwnerName TableName Type UsedPages RsvdPages ExpRsvdPages PctBloatRsvdPages
--------- --------- ---- --------- --------- ------------ -----------------
dbo authors DATA 2.0 16.0 8.0 100.00
dbo authors INDEX 4.0 32.0 16.0 50.00
显示当前数据库 (pubs2) 的事务日志的空间使用信息:
sp_spaceusage 'display', 'tranlog'
TableName TotalPages UsedPages CLRPagesFreePages PctUsedPages PctFreePages
--------- ----------- --------- ----------------- ------------- -----------
syslogs 4096.0 18.0 0.0 1482.0 0.43 36.18
将当前数据库中 authors 表的空间使用信息存档到缺省表中(对于表和索引,缺省表为 spaceusage_object):
sp_spaceusage 'archive', 'table', 'authors'
Data was successfully archived into table 'pubs2.dbo.spaceusage_object'.
将 authors 表的空间使用信息存档到 pubs3 数据库中的缺省表中(对于表和索引,缺省表为 spaceusage_object):
sp_spaceusage 'archive using dbname = pubs3', 'table', 'authors'
Data was successfully archived into table 'pubs3.dbo.spaceusage_object'.
对 authors 表运行 update table statistics 并将其空间使用信息存档到当前数据库中前缀为 monday_ 的表(此示例中为 monday_spaceusage_object)中:
sp_spaceusage 'archive using dbname = pubs2, prefix=monday_',
'table','authors', null, 'update table statistics'
将当前数据库的事务日志的空间使用信息存档到 pubs3 数据库的缺省表(对于事务日志,缺省表为 spaceusage_tranlog)中:
sp_spaceusage 'archive using dbname=pubs3', 'tranlog'
Data was successfully archived into table 'pubs3.dbo.spaceusage_tranlog'.
根据当前数据库中的缺省表(对于表或索引,缺省表为 spaceusage_object),详细报告上次存档的 authors 表的空间使用信息:
sp_spaceusage 'report', 'table', 'authors'
All the page counts in the result set are in the unit 'KB'.
All the data in the result set are dated 'Jun 15 2013 11:50PM'.
OwnerName TableName IndId NumRows UsedPages RsvdPages ExtentUtil
ExpRsvdPages PctBloatUsedPages PctBloatRsvdPages
--------- --------- ----- ------- --------- --------- ----------
------------ ----------------- -----------------
dbo authors 0 23.0 4.0 32.0 12.50
16.0 0.00 100.00
dbo authors 1 NULL 4.0 32.0 12.50
16.0 0.00 100.00
dbo authors 2 NULL 4.0 32.0 12.50
16.0 0.00 100.00
根据 pubs3 数据库中的缺省表,概要报告上次存档的 authors 表的空间使用信息:
sp_spaceusage 'report summary using dbname=pubs3', 'table', 'authors'
All the page counts in the result set are in the unit 'KB'.
All the data in the result set are dated 'Jan 17 2013 11:29AM'.
OwnerName TableName Type UsedPages RsvdPages ExpRsvdPages PctBloatRsvdPages
--------- --------- ---- ---------- -------- ------------ -----------------
dbo authors DATA 4.0 32.0 16.0 100.00
dbo authors INDEX 8.0 64.0 32.0 50.00
根据当前数据库中的 monday_spaceusage_object 表,报告上次存档的 authors 表的空间使用信息摘要(以兆字节为单位):
sp_spaceusage 'report summary using prefix=monday_, unit=MB', 'table', 'authors'
All the page counts in the result set are in the unit 'MB'.
All the data in the result set are dated 'Jan 17 2013 11:29AM'.
OwnerName TableName Type UsedPages RsvdPages ExpRsvdPages PctBloatRsvdPages
--------- --------- ---- ---------- -------- ------------ -----------------
dbo authors DATA .00390625 .03125 .015625 100.00
dbo authors INDEX .0078125 .0625 .03125 50.00
根据当前数据库中的缺省表,报告在 2013 年 6 月 9 日或之后存档的、authors 表上所有索引的空间使用信息:
sp_spaceusage 'report', 'index', 'authors.%', null, null, null, 'Jun 9 2013'
All the page counts in the result set are in the unit 'KB'.
ArchiveDateTime OwnerName TableName IndId IndexName UsedPages
RsvdPages ExtentUtil ExpRsvdPages PctBloatUsedPages PctBloatRsvdPages
--------------- --------- --------- ----- --------- ----------
--------- --------- ----------- ---------------- --------------
Jun 9 2013 12:06AM dbo authors 0 authors 4.0
32.0 12.50 16.0 0.00 100.00
Jun 10 2013 12:05AM dbo authors 0 authors 4.0
32.0 12.50 16.0 0.00 100.00
Jun 11 2013 11:35PM dbo authors 0 authors 4.0
32.0 12.50 16.0 0.00 100.00
Jun 9 2013 12:06AM dbo authors 1 auidind 4.0
32.0 12.50 16.0 0.00 100.00
Jun 10 2013 12:05AM dbo authors 1 auidind 4.0
32.0 12.50 16.0 0.00 100.00
Jun 11 2013 11:35PM dbo authors 1 auidind 4.0
32.0 12.50 16.0 0.00 100.
Jun 9 2013 12:06AM dbo authors 2 aunmind 4.0
32.0 12.50 16.0 0.00 100.00
Jun 10 2013 12:05AM dbo authors 2 aunmind 4.0
32.0 12.50 16.0 0.00 100.00
Jun 11 2013 11:35PM dbo authors 2 aunmind 4.0
32.0 12.50 16.0 0.00 100.00
(1 row affected)
(return status = 0)
根据当前数据库中的缺省表,报告在 2013 年 6 月 10 日与 2013 年 6 月 15 日之间存档的 authors 表的空间使用信息:
sp_spaceusage 'report', 'table', 'authors', null, null, null, 'Jun 10 2013', 'Jun 15 2013'
All the page counts in the result set are in the unit 'KB'.
ArchiveDateTime OwnerName TableName IndId NumRows UsedPages
RsvdPages ExtentUtil ExpRsvdPages PctBloatUsedPages PctBloatRsvdPages
--------------- --------- --------- ----- ------- ---------
--------- ---------- ------------ ----------------- --------------
Jun 10 2013 12:05AM dbo authors 0 23.0 4.0
32.0 12.50 16.0 0.00 100.00
Jun 11 2013 11:35PM dbo authors 0 23.0 4.0
32.0 12.50 16.0 0.00 100.00
Jun 13 2013 11:46PM dbo authors 0 23.0 4.0
32.0 12.50 16.0 0.00 100.00
Jun 14 2013 11:46PM dbo authors 0 23.0 4.0
32.0 12.50 16.0 0.00 100.00
Jun 14 2013 11:46PM dbo authors 0 23.0 4.0
32.0 12.50 16.0 0.00 100.00
Jun 10 2013 12:05AM dbo authors 1 NULL 4.0
32.0 12.50 16.0 0.00 100.00
Jun 11 2013 11:35PM dbo authors 1 NULL 4.0
32.0 12.50 16.0 0.00 100.00
Jun 13 2013 11:46PM dbo authors 1 NULL 4.0
32.0 12.50 16.0 0.00 100.00
Jun 14 2013 11:46PM dbo authors 1 NULL 4.0
32.0 12.50 16.0 0.00 100.00
Jun 14 2013 11:46PM dbo authors 1 NULL 4.0
32.0 12.50 16.0 0.00 100.00
Jun 10 2013 12:05AM dbo authors 2 NULL 4.0
32.0 12.50 16.0 0.00 100.00
Jun 11 2013 11:35PM dbo authors 2 NULL 4.0
32.0 12.50 16.0 0.00 100.00
Jun 13 2013 11:46PM dbo authors 2 NULL 4.0
32.0 12.50 16.0 0.00 100.00
Jun 14 2013 11:46PM dbo authors 2 NULL 4.0
32.0 12.50 16.0 0.00 100.00
Jun 14 2013 11:46PM dbo authors 2 NULL 4.0
32.0 12.50 16.0 0.00 100.00
(1 row affected)
(return status = 0)
显示使用 pubs2 数据库时有关 sybsystemprocs 的信息(sybsystemprocs 在下方以粗体显示):
sp_spaceusage 'display using unit=MB', 'database', sybsystemprocs
All the page counts in the result set are in the unit 'MB'.
TotalPages UsedPages FreePages PctUsedPages PctFreePages DataPages IndexPages LOBPages PctData PctIndex PctLOB
---------- --------- --------- ------------ ------------ --------- ---------- -------- ------- -------- ------
400.000 123.625 276.375 30.91 69.09 116.203 6.125 0.063 94.00 4.95 0.05
(1 row affected)
TableName TotalPages UsedPages CLRPages FreePages PctUsedPages PctFreePages
--------- ---------- --------- -------- ---------- ------------ ------------
syslogs 200.0 1.171875 0.0 198.828125 0.58 99.41
(1 row affected)
TableType Layer DataPages UsedPages RsvdPages UsedPct
------------- ----------- ---------- ---------- ---------- -------
All Tables All layers 122.359375 123.5625 145.671875 30.89
All Tables Data layer 122.359375 116.734375 131.078125 29.18
All Tables Index Layer 122.359375 6.703125 14.09375 1.68
All Tables LOB Layer 122.359375 .125 .5 0.03
System Tables Data layer 116.109375 116.546875 130.328125 29.14
System Tables Index layer 6.078125 6.671875 13.96875 1.67
System Tables LOB layer .0625 .125 .5 0.03
User Tables Data layer .09375 .1875 .75 0.05
User Tables Index layer .015625 .03125 .125 0.01
User Tables LOB layer NULL NULL NULL NULL
显示顶层的摘要,聚合 tpcc 数据库的数据库范围使用信息:
sp_spaceusage 'display summary using unit=GB', 'database', tpcc;
All the page counts in the result set are in the unit 'GB'.
TotalPages UsedPages FreePages PctUsedPages PctFreePages DataPages IndexPages LOBPages PctData PctIndex PctLOB
---------- --------- --------- ------------ ------------ --------- ---------- -------- ------- -------- ------
87.891 46.476 41.414 52.88 47.12 35.216 11.259 0.000 75.77 24.22 0.00
(1 row affected)
TableName TotalPages UsedPages CLRPages FreePages PctUsedPages PctFreePages
--------- ---------- ----------------- -------- ------------------ ------------ ------------
syslogs 58.59375 .2289886474609375 0.0 58.364761352539062 0.39 99.60
(1 row affected, return status = 0)
sp_dboption ... select into。
<from_date> 和 <to_date> 参数用于 report 操作。生成报告时,SAP ASE 服务器只使用存档表中指定时间范围内的数据。如果不包括 <from_date> 或 NULL,SAP ASE 服务器将使用 <to_date> 之前的所有存档数据。如果不包括 <to_date> 或 NULL,SAP ASE 服务器将使用当前日期作为 <to_date> 的值。如果既不包括 <from_date>,也不包括 <to_date>,SAP ASE 服务器将使用存档表中的最新数据生成报告。