SOP For Tablespace Management

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

Global Information Base

Oracle COE
SOP for Table Space Management

Author(s):
Diganta Sinha, Senior Oracle Apps DBA, Tata Consultancy Services Ltd, Port Macquarie, AU.
Sunil Agarwal, Database Analyst, Essential Energy Australia, Sydney.

Approver(s):
James Arnold, Oracle SDM, Melbourne, AU

Date: 2nd Jan 2019

File Revision: 1.0

Document Revision History


Revision Date Author Change Reference Reason for Change
1.0 2nd Jan 2019 Sunil Agarwal All pages Initial release
1.0 2nd Jan 2019 Diganta Sinha All Pages Initial release

Page 1 of 11
TCS Oracle COE Effective Date: 2nd Jan 2019
Global IT Base SOP for Table Space Management Revision: 1.0

Why we need to increase the tablespace size?

Request fails with the following error; there can be several types of errors too.

ORA-1654: unable to extend index INV.MTL_CST_ACTUAL_COST_DETAILS_U1 by 128 in


tablespace APPS_TS_TX_IDX
ORA-1654: unable to extend index ONT.ROI_OE_ORDER_LINES_ALL_N2 by 128 in
tablespace APPS_TS_TX_IDX

It can be different tablespace.

How we will come to know of about the issue in tablespace?

We will see errors in alert log, and concurrent request will start failing.
You will get an alert from OEM or from customized scripts about the possible storage space
requirement on the tablespaces.

The threshold warning level is 80%.


The threshold critical level is 90%.

Steps for increasing the tablespace size.


If you get any of the above threshold level alerts please follow the following instructions to clear
the alerts:

1) Make a note of Tablespace name.


Note: We have taken example for the tablespace “APPS_TS_TX_IDX”.

2) Use following query to determine the tablespace usage report. Try to find as much as
information about the tablespace as you can with below queries.

Below queries can be located at /scripts/unix/monitoring/rac_scripts.

Query1:

SELECT tbs.tablespace_name,
tot.bytes / 1024 total,
tot.bytes / 1024 -SUM(nvl(fre.bytes, 0)) / 1024 used,
SUM(nvl(fre.bytes, 0)) / 1024 free,
(1 -SUM(nvl(fre.bytes, 0)) / tot.bytes) *100 pct,
decode(greatest((1 -SUM(nvl(fre.bytes, 0)) / tot.bytes) *100, 90), 90, '', '*') pct_warn
FROM dba_free_space fre,
(SELECT tablespace_name,
SUM(bytes) bytes
FROM dba_data_files
GROUP BY tablespace_name)
tot,
dba_tablespaces tbs
WHERE tot.tablespace_name = tbs.tablespace_name
AND fre.tablespace_name(+) = tbs.tablespace_name
AND tbs.tablespace_name = '&tablespacename'
GROUP BY tbs.tablespace_name,
tot.bytes / 1024,
tot.bytes
ORDER BY 5, 1;

Filename: SOP for Table Space Management.doc Page 2 of 11


TCS Oracle COE Effective Date: 2nd Jan 2019
Global IT Base SOP for Table Space Management Revision: 1.0

Query2:
set lines 1000;
set pages 1000;
column dummy noprint
column pct_used format 999.9 heading "%|Used"
column name format a21 heading "Tablespace Name"
column Kbytes format 999,999,999,999 heading "KBytes"
column used format 999,999,999,999 heading "Used"
column free format 999,999,999 heading "Free"
column largest format 999,999,999 heading "Largest"
column max_size format 999,999,999 heading "MaxPoss|Kbytes"
column pct_max_used format 999.9 heading "%|Max|Used"
break on report
compute sum of kbytes on report
compute sum of free on report
compute sum of used on report

