问题
I need to shrink a tablespace in oracle 11g. It is not a temporary table-space, I cant lose the data in that tablespace. One of my other tablespaces is out of space so I have to reallocate the remaining size of this tablespace. shrink does not work on a permanent tablespace. The current size of the datafile is 1150MB and I want it to be 256MB
回答1:
You can resize the file, thus:-
ALTER DATABASE DATAFILE '/your/path/your_file01.dbf' RESIZE 256M;
of course if you already used some space above 256M then you will get an error
ORA-03297: file contains used data beyond requested RESIZE value
Then you can use this query to see the smallest size you can resize the datafile:
SELECT CEIL((NVL(e.hwm, 1) * 8192)/1024/1024) as "Mb"
FROM
dba_data_files f
LEFT
JOIN (SELECT file_id, max(block_id + blocks - 1) hwm FROM dba_extents GROUP BY file_id) e ON f.file_id = e.file_id
WHERE
f.file_name = '/your/path/your_file01.dbf'
/
*If your tablespace block size is not 8192 then change that value first. Also note that the query will take a long time to run - this is normal - alternatively you can just use the trial and error technique favoured by many and resize it a bit at a time until it errors out.
来源:https://stackoverflow.com/questions/15563408/shrink-permanent-tablespace-in-oracle-11g