Logo Oracle |
Tablespace adalah storage dari segment,atau dengan kata lain adalah tempat dimana segment-segment database disimpan. Yang termasuk dalam segment adalah table, index, cluster, rollback(undo), temporary segment, dan lain-lain.
Object-object di dalam dalam suatu schema yang sama dapat memakai tablespace yang berbeda-beda. Suatu Tablespace dapat memiliki object-object dari schema yang berbeda-beda pula.
Singkatnya, oracle menyimpan data secara logical dengan Tablespace dan menyimpan data secara fisik dengan datafiles yang terhubung dengan tablespace.
Extend management :
Extend management :
- Locally managed
Direkomendasikan memakai ini, free extend direcord menggunakan bitmap - Data dictionary managed
Tidak direkomendasikan memakai ini, Free extend direcord menggunakan data dictionary, support only backward compatibility
- Automatic
Setiap ukuran extend diatur otomatis, automatic tidak bisa digunakan di temporary tablespae - Uniform
Ukuran setiap extendnya sama, kita yang menentukan sendiri besarnya
- Automatic (ASSM – Automatic segment space management)
Memakai bitmap untuk mengatur segment secara otomatis - Manual
Memakai freelist untuk mengatur segment. Freelist adalah daftar dari data block yang kosong . kalo kita menggunakan ini kita harus mengatur PCTUSED, FREELISTS, FREELISTS GROUP
Create simple tablespace :
CREATE TABLESPACE tablespace01
DATAFILE 'C:\OracleG11\Tablespace\tablespace01.dbf' SIZE
30m;
Create tablespace dengan multiple datafiles :
CREATE TABLESPACE tablespace02
DATAFILE 'C:\OracleG11\Tablespace\tablespace02.dbf' SIZE
30m,
'C:\OracleG11\Tablespace\tablespace03.dbf' SIZE 30m;
Drop tablespace :
DROP TABLESPACE tablespace02 INCLUDING CONTENTS AND
DATAFILES;
Mengatur size tablespace :
ALTER DATABASE
DATAFILE 'C:\OracleG11\Tablespace\tablespace01.dbf'
RESIZE 20m;
ALTER TABLESPACE tablespace01 ADD
DATAFILE '/oradata/oracle/ts_bak/tablespace0101.dbf' SIZE 10m;
Melihat dan Mengatur tablespace default :
select PROPERTY_VALUE from database_properties where PROPERTY_NAME='DEFAULT_PERMANENT_TABLESPACE';
alter database default tablespace tablespace01;
Melihat datafile, size, dan free size dari tablespace2 yang ada :
set pagesize 100
set sqlnumber off
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,
-- this give warning to high percentage usage tablespace
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
GROUP BY tbs.tablespace_name,
tot.bytes / 1024,
tot.bytes
ORDER BY 5, 1;
set sqlnumber off
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,
-- this give warning to high percentage usage tablespace
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
GROUP BY tbs.tablespace_name,
tot.bytes / 1024,
tot.bytes
ORDER BY 5, 1;
mengecek fragmentasi pada tablespace
create table SPACE_TEMP (
TABLESPACE_NAME CHAR(30),
CONTIGUOUS_BYTES NUMBER)
/
declare
cursor query is select *
from dba_free_space
order by tablespace_name, block_id;
this_row query%rowtype;
previous_row query%rowtype;
total number;
begin
open query;
fetch query into this_row;
previous_row := this_row;
total := previous_row.bytes;
loop
fetch query into this_row;
exit when query%notfound;
if this_row.block_id = previous_row.block_id + previous_row.blocks then
total := total + this_row.bytes;
insert into SPACE_TEMP (tablespace_name)
values (previous_row.tablespace_name);
else
insert into SPACE_TEMP values (previous_row.tablespace_name,
total);
total := this_row.bytes;
end if;
previous_row := this_row;
end loop;
insert into SPACE_TEMP values (previous_row.tablespace_name,
total);
end;
.
/
set pagesize 60
set newpage 0
set echo off
ttitle center 'Contiguous Extents Report' skip 3
break on "TABLESPACE NAME" skip page duplicate
spool contig_free_space.lis
rem
column "CONTIGUOUS BYTES" format 999,999,999
column "COUNT" format 999
column "TOTAL BYTES" format 999,999,999
column "TODAY" noprint new_value new_today format a1
rem
select TABLESPACE_NAME "TABLESPACE NAME",
CONTIGUOUS_BYTES "CONTIGUOUS BYTES"
from SPACE_TEMP
where CONTIGUOUS_BYTES is not null
order by TABLESPACE_NAME, CONTIGUOUS_BYTES desc;
select tablespace_name, count(*) "# OF EXTENTS",
sum(contiguous_bytes) "TOTAL BYTES"
from space_temp
group by tablespace_name;
spool off
drop table SPACE_TEMP
/
sumber :
0 komentar :
Posting Komentar
Mari berkomentar dengan baik, benar, dan sopan :D