select (select decode(extent_management,'LOCAL','*',' ') ||


decode(segment_space_management,'AUTO','a ','m ')
from dba_tablespaces where tablespace_name = b.tablespace_name) ||
nvl(b.tablespace_name,
nvl(a.tablespace_name,'UNKOWN')) name,
kbytes_alloc kbytes,
kbytes_alloc-nvl(kbytes_free,0) used,
nvl(kbytes_free,0) free,
((kbytes_alloc-nvl(kbytes_free,0))/
kbytes_alloc)*100 pct_used,
nvl(largest,0) largest,
nvl(kbytes_max,kbytes_alloc) Max_Size,
decode( kbytes_max, 0, 0, (kbytes_alloc/kbytes_max)*100) pct_max_used
from ( select sum(bytes)/1024 Kbytes_free,
max(bytes)/1024 largest,
tablespace_name
from sys.dba_free_space
group by tablespace_name ) a,
( select sum(bytes)/1024 Kbytes_alloc,
sum(maxbytes)/1024 Kbytes_max,
tablespace_name
from sys.dba_data_files
group by tablespace_name
union all
select sum(bytes)/1024 Kbytes_alloc,
sum(maxbytes)/1024 Kbytes_max,
tablespace_name
from sys.dba_temp_files
group by tablespace_name )b
where a.tablespace_name (+) = b.tablespace_name
order by &1
/

Query3:
SELECT max(bytes) FROM dba_free_space WHERE tablespace_name = '<tablespace name>';

The above query returns the largest available contiguous chunk of space.

If this query is done immediately after the failure, it will show that the largest contiguous space in
the tablespace is smaller than the next extent the object was trying to allocate.

Filename: SOP for Table Space Management.doc Page 3 of 11


TCS Oracle COE Effective Date: 2nd Jan 2019
Global IT Base SOP for Table Space Management Revision: 1.0

Query4:

Following Sql statement will generate tablespace usage report taking autoextend into
consideration:

set linesize 250


set pagesize 70
col tablespace_name format a20
select a.tablespace_name, SUM(a.bytes)/1024/1024 "CurMb",
SUM(decode(b.maxextend, null, A.BYTES/1024/1024, b.maxextend*8192/1024/1024)) "MaxMb",
(SUM(a.bytes)/1024/1024 - round(c."Free"/1024/1024)) "TotalUsed",
(SUM(decode(b.maxextend, null, A.BYTES/1024/1024, b.maxextend*8192/1024/1024)) - (SUM(a.bytes)/1024/1024 -
round(c."Free"/1024/1024))) "TotalFree",
round(100*(SUM(a.bytes)/1024/1024 - round(c."Free"/1024/1024))/(SUM(decode(b.maxextend, null,
A.BYTES/1024/1024, b.maxextend*8192/1024/1024)))) "UPercent"
from dba_data_files a,
sys.filext$ b,
(SELECT c.tablespace_name , sum(c.bytes) "Free" FROM DBA_FREE_SPACE c GROUP BY TABLESPACE_NAME) c
where a.file_id = b.file#(+)
and a.tablespace_name = c.tablespace_name
GROUP by a.tablespace_name, c."Free"/1024
/

Filename: SOP for Table Space Management.doc Page 4 of 11


TCS Oracle COE Effective Date: 2nd Jan 2019
Global IT Base SOP for Table Space Management Revision: 1.0

Eg:

Use Query2:

One more point to remember, TRAX_SMALL_DATA is showing ZERO in above picture. Normally
we think, we need to add datafile but the assumption is wrong. Recommend to do proper
investigation.

How to investigate further, there is still space is available around 33238007808 (MAXBYTES
34359721984 – BYTES 1121714176).
In this case, don’t add any new datafile.

Filename: SOP for Table Space Management.doc Page 5 of 11


TCS Oracle COE Effective Date: 2nd Jan 2019
Global IT Base SOP for Table Space Management Revision: 1.0

select file_name,bytes/1024/1024,maxbytes/1024/1024,autoextensible,status from dba_data_files


where tablespace_name='TS_APPSBKP_DATA';

3) Getting the list of dbf’s for the tablespace in question:

select ts.name||'|'||df.name||'|'||bytes/1024/1024||'|'||CREATE_BYTES/1024/1024
from v$tablespace ts, v$datafile df
where ts.ts#=df.ts#
and ts.name = 'APPS_TS_TX_IDX';

Now you have the list of existing datafiles, the new datafile name should follow the sequence
number in order and should use the next data mount point in the sequence.
Note: Data mount points should be used in a circular fashion.
For e.g if the output of above query is as below:

