Home » RDBMS Server » Server Administration » How to Reclaiming Wasted Space throughly (Oracle 10.2.0.5 64bit, HPUX PA 11.11 64bit)
How to Reclaiming Wasted Space throughly [message #580651] |
Tue, 26 March 2013 09:26 |
snowball
Messages: 229 Registered: April 2006 Location: China
|
Senior Member |
|
|
Hi, Guys
In one of our Data warehousing DB, even though, all the tablespaces' space should keep on at least 1 month, but our leader want us to estimate how much space can free up with db method.
I have referenced
<Administrator Guide> - Reclaiming Wasted Space
http://docs.oracle.com/cd/B19306_01/server.102/b14231/schema.htm#sthref2092
I have several questions on reclaim space:
1. It seems that segment advisor give a really cool view to know which segment should be shrinked and how much size will free up after shrinked.
But actually, this need a very a job or manually do this. I have once heard about some query from can estimate this :
A script from MOS, but actually I found this it's not very accurate with segment advisor.
This script should report the real space the table occupy, but after shrink space, the space doesn't free up.
SELECT TABLE_NAME , (BLOCKS *8192 / 1024/1024 ) - (NUM_ROWS*AVG_ROW_LEN/1024/1024)
"Data lower than HWM in MB" FROM DBA_TABLES WHERE UPPER(owner) =UPPER('&OWNER') order by 2 desc;
Also there is a script evaluate the tablespace fragments from some people:
SELECT tablespace_name,
SQRT (MAX (blocks) / SUM (blocks))
* (100 / SQRT (SQRT (COUNT (blocks))))
FSFI
FROM dba_free_space
GROUP BY tablespace_name
ORDER BY 1;
if the value is very low, we can coalesce the tablespace. But after I coalesce the tablespace, I can't see any space free up.
From <Concepts>:
Quote:Coalescing extents is not necessary in
locally managed tablespaces, because all contiguous free space is available for
allocation to a new extent regardless of whether it was reclaimed from one or more
extents.
I don't know if these script right or not, OR i wrongly understand these scripts. If I were, please forgive me as I am not English native speaker.
2. is there any good way to estimate how much space we should free up? ( After free up the space , dba_free_space should see this result)
Thanks very much.
|
|
|
|
|
|
Re: How to Reclaiming Wasted Space throughly [message #580689 is a reply to message #580658] |
Tue, 26 March 2013 18:58 |
snowball
Messages: 229 Registered: April 2006 Location: China
|
Senior Member |
|
|
Thanks, Michel.
I can see from dbms_space package, that there are 2 procedures related with space estimate:
Quote:
SPACE_USAGE Procedure
Returns information about free blocks in an auto segment space managed segment
UNUSED_SPACE Procedure
Returns information about unused space in an object (table, index, or cluster)
I try both, but don't really know how those two can give me the benefit of shrink or not.
Before delete some records of the table:
SQL> select segment_name, bytes from user_segments where segment_name='TAB2';
SEGMENT_NAME BYTES
-------------------- ----------
TAB2 6291456
SQL> variable unf number;
SQL> variable unfb number;
SQL> variable fs1 number;
SQL> variable fs1b number;
SQL> variable fs2 number;
SQL> variable fs2b number;
SQL> variable fs3 number;
SQL> variable fs3b number;
SQL> variable fs4 number;
SQL> variable fs4b number;
SQL> variable full number;
SQL> variable fullb number;
SQL>
SQL> begin
2 dbms_space.space_usage('SCOTT','TAB2',
3 'TABLE',
4 :unf, :unfb,
5 :fs1, :fs1b,
6 :fs2, :fs2b,
7 :fs3, :fs3b,
8 :fs4, :fs4b,
9 :full, :fullb);
10 end;
11 /
PL/SQL procedure successfully completed.
SQL> select :fullb+:fs1b+:fs2b+:fs3b+:fs4b from dual;
:FULLB+:FS1B+:FS2B+:FS3B+:FS4B
------------------------------
5758976
SQL> VAR total_blocks NUMBER;
SQL> VAR total_bytes NUMBER;
SQL> VAR unused_blocks NUMBER;
SQL> VAR unused_bytes NUMBER;
SQL> VAR lastextf NUMBER;
SQL> VAR last_extb NUMBER;
SQL> VAR lastusedblock NUMBER;
EXEC DBMS_SPACE.UNUSED_SPACE('SCOTT', 'TAB2', 'TABLE', :total_blocks,:total_bytes,:unused_blocks, :unused_bytes, :lastextf, :last_extb, :lastusedblock); ck);
PL/SQL procedure successfully completed.
SQL>
SQL> PRINT :unused_bytes;
UNUSED_BYTES
------------
40960
SQL> SELECT COUNT(*) FROM TAB2;
COUNT(*)
----------
51128
After delete the most data of the table:
SQL> SELECT COUNT(*) FROM TAB2;
COUNT(*)
----------
51128
SQL> DELETE FROM TAB2 WHERE ROWNUM <= 50000;
50000 rows deleted.
SQL> COMMIT;
Commit complete.
SQL> variable unf number;
SQL> variable unfb number;
SQL> variable fs1 number;
SQL> variable fs1b number;
SQL> variable fs2 number;
SQL> variable fs2b number;
SQL> variable fs3 number;
SQL> variable fs3b number;
SQL> variable fs4 number;
SQL> variable fs4b number;
SQL> variable full number;
SQL> variable fullb number;
SQL>
SQL> begin
2 dbms_space.space_usage('SCOTT','TAB2',
3 'TABLE',
4 :unf, :unfb,
5 :fs1, :fs1b,
6 :fs2, :fs2b,
7 :fs3, :fs3b,
8 :fs4, :fs4b,
9 :full, :fullb);
10 end;
11 /
PL/SQL procedure successfully completed.
SQL> select :fullb+:fs1b+:fs2b+:fs3b+:fs4b from dual;
:FULLB+:FS1B+:FS2B+:FS3B+:FS4B
------------------------------
5758976
SQL> VAR total_blocks NUMBER;
SQL> VAR total_bytes NUMBER;
SQL> VAR unused_blocks NUMBER;
SQL> VAR unused_bytes NUMBER;
SQL> VAR lastextf NUMBER;
SQL> VAR last_extb NUMBER;
SQL> VAR lastusedblock NUMBER;
SQL> EXEC DBMS_SPACE.UNUSED_SPACE('SCOTT', 'TAB2', 'TABLE', :total_blocks,:total_bytes,:unused_blocks, :unused_bytes, :lastextf, :last_extb, :lastusedblock);
PL/SQL procedure successfully completed.
SQL>
SQL> PRINT :unused_bytes;
UNUSED_BYTES
------------
368640
After shrink table :
SQL> alter table scott.tab2 enable row movement;
Table altered.
SQL> alter table scott.tab2 shrink space;
Table altered.
SQL> alter table scott.tab2 disable row movement;
Table altered.
SQL> select segment_name, bytes from user_segments where segment_name='TAB2';
SEGMENT_NAME BYTES
-------------------- ----------
TAB2 196608
SQL> VAR total_blocks NUMBER;
SQL> VAR total_bytes NUMBER;
SQL> VAR unused_blocks NUMBER;
SQL> VAR unused_bytes NUMBER;
SQL> VAR lastextf NUMBER;
SQL> VAR last_extb NUMBER;
SQL> VAR lastusedblock NUMBER;
EXEC DBMS_SPACE.UNUSED_SPACE('SCOTT', 'TAB2', 'TABLE', :total_blocks,:total_bytes,:unused_blocks, :unused_bytes, :lastextf, :last_extb, :lastusedblock); ck);
PL/SQL procedure successfully completed.
SQL>
SQL> PRINT :unused_bytes;
UNUSED_BYTES
------------
24576
SQL>
SQL>
SQL>
SQL> variable unf number;
SQL> variable unfb number;
SQL> variable fs1 number;
SQL> variable fs1b number;
SQL> variable fs2 number;
SQL> variable fs2b number;
SQL> variable fs3 number;
SQL> variable fs3b number;
SQL> variable fs4 number;
SQL> variable fs4b number;
SQL> variable full number;
SQL> variable fullb number;
SQL>
SQL> begin
2 dbms_space.space_usage('SCOTT','TAB2',
3 'TABLE',
4 :unf, :unfb,
5 :fs1, :fs1b,
6 :fs2, :fs2b,
7 :fs3, :fs3b,
8 :fs4, :fs4b,
9 :full, :fullb);
10 end;
11 /
PL/SQL procedure successfully completed.
SQL> select :fullb+:fs1b+:fs2b+:fs3b+:fs4b from dual;
:FULLB+:FS1B+:FS2B+:FS3B+:FS4B
------------------------------
139264
With the info from UNUSED_SPACE and UNUSED_SPACE, I can't figure out how I can get a estimate result after shrink.
Correct me if I'm wrong.
Thanks very much.
|
|
|
Re: How to Reclaiming Wasted Space throughly [message #580690 is a reply to message #580660] |
Tue, 26 March 2013 19:11 |
snowball
Messages: 229 Registered: April 2006 Location: China
|
Senior Member |
|
|
Hi, BlackSwan
Quote:Reclaim space from where to where?
Reclaim space from tables to tablespaces.
Quote:Reclaim space that exists due to DELETE inside 1 or more tables?
Yes, there are some tables have delete actions, but I need to get a estimate release size after shrink.
Quote:Reclaim space that exists due to TRUNCATE or DROP?
No. Truncate and Drop operations have been done, as this could release the space.
So we think of that if there is any possible to reclaim from table without archive or clean out the data.
Quote:Will new data ever be added such that it can reside in what is now "free space"?
Of course, there are some new data will be added every day, but this db doesn't clean or reclaim the space with database way, but business rule.
With business rules, such as Table A should keep latest 3 months data, so after 3 months, data can be clean before latest 3 months.
Thanks very much.
|
|
|
|
|
|
|
|
|
Re: How to Reclaiming Wasted Space throughly [message #580737 is a reply to message #580735] |
Wed, 27 March 2013 11:22 |
cookiemonster
Messages: 13962 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
[quote title=snowball wrote on Wed, 27 March 2013 15:36]Quote:
Quote:
What is the problem?
I don't really know, what's the problem, because the data require from developers, so only a very small part of data can be cleaned at specific time.
That's the reality. I can't push or change .
Question is - why does any free space need to be reclaimed? It'll be used up again by the tables that had it in first place sooner or later.
|
|
|
Goto Forum:
Current Time: Sun Jan 12 23:39:38 CST 2025
|