In real production world “Prediction” of data growth is an important aspects of DBA life because this will allow business not only to foresee the real position in terms of existing hardware but also enable to plan the future expenses which should be spent on hardware(s) & storage.
To generate data growth report, Oracle provides various means which will be explored here. We can track growth for an object (i.e. table, indexes) or for tablespaces or for schema or even at database level using the views provided by Oracle.
There are few important views provided by Oracle which helps us track the growth. These can be listed as:
- DBA_SEGMENTS
- DBA_TABLESPACES
- DBA_HIST_SEG_STAT
- DBA_HIST_TABLESPACE_STAT
- DBA_HIST_TBSPC_SPACE_USAGE
- DBA_HIST_SNAPSHOT
- DBMS_SPACE
View which does not have HIST in its name provides “accumulated till date” information. This means you can derive current size of an object using DBA_SEGMENTS & DBA_TABLESPACES. This view stores data usages information in terms of BYTES. To explain this, we can say here that when we create a table ( with segment allocation immediate option) Oracle allocates spaces for this object which is not utilised until we add a row. In simple terms used space is “High water mark” where Oracle has used the allocated space “up to”. This is brilliantly explained by “Ask The Oracle Masters (AskTOM)”
However, this view cannot give you a comparative data growth chart where you can see the past usages and forecast the future requirement of the storage. To generate such a report should visit history views.
Take DBA_HIST_SEG_STAT first. This view captures lot more information about the segments and obviously in historical form like logical reads, physical read, buffer busy wait, row lock waits, table scans, physical write besides space allocation and utilization both. When such historical view is combinedly red with DBA_HIST_SNAPSHOT we will get the required information in comparative form. To find data growth rate for any object we can refer this view.
To find growth rate of a tablespace we can also utilize another history view DBA_HIST_TABLESPACE_STAT & DBA_HIST_TBSPC_SPACE_USAGE with DBA_HIST_SNAPSHOT. By using these views, we can find the historical information of allocated spaces Vs. used storage.
However, I must highlight here that the historical information captured will remain be available in the database for those dates & for those snapshots only which is configured by DBA to be kept in the database. Beyond which, we cannot get such information. For example, if DBA has configured 15 days of snapshot to be kept, we can retrieve such comparative information for last 15 days only.
If we want such comparison report for a year or more, we should follow alternate ways. We may create a table which can be populated with such information by a scheduled job and instead of querying DB supplied views we should query these tables.
If we do not have such information kept earlier, we cannot have comparison reports beyond snapshots available in the database.
The package DBMS_SPACE enables us to analyse segment growth and space requirements in Oracle with the help of its numerous method. We can refer “Oracle standard Documentation” for exploring this package in details. This package helps DBAs to perform capacity planning activity which will be explained in my another blog.
We consider this PL/SQL package here because this package provides a function “OBJECT_GROWTH_TREND” use of which we can extrapolate the growth of a particular table/indexes.
Let’s see these in terms of queries.
Tablespace Wise Growth on Daily basis: Daily growth report of a tablespace.
SELECT TO_DATE(TO_CHAR (snpshot.begin_interval_time,’DD-MM-YYYY’),’DD-MM-YYYY’) daywise
, dhts.tsname tablespacename
, max(round((dhtsu.tablespace_size* dtblspc.block_size )/(1024*1024*1024),2) ) maximum_allocsize_GB
, max(round((dhtsu.tablespace_usedsize* dtblspc.block_size )/(1024*1024*1024),2)) maximum_usedsize_GB
FROM DBA_HIST_TBSPC_SPACE_USAGE dhtsu
, DBA_HIST_TABLESPACE_STAT dhts
, DBA_HIST_SNAPSHOT snpshot
, DBA_TABLESPACES dtblspc
WHERE dhtsu.tablespace_id= dhts.ts#
AND dhtsu.snap_id = snpshot.snap_id
AND dhts.tsname = dtblspc.tablespace_name
AND dhts.tsname NOT IN (‘SYSAUX’,’SYSTEM’)
GROUP BY TO_DATE(TO_CHAR (snpshot.begin_interval_time,’DD-MM-YYYY’),’DD-MM-YYYY’)
, dhts.tsname
ORDER BY dhts.tsname
, daywise;
And the output would be:
DAYWISE | TABLESPACENAME | MAXIMUM_ALLOCSIZE_GB | MAXIMUM_USEDSIZE_GB |
---|---|---|---|
9-Jul-17 | TEST_DATA | 158 | 150.01 |
10-Jul-17 | TEST_DATA | 158 | 149.19 |
11-Jul-17 | TEST_DATA | 158 | 152.44 |
12-Jul-17 | TEST_DATA | 159 | 153.39 |
13-Jul-17 | TEST_DATA | 181 | 171.9 |
14-Jul-17 | TEST_DATA | 192 | 182.19 |
15-Jul-17 | TEST_DATA | 192 | 178.23 |
16-Jul-17 | TEST_DATA | 192 | 177.9 |
17-Jul-17 | TEST_DATA | 192 | 183.29 |
18-Jul-17 | TEST_DATA | 222 | 214.76 |
19-Jul-17 | TEST_DATA | 249 | 242.71 |
20-Jul-17 | TEST_DATA | 264 | 254.59 |
21-Jul-17 | TEST_DATA | 279 | 261.88 |
22-Jul-17 | TEST_DATA | 279 | 264.31 |
23-Jul-17 | TEST_DATA | 279 | 269.89 |
24-Jul-17 | TEST_DATA | 279 | 271.94 |
25-Jul-17 | TEST_DATA | 279 | 273.97 |
26-Jul-17 | TEST_DATA | 298 | 278.62 |
27-Jul-17 | TEST_DATA | 298 | 286.75 |
28-Jul-17 | TEST_DATA | 313 | 297.25 |
29-Jul-17 | TEST_DATA | 313 | 300.01 |
30-Jul-17 | TEST_DATA | 313 | 300.96 |
31-Jul-17 | TEST_DATA | 316 | 301.97 |
1-Aug-17 | TEST_DATA | 316 | 304.58 |
2-Aug-17 | TEST_DATA | 316 | 310.16 |
3-Aug-17 | TEST_DATA | 333 | 320.15 |
4-Aug-17 | TEST_DATA | 333 | 332.39 |
5-Aug-17 | TEST_DATA | 333 | 275.86 |
6-Aug-17 | TEST_DATA | 333 | 284.69 |
7-Aug-17 | TEST_DATA | 333 | 287.04 |
8-Aug-17 | TEST_DATA | 333 | 290.9 |
9-Aug-17 | TEST_DATA | 333 | 293.4 |
10-Aug-17 | TEST_DATA | 333 | 303.53 |
11-Aug-17 | TEST_DATA | 333 | 313.73 |
12-Aug-17 | TEST_DATA | 333 | 310.03 |
13-Aug-17 | TEST_DATA | 333 | 309.44 |
14-Aug-17 | TEST_DATA | 337 | 326.27 |
15-Aug-17 | TEST_DATA | 337 | 326.58 |
16-Aug-17 | TEST_DATA | 337 | 322.59 |
17-Aug-17 | TEST_DATA | 339 | 335.14 |
18-Aug-17 | TEST_DATA | 347 | 342.66 |
19-Aug-17 | TEST_DATA | 347 | 338.71 |
20-Aug-17 | TEST_DATA | 365 | 341.82 |
21-Aug-17 | TEST_DATA | 365 | 344.18 |
22-Aug-17 | TEST_DATA | 365 | 340.89 |
23-Aug-17 | TEST_DATA | 365 | 344.29 |
24-Aug-17 | TEST_DATA | 385 | 363.64 |
25-Aug-17 | TEST_DATA | 385 | 366.42 |
26-Aug-17 | TEST_DATA | 385 | 364.74 |
27-Aug-17 | TEST_DATA | 385 | 373.13 |
28-Aug-17 | TEST_DATA | 386 | 378.41 |
29-Aug-17 | TEST_DATA | 386 | 379.34 |
30-Aug-17 | TEST_DATA | 388 | 383.77 |
31-Aug-17 | TEST_DATA | 410 | 393.69 |
1-Sep-17 | TEST_DATA | 411 | 406.66 |
2-Sep-17 | TEST_DATA | 411 | 399.87 |
3-Sep-17 | TEST_DATA | 411 | 397.68 |
4-Sep-17 | TEST_DATA | 434 | 405.79 |
5-Sep-17 | TEST_DATA | 434 | 403.28 |
6-Sep-17 | TEST_DATA | 434 | 405.77 |
Daily Object’s Growth with respect to Tablespace in last X days:
SELECT * FROM
(SELECT ds.tablespace_name
, ds.segment_name
, TO_DATE(TO_CHAR (snpshot.end_interval_time,’DD-MM-YYYY’),’DD-MM-YYYY’) daywise
, SUM(dhss.space_used_delta) / 1024 / 1024 “Space used (MB)”
, AVG(ds.bytes) / 1024 / 1024 “Total Object Size (MB)”
, ROUND(SUM(dhss.space_used_delta) / SUM(ds.bytes) * 100, 2) “Percent of Total Disk Usage”
FROM dba_hist_snapshot snpshot
, dba_hist_seg_stat dhss
, dba_objects dobj
, dba_segments ds
WHERE begin_interval_time > TRUNC(SYSDATE) – &pastdays
AND snpshot.snap_id = dhss.snap_id
AND dobj.object_id = dhss.obj#
AND dobj.owner = ds.owner
AND dobj.object_name = ds.segment_name
AND ds.segment_name = ‘TEST_TAB1′
GROUP BY ds.tablespace_name,ds.segment_name,TO_DATE(TO_CHAR (snpshot.end_interval_time,’DD-MM-YYYY’),’DD-MM-YYYY’)
ORDER BY ds.tablespace_name,ds.segment_name,TO_DATE(TO_CHAR (snpshot.end_interval_time,’DD-MM-YYYY’),’DD-MM-YYYY’));
And the output would be:
TABLESPACE_NAME | SEGMENT_NAME | DAYWISE | Space used (GB) | Total Object Size (GB) | Percent of Total Disk Usage |
---|---|---|---|---|---|
TEST_DATA | TEST_TAB1 | 8/28/2017 0:00 | 4.82 | 4.83 | 19.97 |
TEST_DATA | TEST_TAB1 | 8/29/2017 0:00 | 4.72 | 4.83 | 13.97 |
TEST_DATA | TEST_TAB1 | 8/30/2017 0:00 | 4.74 | 4.83 | 49.05 |
TEST_DATA | TEST_TAB1 | 8/31/2017 0:00 | 4.74 | 4.83 | 32.71 |
TEST_DATA | TEST_TAB1 | 9/1/2017 0:00 | 4.74 | 4.83 | 16.37 |
TEST_DATA | TEST_TAB1 | 9/2/2017 0:00 | 4.75 | 4.83 | 49.18 |
TEST_DATA | TEST_TAB1 | 9/3/2017 0:00 | 0 | 4.83 | 0 |
TEST_DATA | TEST_TAB1 | 9/4/2017 0:00 | 4.78 | 4.83 | 49.47 |
TEST_DATA | TEST_TAB1 | 9/5/2017 0:00 | 4.75 | 4.83 | 19.65 |
TEST_DATA | TEST_TAB1 | 9/6/2017 0:00 | 4.8 | 4.83 | 33.14 |
TEST_DATA | TEST_TAB1 | 9/7/2017 0:00 | 4.8 | 4.83 | 49.71 |
Object’s Growth in Last X days:: This is accumulated growth till last X days.
SELECT ds.tablespace_name
, ds.segment_name “object name”
, dobj.object_type
, ROUND(SUM(dhss.space_used_delta) / 1024 / 1024 / 1024,2) “Growth (GB)”
FROM dba_hist_snapshot snpshot
, dba_hist_seg_stat dhss
, dba_objects dobj
, dba_segments ds
WHERE begin_interval_time > TRUNC(SYSDATE) – &past_days
AND snpshot.snap_id = dhss.snap_id
AND dobj.object_id = dhss.obj#
AND dobj.owner = ds.owner
AND dobj.object_name = ds.segment_name
AND ds.owner =’TESTOWNER’
GROUP BY ds.tablespace_name,ds.segment_name,dobj.object_type
ORDER BY 3 ASC;
And the output would be:
TABLESPACE_NAME | object name | OBJECT_TYPE | growth (mb) |
---|---|---|---|
TEST_DATA | TEST_TAB1 | TABLE PARTITION | 47.64 |
And the last but not the least, DBMS_SPACE package. Method OBJECT_GROWTH_TREND is the brilliant way to get the growth estimate for a object. We can write query with this method using TABLE function.
select * from table(
DBMS_SPACE.OBJECT_GROWTH_TREND (
object_owner => ‘TESTOWNER’,
object_name => ‘TEST_TAB1’,
object_type => ‘TABLE PARTITION’,
partition_name => ‘T1’ ) );
And the output would be:
TIMEPOINT | SPACE_USAGE | SPACE_ALLOC | QUALITY |
---|---|---|---|
08-08-17 12:56:30.688879000 PM | 5163858429 | 5206179840 | INTERPOLATED |
09-08-17 12:56:30.688879000 PM | 5163858429 | 5206179840 | INTERPOLATED |
10-08-17 12:56:30.688879000 PM | 5163858429 | 5206179840 | INTERPOLATED |
11-08-17 12:56:30.688879000 PM | 5163858429 | 5206179840 | INTERPOLATED |
12-08-17 12:56:30.688879000 PM | 5163858429 | 5206179840 | INTERPOLATED |
13-08-17 12:56:30.688879000 PM | 5163858429 | 5206179840 | INTERPOLATED |
14-08-17 12:56:30.688879000 PM | 5163858429 | 5206179840 | INTERPOLATED |
15-08-17 12:56:30.688879000 PM | 5163858429 | 5206179840 | INTERPOLATED |
16-08-17 12:56:30.688879000 PM | 5163858429 | 5206179840 | INTERPOLATED |
17-08-17 12:56:30.688879000 PM | 5163858429 | 5206179840 | INTERPOLATED |
18-08-17 12:56:30.688879000 PM | 5163858429 | 5206179840 | INTERPOLATED |
19-08-17 12:56:30.688879000 PM | 5163858429 | 5206179840 | INTERPOLATED |
20-08-17 12:56:30.688879000 PM | 5163858429 | 5206179840 | INTERPOLATED |
21-08-17 12:56:30.688879000 PM | 5163858429 | 5206179840 | INTERPOLATED |
22-08-17 12:56:30.688879000 PM | 5163858429 | 5206179840 | INTERPOLATED |
23-08-17 12:56:30.688879000 PM | 5163858429 | 5206179840 | INTERPOLATED |
24-08-17 12:56:30.688879000 PM | 5163858429 | 5206179840 | INTERPOLATED |
25-08-17 12:56:30.688879000 PM | 5163858429 | 5206179840 | INTERPOLATED |
26-08-17 12:56:30.688879000 PM | 5163858429 | 5206179840 | INTERPOLATED |
27-08-17 12:56:30.688879000 PM | 5163858429 | 5206179840 | INTERPOLATED |
28-08-17 12:56:30.688879000 PM | 5163858429 | 5206179840 | INTERPOLATED |
29-08-17 12:56:30.688879000 PM | 5163858429 | 5206179840 | INTERPOLATED |
30-08-17 12:56:30.688879000 PM | 5163858429 | 5206179840 | INTERPOLATED |
31-08-17 12:56:30.688879000 PM | 5163858429 | 5206179840 | INTERPOLATED |
01-09-17 12:56:30.688879000 PM | 5163858429 | 5206179840 | INTERPOLATED |
02-09-17 12:56:30.688879000 PM | 5163858429 | 5206179840 | INTERPOLATED |
03-09-17 12:56:30.688879000 PM | 5163858429 | 5206179840 | INTERPOLATED |
04-09-17 12:56:30.688879000 PM | 5163858429 | 5206179840 | INTERPOLATED |
05-09-17 12:56:30.688879000 PM | 5163858429 | 5206179840 | INTERPOLATED |
06-09-17 12:56:30.688879000 PM | 5163858429 | 5206179840 | INTERPOLATED |
07-09-17 12:56:30.688879000 PM | 5163858429 | 5206179840 | INTERPOLATED |
08-09-17 12:56:30.688879000 PM | 5163858429 | 5206179840 | PROJECTED |
09-09-17 12:56:30.688879000 PM | 5163858429 | 5206179840 | PROJECTED |
10-09-17 12:56:30.688879000 PM | 5163858429 | 5206179840 | PROJECTED |
11-09-17 12:56:30.688879000 PM | 5163858429 | 5206179840 | PROJECTED |
12-09-17 12:56:30.688879000 PM | 5163858429 | 5206179840 | PROJECTED |