APPS_TS_TX_IDX|/prod/oradata/data01/prod/APPS_TS_TX_IDX01.dbf|2750|0
APPS_TS_TX_IDX|/prod/oradata/data02/prod/APPS_TS_TX_IDX02.dbf|4096|0
APPS_TS_TX_IDX|/prod/oradata/data03/prod/APPS_TS_TX_IDX03.dbf|3300|0
APPS_TS_TX_IDX|/prod/oradata/data04/prod/APPS_TS_TX_IDX04.dbf|4096|0
APPS_TS_TX_IDX|/prod/oradata/data05/prod/APPS_TS_TX_IDX05.dbf|3950|0
APPS_TS_TX_IDX|/prod/oradata/data01/prod/APPS_TS_TX_IDX06.dbf|4096|0
APPS_TS_TX_IDX|/prod/oradata/data02/prod/APPS_TS_TX_IDX07.dbf|3900|0
APPS_TS_TX_IDX|/prod/oradata/data03/prod/APPS_TS_TX_IDX08.dbf|4000|0
APPS_TS_TX_IDX|/prod/oradata/data04/prod/APPS_TS_TX_IDX09.dbf|3750|0
APPS_TS_TX_IDX|/prod/oradata/data05/prod/APPS_TS_TX_IDX10.dbf|3800|0
APPS_TS_TX_IDX|/prod/oradata/data01/prod/APPS_TS_TX_IDX11.dbf|4096|0
APPS_TS_TX_IDX|/prod/oradata/data02/prod/APPS_TS_TX_IDX12.dbf|3500|0
APPS_TS_TX_IDX|/prod/oradata/data03/prod/APPS_TS_TX_IDX13.dbf|2850|0
APPS_TS_TX_IDX|/prod/oradata/data04/prod/APPS_TS_TX_IDX14.dbf|3650|0
APPS_TS_TX_IDX|/prod/oradata/data05/prod/APPS_TS_TX_IDX15.dbf|2900|0
APPS_TS_TX_IDX|/prod/oradata/data01/prod/APPS_TS_TX_IDX16.dbf|3450|0

In above case the new datafile should be named as follows:


/prod/oradata/data02/prod/APPS_TS_TX_IDX17.dbf
Note: Since last datafile in the order is /prod/oradata/data01/prod/APPS_TS_TX_IDX16.dbf and
was created on data01 mount point so the next file name will be APPS_TS_TX_IDX17.dbf and
should be created on the next mount i.e. data02.

Important: Also we have 2 more mount points “system01” and “custom01”. The system01 mount
is used for system tablespaces and custom01 mount is used for other custom application
tablespaces. For tablespaces on these mount points we just need to increase the sequence
number and not the data mount. The dbf should be added on the mount where the other dbf’s are
present.

Filename: SOP for Table Space Management.doc Page 6 of 11


TCS Oracle COE Effective Date: 2nd Jan 2019
Global IT Base SOP for Table Space Management Revision: 1.0

4) Checks to be performed before adding the datafile:

Confirm that file does not already exist and you have enough space in the mount point.

Run following commands from UNIX prompt:

a) ls -l /prod/oradata/data02/prod/APPS_TS_TX_IDX17.dbf
--This should not list the data file.

b) df -k | grep /prod/oradata/data02
--The mount point should not be more then 90% used after creating a datafile, do the estimations
accordingly. If the mount point usage goes above 85% please inform the lead about the same.

C) Ensure that all the previous dbf’s are of size 4096 M. If you have a dbf of size less than 4096
MB jump to Step 5 - Scenario 1.

5) Adding a new datafile:

Scenario 1)
Check if an existing datafile can be extended by the amount required (if the datafile is not already
at 4GB). If datafile can be extended then use below command and skip Scenario 2:

Step I) If autoextend is on then do only following:

A) For datafiles over 1000MB and < 4096M big Data & Indx Tablespaces Ex: INV, MRP, BOM,
FND, JTF, PO, GL, OKC, WSH, OSM, AR, ONT, ASO, OKSX, OKSD, use following:
alter database datafile '<file_name>' autoextend on next 50M maxsize 4096M;

B) For datafiles > 100M and <= 1000M, use following:


alter database datafile '<file_name>' autoextend on next 25M maxsize 4096M;

C) For datafiles < 100M, use following:


alter database datafile '<file_name>' autoextend on next 10M maxsize 4096M;

Step II) If autoextend is off then do only following:


alter database datafile '<file>' resize <size>;

Scenario 2)
Add new database file to tablespace shown in alert using command as given below:

