To shrink a datafile
Hi All,
Database Version :11gR2
I have a tablespace which has around 32gb space consumed. But if i check the used space then its only 16GB. When i tried to resize the datafile it throws the error
ORA-03297: file contains used data beyond requested RESIZE valueAs per my understanding there are not continous blocks which are there in datafile due to fragmentation may be and there by not able to resize it. If i export the tablespace using datapump and reimport this will release the space.
But i want to know if there are any alternative ways to do the same.
Thank You
Arun
Arun,
I dont think we can resolve fragmentation using RMAN.
Use can try,
1) export/import
2) Move object from fragmented tablespace to new tablespace and then back to it (You can create a script to do that)
3) Find HWM of the tablespace and resize as per that.
How to Resolve ORA-03297 When Resizing a Datafile by Finding the Table Highwatermark [ID 130866.1]
Mark your Post as Answered or Helpful if Your question is answered.
Thanks & Regards,
SID
(StepIntoOracleDBA)
Email : [email protected]
http://stepintooracledba.blogspot.in/
http://www.stepintooracledba.com/
Similar Messages
-
ORA-01237 when trying to shrink a datafile
I have a datafile which is on a disk which run full.
The datafile was thought to autoextend to 2 GB, but due to other use the disk is now full with the datafile using 850 MB.
select file_name, bytes, maxbytes from dba_data_files
where file_name = '/dtb1/CELV4/dtb1/tma001.dbf'
FILE_NAME,BYTES,MAXBYTES
/dtb1/CELV4/dtb1/tma001.dbf,850395136,2147483648
I have now added another datafile on another disk.
To make sure that the old datafile does not extend any further, I tried to shrink the datafile:
alter database datafile '/dtb1/CELV4/dtb1/tma001.dbf' resize 1g;
ORA-01237: cannot extend datafile 8
ORA-01110: data file 8: '/dtb1/CELV4/dtb1/tma001.dbf'
ORA-27072: File I/O error
Additional information: 2
As far as I have understood the documentation, shrinking a datafile should be possible. So where does this error come from? Does Oracle first need additional space for shrinking, so the nearly full disc could be the problem?
Many thanks,
ThomasThe datafile size is 850395136 bytes -- i.e. about 811MB (dividing by 1048576)
The "alter database datafile ... resize 1g" command that you issued attempted to increase the size of the file.
If you want to prevent the datafile from attempting to autoextend you should set autoextend off with
alter database datafile '/dtb1/CELV4/dtb1/tma001.dbf' maxsize 820M;
alter database datafile '/dtb1/CELV4/dtb1/tma001.dbf' autoextend off;The first command to change the maxsize is optional. IF autoextend is set to OFF, Oracle will ignore the MAXSIZE. However, it is safer to reduce this as well, in case a DBA or a script resets the datafile back to AUTOEXTEND ON in the future.
(Note : If MAXSIZE is set to less than the current size, Oracle will silently allow you to do so, and autoextend would fail to extend the datafile, but that is not a "clean" way to set the maxsize). -
Is it possible to shrink a datafile if i have extents near the end? Anyway to move the extents? I get the high watermark exception when I try to shrink the datafile even though I have alot of free space.
Hi,
Try this query from http://asktom.oracle.com/pls/asktom/f?p=100:11:4177261019303253::::P11_QUESTION_ID:153612348067
----------- maxshrink.sql ----------------------------------
set verify off
column file_name format a50 word_wrapped
column smallest format 999,990 heading "Smallest|Size|Poss."
column currsize format 999,990 heading "Current|Size"
column savings format 999,990 heading "Poss.|Savings"
break on report
compute sum of savings on report
column value new_val blksize
select value from v$parameter where name = 'db_block_size'
select file_name,
ceil( (nvl(hwm,1)*&&blksize)/1024/1024 ) smallest,
ceil( blocks*&&blksize/1024/1024) currsize,
ceil( blocks*&&blksize/1024/1024) -
ceil( (nvl(hwm,1)*&&blksize)/1024/1024 ) savings
from dba_data_files a,
( select file_id, max(block_id+blocks-1) hwm
from dba_extents
group by file_id ) b
where a.file_id = b.file_id(+)
column cmd format a75 word_wrapped
select 'alter database datafile '''||file_name||''' resize ' ||
ceil( (nvl(hwm,1)*&&blksize)/1024/1024 ) || 'm;' cmd
from dba_data_files a,
( select file_id, max(block_id+blocks-1) hwm
from dba_extents
group by file_id ) b
where a.file_id = b.file_id(+)
and ceil( blocks*&&blksize/1024/1024) -
ceil( (nvl(hwm,1)*&&blksize)/1024/1024 ) > 0
/Regards,
SK -
Hi Gurus!
I got a DB around 12Tb used and the Company is planing to reduce 30% of this space, deleting some periods.
After to reduce the space used in database, I´ll need to release as much as I can in all tablespaces, because I´ll need to move the datafiles to another storage and release the current one.
I got a doubt if can I shrink the datafiles and after that, to try to resize all of them.
Unfotunatelly, I don´t have enough space to create other tablespaces toward to do a reorg.
Is it a good idea to try to shrink the concerned datafiles and after, to resize it?
Thanks in advance.
Regards,
LeonardoHi Gurus!
I got a DB around 12Tb used and the Company is planing to reduce 30% of this space, deleting some periods.
After to reduce the space used in database, I´ll need to release as much as I can in all tablespaces, because I´ll need to move the datafiles to another storage and release the current one.
I got a doubt if can I shrink the datafiles and after that, to try to resize all of them.
Unfotunatelly, I don´t have enough space to create other tablespaces toward to do a reorg.
Is it a good idea to try to shrink the concerned datafiles and after, to resize it?
Thanks in advance.
Regards,
Leonardo -
Shrink Datafiles for database in Avalability Group
We're running SharePoint 2010 on SQL Server 2012. We are also using Availability Groups for all databases (Primary and Secondary replica). I'm running low on space and would like to shrink the datafiles for one of the content
databases. The content database has 2 datafiles spread across 2 LUNS. The SharePoint content database had a run away situation that caused the database to grow very large. The situation has been corrected and the database now has about 98%
free space. The database will not grow much larger than it is now. I know shrinking datafiles is generally not a good idea, but in the case I think it's appropriate.
My question is, has anyone done this before on a database/datafiles that are in a High Availability Group? Are there any risks? Any recommendations?
Thanks!Hi,
SharePoint content database is different than the ordinary database . You need to test the effect in the test environment before making the changes to the product environment.
There is a good article regarding Database Maintenance for SharePoint
http://technet.microsoft.com/en-us/library/cc262731(v=office.14).aspx#DBMaintenanceForSPS2010_ShrinkingDataFiles
Only perform shrink operations rarely, and only after you perform an operation that removes a lot of data from a database, and then only when you do not expect to use that free space again.
Because shrinking causes index fragmentation, do not shrink database files regularly. Instead, shrink database files only in response to large quantities of unused space that appear as a result of operations that significantly impact the
relative amount of used space in a database. If at all possible, avoid shrinking a database.
However, if you must shrink a database, use the following guidelines:
•Do not auto-shrink databases or configure a maintenance plan that programmatically shrinks your databases.
•Shrink a database only when users or administrators remove 50% or more of the content and you do not expect to reuse the unused space.
•Shrink only content databases. Users and administrators do not delete enough data from the configuration database, Central Administration content database, and various service application
databases to contain significant free space.
•Shrinking databases is an extremely resource-intensive operation. Therefore, if you absolutely must shrink a database, carefully consider when you schedule the shrink operation.
•After you shrink a database, the indexes in that database are fragmented. Use ALTER INDEX… REORGANIZE to address the fragmentation. If you are not configured to allow instant file initialization,
shrink the database to a target size that accommodates the size required for the near-term growth that you expect. For more information, see
Database File Initialization.
Thanks.
Tracy Cai
TechNet Community Support -
Finding out objects good candidates for reorganization ( datafile shrink)
Hi Gurus,
I need to find out what can objects are good candidates for reorganization to allow shrinking some datafiles. one of the challenges i have is to try and figure out how i can release some space from the tablespace in one of our environment .Please let me know if you have any scripts for this.Either on a tablespace by tablespace basis or as a general statement which of the following statements are more true than the other statements.
1) More data is being INSERTED into the DB than being DELETED. In other words total disk space consumption is increasing?
2) About the same amount of data in being INSERTED as being DELETED. In other words the amount of disk space consumed is at equilibrium.
3) More data is being DELETED than being INSERTED. In other words less data is being held in the DB as time progresses.
Which statement best reflects your database environment? -
Oracle 11.1.0.7:
I need to give some space back to the storage. I am trying to figure out what process should I follow to shrink the datafiles and drop the datafiles.
1. Should I first do shrink space on tablespace and then drop few datafiles?
2. How do I know how much space can be shrunk?
3. How do I know if after shrinking which datafiles are ready for drop?
Is there any other better way?I"ve just gone through a very similar procedure.
First i had to identify the high water mark in each datafile, and then shrink it back to that or just above that value.
NOTE: It's best to do this when your DB is not in use, specifically growing or if it is some of the commands might fail saying that there is data beyond that size.
Now most likely your data is spread across the datafiles in some sort of "optimal" way by oracle, so it's unlikely that you'll be able to get any "clean" datafiles that you can just drop.
So what i did was to create a new tablespace big enough to hold the objects, MOVED the tables and REBUILT the indexes in the new TS.
Now one option here is to just keep the new TS's and drop the old ones, if needed you can even rename your tablespace (10g and above)
ALTER TABLESPACE old_ts RENAME TO new_ts;
However, you must follow the rules when renaming a tablespace (also need to separetly rename the df if you want to keep your naming standard) :
You cannot rename the SYSTEM or SYSAUX tablespaces.
You cannot rename an offline tablespace.
You cannot rename a tablespace that contains offline datafiles.
Here we wanted to keep the file names locations so i ended up copying everything back into the originals, but before i did that , i could querried dba_segments to get the minimum size required, and I then I shrunk and dropped the datafiles in the original TS as appropriate.
To get the hight water mark, i used this script :
SELECT 'ALTER DATABASE DATAFILE ''' || FILE_NAME || ''' RESIZE ' || HWMM || ';' CL_DYN_SQL
FROM (
SELECT DF.FILE# FILE_ID, DF.NAME FILE_NAME, NVL(DFD.MAX_BLOCK_COUNT,1)*DF.BLOCK_SIZE HWM,
DECODE(SIGN((1024)-(CEIL(NVL(DFD.MAX_BLOCK_COUNT,1)*DF.BLOCK_SIZE/(1024*1024)))),
1,1024, CEIL(NVL(DFD.MAX_BLOCK_COUNT,1)*DF.BLOCK_SIZE/(1024*1024))) || 'M' HWMM,
DF.BYTES
FROM V$DATAFILE DF, V$TABLESPACE TS,
SELECT FILE_ID, MAX(BLOCK_ID+BLOCKS-1) MAX_BLOCK_COUNT
FROM DBA_EXTENTS DE
WHERE DE.TABLESPACE_NAME IN ('TS_D', 'TS_I')
GROUP BY FILE_ID
) DFD
WHERE DF.FILE# = DFD.FILE_ID (+)
AND DF.TS# = TS.TS#
AND TS.NAME IN ('TS_D', 'TS_I')
WHERE HWM < BYTES
ORDER BY 1; -
Try to shrink datafiles after deleting huge amount of records
Dear Sir;
I have deleted more than 50 million records along with table’s partitions for the previous year.
now I'm trying to shrink datafile with more than 10GB free space but still unable to delete due to
ORA-03297: file contains used data beyond requested RESIZE value.
How can we shrink these datafile or otherwise what is the best way to delete huge amount of records and get additional space in HD
Thanks and best regards
Ali LabadiHi,
You could see this article of Jonathan LEWIS:
http://jonathanlewis.wordpress.com/2010/02/06/shrink-tablespace -
How can I reduce size of the SYSTEM datafile?
Hi All,
I recently installed Oracle 9i Enterprise addition on Windows XP Pro. Everything went smoothly. However, I foolishly created a database with large space requirements in the default tablespace (SYSTEM) and this caused the datafile for the SYSTEM tables space to grow to 8 Gig. I dropped the tables and tried to shrink the datafile with the 'alter database datafile resize' command but the command failed indicating that the tablespace had data byond the reize amount. However, this is claerly not true since the OEM indicates that the tablespace is only 4% utilized.
How can I reset the high water mark for the SYSTEM tablespace so that I can resize the datafile?Hi All,
I recently installed Oracle 9i Enterprise addition on Windows XP Pro. Everything went smoothly. However, I foolishly created a database with large space requirements in the default tablespace (SYSTEM) and this caused the datafile for the SYSTEM tables space to grow to 8 Gig. I dropped the tables and tried to shrink the datafile with the 'alter database datafile resize' command but the command failed indicating that the tablespace had data byond the reize amount. However, this is claerly not true since the OEM indicates that the tablespace is only 4% utilized.
How can I reset the high water mark for the SYSTEM tablespace so that I can resize the datafile? at one time (perhaps during the install) the extents may have been used and although you see only 4% used those extents have been allocated nonetheless.
you'll have to rebuild the db if you can't resize the system ts
to reset the high water mark you would have to truncate the system tables, don't think you want to do that
steve -
Use expdp/impdp to reorganize a tablespace to remove additional datafile ?
Oracle 10g (10.2.0.1)
We had a tablespace with a single datafile WORK1, WORK1 filled up, colleague added two datafiles WORK2 and WORK3 (instead of resizing original larger).
I resized WORK1, increasing by 500Mb.
I was able to drop WORK3, but not WORK2 (ORA-03262: the file is non-empty)
My proposed solution is to expdp the tablespace, drop the tablespace and datafiles, recreate the tablespace with a correctly sized datafile and finally impdp the tablespace.
Is this solution valid ?
Any hints at syntax would be useful1. Map your datafile.
2. If no segments in datafile, drop it and go to 5.
2. Shrink the datafile up to where the data ends.
3. Rebuild/move the last object in the data file,
4. Go to 1
5. Fin
To map data file...
accept file_num char prompt 'File ID: ';
SET PAGESIZE 70
SET LINESIZE 132
SET NEWPAGE 0
SET VERIFY OFF
SET ECHO OFF
SET HEADING ON
SET FEEDBACK OFF
SET TERMOUT ON
COLUMN file_name FORMAT a50 HEADING 'File Name'
COLUMN owner FORMAT a10 TRUNC HEADING 'Owner'
COLUMN object FORMAT a30 TRUNC HEADING 'Object'
COLUMN obj_type FORMAT a2 HEADING ' '
COLUMN block_id FORMAT 9999999 HEADING 'Block|ID'
COLUMN blocks FORMAT 999,999 HEADING 'Blocks'
COLUMN mbytes FORMAT 9,999.99 HEADING 'M-Bytes'
SELECT 'free space' owner,
' ' object,
' ' obj_type,
f.file_name,
s.block_id,
s.blocks,
s.bytes/1048576 mbytes
FROM dba_free_space s,
dba_data_files f
WHERE s.file_id = TO_NUMBER(&file_num)
AND s.file_id = f.file_id
UNION
SELECT owner,
segment_name,
DECODE(segment_type, 'TABLE', 'T',
'INDEX', 'I',
'ROLLBACK', 'RB',
'CACHE', 'CH',
'CLUSTER', 'CL',
'LOBINDEX', 'LI',
'LOBSEGMENT', 'LS',
'TEMPORARY', 'TY',
'NESTED TABLE', 'NT',
'TYPE2 UNDO', 'U2',
'TABLE PARTITION','TP',
'INDEX PARTITION','IP', '?'),
f.file_name,
s.file_id,
s.block_id,
s.blocks,
s.bytes/1048576
FROM dba_extents s,
dba_data_files f
WHERE s.file_id = TO_NUMBER(&file_num)
AND s.file_id = f.file_id
ORDER
BY file_id,
block_id -
How to shrink database for the Oracle
Hi,
As you know, in the Sql server database there is a "shrink database" for the shrink the database space, but how to do that for the Oracle9i?
Any comments would be appreciated.
Thanks a lotYou will have to resize ur datafiles to shrink ur db. Here are the steps
1) select file_name,file_id,bytes from dba_data_files;
This will give u the current size of datafiles.
2) select file_id,sum(bytes) from dba_free_space group by file_id;
This will give u the free space in the datafiles. If the file_id is not listed in this query that means the file is fully occupied/used.
(used space = bytes col from query 1 - sum(bytes) col from query 2)
3) alter database datafile file_id resize ### ;
Enter the value you wanna resize based upon ur req. You cannot shrink the datafiles below the used space.
Regards,
http://askyogesh.com -
Dear all,
We have allocated lots of datafiles to a tablespace when it was required, now there are good amount of free space available on this tablesapace and we want to re-gain the allocated spaces from this tablspace as we need to allocate these spaces to other tablespaces.
I wanted to know how to drop the datafile from this tablespace as I dont know which datafile is empty. How can we know which datafile is empty?
We are on Oracle 11g with ASM file system.
Please let me know the process in detail.
Thanks in advance.
Regards.Hi Girish,
Thanks for putting an effort to reply on my query.
If I am not mentioning the optional solution (Shrink Tablespace) for this issue, it does not mean that I have not done my part at all.
I know shrinking the datafile will reduce the size of the datafile but we can say this is the optional solution for this problem.
I know we can drop a datafile including its contents but my question is: How can we know a datafile contains what table's data?
If you have answer of this query, will appreciate if you can post your answer.
Well, my unresolved questions are not 21, its very less, it is just that I have not marked those as answered, I will update all answered questions today :)
Regards. -
Version: 11.1.0.7.4 RAC & ASM
OUR DB size is 3TB and all the tablespaces are BIGFILE tablespaces, one datafile has grown to consumed all Free Space in ASM. We have dropped the table, but some LOB segments are at the end of the data file, so we could not shrink the datafile at this time as we are getting below error
ORA 3297 file contains <num> blocks of data beyond requested RESIZE value
Datpump export & re-import all the object in that tablespace will relieve the space. However at this time there is not empty ASM space to adopt this route.
So If we take "COMPRESSED RMAN BACKUP" of this tablespace and drop the tablespace and re-store it again, will the segments in that tablespace after re-store will be compact? so that we can re-size the datafile?
or
RMAN tablespace restore will have no effect on segments inside the tablespace evethough the RMAN backup is COMPRESSED ?try this,
alter table your_big_table deallocate unused keep your_req_value;
Also you can move the big table into an another tablespace,
alter table your_big_table move tablespace more_space_tablespace;
You can also use DBMS_REDEFINITION package to reorganize a table while it remains online for updates.
Thanks -
Need query to find the minimum size of a datafile
Hi All,
I need to reduce the size of a datafile. Before that i need to find out how far i can reduce the size of the datafile. Please help
DB version:11.2.0.3
OS:AIX 6.1Below SQL will ask you blocksize (I guess it is default i.e. 8192) :
select 'alter database datafile '''||file_name||''' resize ' ||
ceil( (nvl(hwm,1)*&&blksize)/1024/1024 ) || 'm;' cmd
from dba_data_files a,
( select file_id, max(block_id+blocks-1) hwm
from dba_extents
group by file_id ) b
where a.file_id = b.file_id(+)
and ceil( blocks*&&blksize/1024/1024) -
ceil( (nvl(hwm,1)*&&blksize)/1024/1024 ) > 0
It will tell you upto how much extend you can shrink your datafile.
Regards
Girish Sharma -
Can we resize/shrink data file if objects stored on fragmented space
Can we shrink data file if objects stored on fragmented space
for example if i
1- delete records from a table
2- shrink objects
if i do above two process and then i can resize or shrink the datafiles on which these objects are stored.
regards,AMIABU wrote:
i have no any SQL that can show me fregmentation. can you please provide.
regards,Then how do you know you have it and need to fix it?
Maybe you are looking for
-
How to trigger an Idoc from Sales order creation and change
We are trying to trigger Idoc from sales order creation and change we have done following setting mentioned below: Follow the below steps: 1. Go to NACE transaction 2. Select V1 application and select OUTPUT TYPES 3. Select the required output type a
-
Imlib_context_free() starting Conky ....
I am trying to run Conky on ArchLinux x86_64, with LXDE. This is what I did. $ sudo pacman -S conky $ mkdir ~/.conkyrc $ cp /etc/conky/conky.conf ~/.conkyrc $ conky Then I get this ... Conky: missing text block in configuration; exiting ***** Imlib2
-
Bluetooth headset setup in infinite loop
I have been trying to pair my Bluespoon AX2 with my Macbook pro. Every time I go through the process of finding the headset, entering the access key, and then my mac goes into an infinite loop while it is "Gathering additional information about your
-
I'm having an exceedingly infuriating time trying to install flash on my mac I'm using safari 7.1.....i needed to update my flash player for one of my movie sites so i goto n adobe and I followed the instructions, went through user name and password
-
What more details can be added?