TimesTen中表占用空间的计算有实算和估算两种,前者用于监控,后者用于预测。
实算使用ttComputeTabSizes + tablesize(tblsize)或dsmap内部工具,估算使用ttSize。
Command> create table test(a int, b timestamp, primary key(a));
Command>
declare a number := 1;
begin
for i in 1..100000 loop
a := a+1;
insert into test values(a, sysdate);
commit;
end loop;
end;
/
Command> tables;
ORACLE.TEST
1 table found.
Command> select count(*) from test;
< 100000 >
1 row found.
Command> create table test1 as select * from test where rownum <= 50000;
50000 rows inserted.
Command> tables;
ORACLE.TEST
ORACLE.TEST1
2 tables found.
Command> indexes;
Indexes on table ORACLE.TEST:
TEST: unique range index on columns:
A
1 index found.
Indexes on table ORACLE.TEST1:
No indexes found.
1 index found on 2 tables.
Command> call ttComputeTabSizes('ORACLE.TEST', 1);
Command> tablesize ORACLE.TEST
Sizes of ORACLE.TEST:
INLINE_ALLOC_BYTES: 6018272
NUM_USED_ROWS: 100000
NUM_FREE_ROWS: 96
AVG_ROW_LEN: 60
OUT_OF_LINE_BYTES: 0
METADATA_BYTES: 18416
TOTAL_BYTES: 6036688
LAST_UPDATED: 2016-05-03 07:32:47.000000
1 table found.
必须先用,tablesize才能显示结果。ttComputeTabSizes中的null表示计算所有表,1表示计算not inline列
Command> tablesize ORACLE.TEST1;
0 tables found.
Command> call ttComputeTabSizes(null, 1);
Command> tablesize ORACLE.TEST1;
Sizes of ORACLE.TEST1:
INLINE_ALLOC_BYTES: 3016832
NUM_USED_ROWS: 50000
NUM_FREE_ROWS: 176
AVG_ROW_LEN: 60
OUT_OF_LINE_BYTES: 0
METADATA_BYTES: 10000
TOTAL_BYTES: 3026832
LAST_UPDATED: 2016-05-03 07:44:14.000000
1 table found.
tablesize也支持通配符,如%。但不能累加,只能逐个显示。
Command> tablesize TEST%
Sizes of ORACLE.TEST:
INLINE_ALLOC_BYTES: 6018272
NUM_USED_ROWS: 100000
NUM_FREE_ROWS: 96
AVG_ROW_LEN: 60
OUT_OF_LINE_BYTES: 0
METADATA_BYTES: 18416
TOTAL_BYTES: 6036688
LAST_UPDATED: 2016-05-03 07:44:14.000000
Sizes of ORACLE.TEST1:
INLINE_ALLOC_BYTES: 3016832
NUM_USED_ROWS: 50000
NUM_FREE_ROWS: 176
AVG_ROW_LEN: 60
OUT_OF_LINE_BYTES: 0
METADATA_BYTES: 10000
TOTAL_BYTES: 3026832
LAST_UPDATED: 2016-05-03 07:44:14.000000
2 tables found.
tablesize好像没有计算索引占用空间。
ttSize用于估算,因此会有误差。它的定位是:
ttSize is not a reporting tool which analyses & summarises existing space utilisation for a table. Rather ttSize is an estimation tool intended for use by system architects to allow them to get an idea how big their datastore structures would be for a (user specified) number of rows.
TimesTen中既有ttSize内置过程,也有操作系统下的Utility程序。
先来看Utility程序,用法比较简单,通常只需指定表未来会达到的行数即可,如果不指定行数,则会用实际的行数,我们认为就不是估算而是计算了;而且此时会计算索引的空间。
ttSize -tbl [<owner>.]<tableName> [-rows <rows>] [-frac <frac>] {<DSN> | -connstr <connStr>}
唯一需要说明的选项是-frac,这是针对VARCHAR和VARBINARY这些变长列的,如果表存在,会进行表扫描以确定变长列空间占满程度,如果表不存在,则认为是50%占满。这也可以解释为何有时ttSize不会完全准确。
在下例中,我们估算test1表到10万行的情况,与已有的10万行记录的test表空间 6036688 相比,估算结果 6040494 还算准确。
[oracle@tt12c ~]$ ttSize -tbl oracle.test1 -rows 100000 sampledb_1122
Rows = 100000
Total in-line row bytes = 6040494
Total = 6040494
下例不指定行数,因此是实际计算,而且包含了索引。结果8075928与后面dsmap的结果‘Total usage for ORACLE.TEST= 8105200’很接近了。
[oracle@tt12c ~]$ ttSize -tbl oracle.test1 sampledb_1122
Rows = 50000
Total in-line row bytes = 3030654
Total = 3030654
[oracle@tt12c ~]$ ttSize -tbl oracle.test sampledb_1122
Rows = 100000
Total in-line row bytes = 6040494
Indexes:
Range index ORACLE.TEST adds 2035434 bytes
Total index bytes = 2035434
Total = 8075928
也可以使用与utility对应的built-in procudure来计算,
Command> call ttsize('test1', 100000, null);
< 6040494.00000000 >
1 row found.
Command> call ttsize('test1', null, null);
< 3030654.00000000 > <-行数指定为空,表示使用实际的行数,这与之前的结果‘TOTAL_BYTES: 3026832’比较接近了。
1 row found.
Command> call ttsize('test', null, null);
< 8075928.00000000 > <-比之前的结果‘TOTAL_BYTES:6036688’要大,后面通过dsmap的结果‘Total usage for ORACLE.TEST= 8105200’验证可知此结果包含了索引
1 row found.
dsmap是一个内部工具,运行时需要用checkpoint文件或shmid来指定data store,这和一般用DSN不同。
可以用ttstatus来查询shmid和得到data store路径,例如,输出Shared Memory KEY 0x3e001cf8 ID 622607
中得到shmid为622607
[oracle@tt12c support]$ ttadmin sampledb_1122 RAM Residence Policy : inUse Replication Agent Policy : manual Replication Manually Started : False Cache Agent Policy : manual Cache Agent Manually Started : False [oracle@tt12c support]$ ttstatus sampledb_1122
TimesTen status report as of Tue May 3 08:13:51 2016
Daemon pid 2346 port 53396 instance tt1122
TimesTen server pid 2355 started on port 53397 ------------------------------------------------------------------------
Data store /home/oracle/TimesTen/tt1122/info/DemoDataStore/sampledb_1122 There are 12 connections to the data store Shared Memory KEY 0x3e001cf8 ID 622607 PL/SQL Memory KEY 0x3f001cf8 ID 655376 Address 0x7fa0000000 Type PID Context Connection Name ConnID Process 3289 0x0000000001c1baf0 sampledb_1122 1
Subdaemon 2353 0x0000000001c65c50 Manager 142
Subdaemon 2353 0x0000000001cbd160 Rollback 141
Subdaemon 2353 0x0000000001d12770 IndexGC 133
Subdaemon 2353 0x00007ff1540008c0 Deadlock Detector 134
Subdaemon 2353 0x00007ff15c0008c0 Checkpoint 138
Subdaemon 2353 0x00007ff1600008c0 HistGC 137
Subdaemon 2353 0x00007ff1640008c0 Log Marker 135
Subdaemon 2353 0x00007ff1680008c0 AsyncMV 139
Subdaemon 2353 0x00007ff16c0008c0 Aging 140
Subdaemon 2353 0x00007ff16c055da0 Monitor 132
Subdaemon 2353 0x00007ff17c0734b0 Flusher 136
Replication policy : Manual
Cache Agent policy : Manual
PL/SQL enabled. ------------------------------------------------------------------------
Accessible by group oinstall
End of report
接下来可以使用-shmid或-dsname任意一种方式。例如:
./dsmap -dsname /home/oracle/TimesTen/tt1122/info/DemoDataStore/sampledb_1122.ds0 -tblsize oracle.test
或
./dsmap -shmid 622607 -tblsize oracle.test
如果使用-dsname,可以使用ttlogholds或ttckpthistory来确定最新的checkpoint文件,例如ttlogholds的输出中,最下ds1的为最新的。
Command> call ttlogholds; < 3, 57729024, Checkpoint , sampledb_1122.ds0 > < 3, 57731072, Checkpoint , sampledb_1122.ds1 > 2 rows found.
[oracle@tt12c support]$ ./dsmap -shmid 622607 -tblsize oracle.test
** 3 processes attached to the shm segment
2016-05-03 08:16:43.407
TimesTen Release 11.2.2.8.11
*** WARNING - Running against shared memory!
DSN = sampledb_1122
filesize = 161738600 (154.25m)
maxid_file = 75497472
maxid_ds = 75497472
Size information for ORACLE.TEST
Total logical pages = 391
Logical page space used = 1807984
In-line information
Total physical pages = 391
Used rows = 100000
Free rows = 96
Total in-line size = 4210288
Space usage information for index ORACLE.TEST
Index type is T-Tree
Hdr size = 1440
Node size = 672
Nodes = 3076
Total index usage = 2068512
System usage = 18416
Total usage for ORACLE.TEST= 8105200
与之前tablezie的输出对比,我们发现System usage
对应之前的METADATA_BYTES
,Logical page space used + Total in-line size
对应之前的INLINE_ALLOC_BYTES
。dsmap比tablesize多了索引空间的显示。
Sizes of ORACLE.TEST:
INLINE_ALLOC_BYTES: 6018272
NUM_USED_ROWS: 100000
NUM_FREE_ROWS: 96
AVG_ROW_LEN: 60
OUT_OF_LINE_BYTES: 0
METADATA_BYTES: 18416
TOTAL_BYTES: 6036688
LAST_UPDATED: 2016-05-03 08:35:57.000000
由以下输出可知,内存空间使用率为50%
Command> dssize m;
The following values are in MB:
PERM_ALLOCATED_SIZE: 40
PERM_IN_USE_SIZE: 20.037
PERM_IN_USE_HIGH_WATER: 20.037
TEMP_ALLOCATED_SIZE: 32
TEMP_IN_USE_SIZE: 9.225
TEMP_IN_USE_HIGH_WATER: 9.286