A) For datafiles over 1000MB and < 4096M big Data & Indx Tablespaces Ex: INV, MRP, BOM,
FND, JTF, PO, GL, OKC, WSH, OSM, AR, ONT, ASO, OKSX, OKSD etc, use following:
alter tablespace <tablespace_name> add datafile '<file_name>' size 50M autoextend on next
50M maxsize 4096M;

B) For datafiles > 100M and <= 1000M, use following:


alter tablespace <tablespace_name> add datafile '<file_name>' size 25M autoextend on next
25M maxsize 4096M;

C) For datafiles < 100M, use following:


alter tablespace <tablespace_name> add datafile '<file_name>' size 10M autoextend on next
10M maxsize 4096M;

Filename: SOP for Table Space Management.doc Page 7 of 11


TCS Oracle COE Effective Date: 2nd Jan 2019
Global IT Base SOP for Table Space Management Revision: 1.0

The size of the datafile should be 4096MB, if more than 4096MB storage is required on the
tablespace then add another file of 4096MB at the same time or in the future as per the
requirement.

If tablespace is a small tablespace and growth of the tablespace is not much, then you can
add the datafile of size 2048m instead of 4096m.

Issue faced:

1 → Error in the alert log:

ORA-1654: unable to extend index INV.MTL_CST_ACTUAL_COST_DETAILS_U1 by 128 in tablespace


APPS_TS_TX_IDX
ORA-1654: unable to extend index ONT.ROI_OE_ORDER_LINES_ALL_N2 by 128 in tablespace APPS_TS_TX_IDX

An "unable to extend" error is raised when there is insufficient contiguous space available to extend a segment.

Steps to resolve this type of issues

1. Determine the largest contiguous space available for the tablespace with the error
SELECT max(bytes) FROM dba_free_space WHERE tablespace_name = '<tablespace
name>';
The above query returns the largest available contiguous chunk of space.

If this query is done immediately after the failure, it will show that the largest contiguous space in
the tablespace is smaller than the next extent the object was trying to allocate.

2. Determine NEXT_EXTENT size

SELECT NEXT_EXTENT, PCT_INCREASE FROM DBA_SEGMENTS WHERE


SEGMENT_NAME = <segment name> AND SEGMENT_TYPE = <segment type> AND
OWNER = <owner>

<segment type> is usually stated in the error message

3. Compute the NEXT EXTENT SIZE if the segment resides in a dictionary managed tablespace
and has a PCT_INCREASE >0

SELECT EXTENT_MANAGEMENT FROM DBA_TABLESPACES WHERE


TABLESPACE_NAME = '<tablespace name>';

Use the "next_extent" size with "pct_increase" (from #2 above) in the following formula to
determine the size of extent that is trying to be allocated.

extent size = next_extent * (1 + (pct_increase/100)

EXAMPLE

next_extent = 512000
pct_increase = 50

next extent size = 512000 * (1 + (50/100)) = 512000 * 1.5 = 768000

Filename: SOP for Table Space Management.doc Page 8 of 11


TCS Oracle COE Effective Date: 2nd Jan 2019
Global IT Base SOP for Table Space Management Revision: 1.0

4) Determine if the tablespace containing the object is AUTOEXTENSIBLE and has reached
MAXSIZ

SELECT file_name, bytes, autoextensible, maxbytes FROM dba_data_files WHERE


tablespace_name='<tablespace name> ';

Possible Solutions

A. Manually Coalesce Adjacent Free Extents


ALTER TABLESPACE <tablespace name> COALESCE;
The extents must be adjacent to each other for this to work.

B. Modify one or more datafiles in the tablespace to use AUTOEXTEND


ALTER DATABASE DATAFILE '<full path and name>' AUTOEXTEND ON MAXSIZE
<integer> <k | m | g | t | p | e>;
NOTE: It is strongly recommended that MAXSIZE be specified to try to prevent the
datafile from consuming all available space on the volume

C. Add a Datafile
ALTER TABLESPACE <tablespace name> ADD DATAFILE '<full path and file name>'
SIZE <integer> <k | m | g | t | p | e>;

D. Lower "next_extent" and/or "pct_increase" size if segment is in a Dictionary Managed


Tablespace
ALTER <SEGMENT TYPE> <segment_name> STORAGE ( next <integer> <k | m | g | t |
p | e> pctincrease <integer>);

E. Resize the Datafile


ALTER DATABASE DATAFILE '<full path and file name>' RESIZE <integer> <k | m | g | t
| p | e>;

F. Defragment the Tablespace


If you would like more information on fragmentation, the following documents are
available from Oracle WorldWide Support . Note that this is not a comprehensive list.

For ORA-1654 errors, we can proactively monitor the issue before hand by using
the following script.
The following statement is executed in lab1. We can try to automate this using cron.

select owner,segment_name, segment_type, tablespace_name, extents, next_extent


,to_char(next_extent,'999,999,999,999')||' will be requested but only '||
to_char(dfs_bytes,'999,999,999,999')||
' is available.'||chr(10)||'Recommended Action : '||chr(10)||'alter '||segment_type||' '
||owner||'.'||segment_name||
' storage ( next '|| to_char(dfs_bytes,'999999999999')||' );' warning_text
from dba_segments
,( select tablespace_name dfs_ts_name , max(bytes) dfs_bytes
from dba_free_space
group by tablespace_name )
where tablespace_name = dfs_ts_name

Filename: SOP for Table Space Management.doc Page 9 of 11


TCS Oracle COE Effective Date: 2nd Jan 2019
Global IT Base SOP for Table Space Management Revision: 1.0

and next_extent > dfs_bytes


and owner not in ('SYS','SYSTEM')

Eg:

SQL>
1 select owner,segment_name, segment_type, tablespace_name, extents, next_extent
2 ,to_char(next_extent,'999,999,999,999')||' will be requested but only '||
3 to_char(dfs_bytes,'999,999,999,999')||
4 ' is available.'||chr(10)||'Recommended Action : '||chr(10)||'alter '||segment_type||' '
5 ||owner||'.'||segment_name||
6 ' storage ( next '|| to_char(dfs_bytes,'999999999999')||' );' warning_text
7 from dba_segments
8 ,( select tablespace_name dfs_ts_name , max(bytes) dfs_bytes
9 from dba_free_space
10 group by tablespace_name )
11 where tablespace_name = dfs_ts_name
12 and next_extent > dfs_bytes
13* and owner not in ('SYS','SYSTEM')
SQL> /

OWNER SEGMENT_NAME SEGMENT_TY TABLESPACE_NAME EXTENTS NEXT_EXTENT


WARNING_TEXT
--------------- ------------------------- ---------- --------------- ------- ---------------- --------------------------
----------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
----
XXLAAPPS LAAF_PROCESSES_I2 INDEX XXLAI 1 1,048,576 1,048,576
will be requested but only 131,072 is available.
Recommended Action :
alter INDEX
XXLAAPPS.LAAF_PROCESSES_I2 storage ( next 131072 );

SQL> alter INDEX XXLAAPPS.LAAF_PROCESSES_I2 storage (next 131072);

Index altered.

SQL> select owner,segment_name, segment_type, tablespace_name, extents, next_extent


2 ,to_char(next_extent,'999,999,999,999')||' will be requested but only '||
to_char(dfs_bytes,'999,999,999,999')||
3 4 ' is available.'||chr(10)||'Recommended Action : '||chr(10)||'alter '||segment_type||' '
5 ||owner||'.'||segment_name||
6 ' storage ( next '|| to_char(dfs_bytes,'999999999999')||' );' warning_text
7 from dba_segments
8 ,( select tablespace_name dfs_ts_name , max(bytes) dfs_bytes
9 from dba_free_space
10 group by tablespace_name )
11 where tablespace_name = dfs_ts_name
12 and next_extent > dfs_bytes
13 and owner not in ('SYS','SYSTEM');

no rows selected

Filename: SOP for Table Space Management.doc Page 10 of 11


TCS Oracle COE Effective Date: 2nd Jan 2019
Global IT Base SOP for Table Space Management Revision: 1.0

To check who ios eating up Temp TBS resource:

select
srt.tablespace,
srt.segfile#,
srt.segblk#,
srt.blocks,
a.sid,
a.serial#,
a.username,
a.osuser,
a.status
from
v$session a,
v$sort_usage srt
where
a.saddr = srt.session_addr
order by
srt.tablespace, srt.segfile#, srt.segblk#,
srt.blocks;

Filename: SOP for Table Space Management.doc Page 11 of 11

You might also like