SQL> create tablespace ts1
  2  datafile '/home/oracle/ts1.dbf' size 10M;

테이블스페이스가 생성되었습니다.

10M 할당된 테이블스페이스가 생성되었다

 

 SQL> create table t1
  2  (id number)
  3  tablespace ts1;

테이블이 생성되었습니다.

※ 참고로 테이블스페이스는 관리자가 생성하고 t1테이블은 유저가 만든것이다

(다시 말해 유저가 테이블을 만들수있게 관리자가 테이블스페이스를 할당했다고 생각하면 된다)

 

 SQL> select TABLE_NAME, TABLESPACE_NAME from user_tables;

TABLE_NAME      TABLESPACE_NAME
---------------    ---------------
T1                                TS1
DEPT                        USERS
EMP                         USERS
BONUS                     USERS
SALGRADE                USERS

 

T1 테이블에 데이터를 꽉 채워 본다

 SQL> insert into t1 select * from t1;

28 개의 행이 만들어졌습니다.

...

SQL> insert into t1 select * from t1;

114688 개의 행이 만들어졌습니다.

SQL> insert into t1 select * from t1;

229376 개의 행이 만들어졌습니다.

SQL> insert into t1 select * from t1;
insert into t1 select * from t1
*
1행에 오류:
ORA-01653: unable to extend table SCOTT.T1 by 128 in tablespace TS1

 

 이제 테이블스페이스를 확장시켜본다

  

 SQL> alter tablespace ts1 add
  2  datafile '/home/oracle/ts1_2.dbf' size 20M;

테이블스페이스가 변경되었습니다.

 

20M를 추가하여 기존의 10M와 함께 전체 30M가 되었다

 

 SQL> insert into t1 select * from t1;

458752 개의 행이 만들어졌습니다.

 데이터가 더 들어가진다!!

다시 계속 집어넣는다

 

SQL> ALTER DATABASE DATAFILE '/home/oracle/ts1.dbf' RESIZE 30M;

데이타베이스가 변경되었습니다.

SQL> ALTER DATABASE DATAFILE '/home/oracle/ts1.dbf'

2 AUTOEXTEND ON NEXT 10M MAXSIZE 100M;

데이타베이스가 변경되었습니다.

 

 SQL> insert into t1 select * from t1;

1835008 개의 행이 만들어졌습니다.

 계속 들어간다...

 

 테이블 t1의 크기는

SQL> show parameter db_block_size

NAME                                 TYPE               VALUE
---------------------- ----------------- ---------------
db_block_size                        integer               8192


SQL> desc dba_extents
 이름                                               널?      유형
 -------------------------------- -------- ------------
 OWNER                                                    VARCHAR2(30)
 SEGMENT_NAME                                     VARCHAR2(81)
 PARTITION_NAME                                     VARCHAR2(30)
 SEGMENT_TYPE                                       VARCHAR2(18)
 TABLESPACE_NAME                                 VARCHAR2(30)
 EXTENT_ID                                                   NUMBER
 FILE_ID                                                         NUMBER
 BLOCK_ID                                                     NUMBER
 BYTES                                                         NUMBER
 BLOCKS                                                       NUMBER
 RELATIVE_FNO                                             NUMBER

 

SQL> select sum(blocks) from dba_extents
  2  where segment_name = 'T1';

SUM(BLOCKS)
-----------
      14336

 

SQL> select 14336 * 8192 from dual;

14336*8192
----------
 117440512

 대략..120메가 정도 된다...

[테이블스페이스 생성하기]

create tablespace data1 datafile '/oracle/oradata/stone/data1.dbf' size  6M
default storage (initial 50k next 50k minextents 10 maxextents 121 pctincrease 0);

테이블 스페이스는 locally managed tablespace를 사용하구요.   

uniform extent size 옵션과 함께 사용하면 데이터들이 각 disk에 고르게 분산이 되어 저장 됩니다.

 

물론 아시겠지만 가장 좋은 분산 방법은 hardware혹은 file system의 기능을 사용한 raid 1+0 입니다.

 

[테이블스페이스 삭제하기]

-- 테이블스페이스 내용도 지우고 데이터파일도 같이 지우기

drop tablespace tsdiskdiary01 including contents and datafiles;

drop tablespace SAMPLE_STONE including contents;

 

-- 테이블스페이스 정보보기
select  tablespace_name, block_size, initial_extent, next_extent, min_extents, max_extents, pct_increase, status from   dba_tablespaces;
select * from dba_data_files;
select * from dba_tablespaces;
select * from v$datafile;

-- 테이블스페이스 만들기
create tablespace data1 datafile '/oracle/oradata/stone/data1.dbf' size  6M
default storage (initial 50k next 50k minextents 10 maxextents 121 pctincrease 0);
/*
initial 50k => 처음 생성되는 익스텐트의 크기
next 50k => 현재 존재하는 마지막 익스텐트 다음에 생성될 익스텐트에 할당할 크기
minextents 10 => 세그먼트가 생성될 때 할당되어야 하는 익스텐트의 수
maxextents 121 => 오라클이 객체에 대해 할당할수 있는 익스텐트의 최대수
pctincrease 0 => 마지막 익스텐트 다음에 생성될 익스텐트의 증가율
*/

-- 테이블스페이스 만들기
create tablespace idx1 datafile '/oracle/oradata/stone/idx1.dbf' size  6M
default storage (initial 50k next 50k pctincrease 0);

create tablespace rds datafile '/oracle/oradata/stone/rds.dbf' size  6M
default storage (initial 50k next 50k pctincrease 0);
-- temp 테이블 스페이스는 안 만들어진다.
create tablespace temp datafile '/oracle/oradata/stone/temp.dbf' size  3M
temporary;


alter tablespace data1 add datafile '/oracle/oradata/stone/data11.dbf' size  3M;
-- 테이블스페이스에 새로운 파일 추가
create tablespace test
 datafile '/oracle/oradata/stone/test.dbf' size 1m;

drop tablespace test;

-- 기존에 있는 데이터파일을 테이블스페이스 파일로 다시 사용한다.
alter tablespace data1
 add datafile  '/oracle/oradata/stone/test.dbf' reuse;

-- 데이터파일의 크기를 늘린다.
alter database datafile
 '/oracle/oradata/stone/test.dbf' resize 1m;

-- 자동으로 증가하는 테이블스페이스 만들기
alter database datafile '/oracle/oradata/stone/test.dbf'
 autoextend on;

-- 테이블스페이스 생성하기
create tablespace app1_data
 datafile '/oracle/oradata/stone/app101.dbf' size 1024k;

create tablespace appl_data
 datafile '/oracle/oradata/stone/appl01.dbf' size 100k;


-- 테이블스페이스 관련 정보보기
select * from dba_tablespaces where tablespace_name = 'TEMP';
-- 얼마의 용량이 남았는지 확인하기
select * from dba_free_space where tablespace_name = 'TEMP';

-- appl_data 테이블스페이스에 test 테이블 만들기 100k 이상하면 에러가 난다..
create table test (num number)
 tablespace appl_data
 storage (initial 50k);

select * from dba_free_space where tablespace_name = 'APP1_DATA';
select * from user_segments where segment_name = 'TEST';

-- 데이터파일 확인하기
select * from dba_data_files;

select * from dba_rollback_segs;

select * from dba_roles;
-- connect, RESOURCE, DBA 역할에 주어진 권한 확인하기
select * from dba_sys_privs where grantee = 'CONNECT';
select * from dba_sys_privs where grantee = 'RESOURCE';
select * from dba_sys_privs where grantee = 'DBA';
select * from dba_users;
-- 사용자에 할당된 테이블스페이스 영역
select * from user_ts_quotas;
-- 사용자 세션 확인하기
select * from v$session;
-- 인덱스 확인하기
select * from user_indexes;

 

CREATE TABLESPACE tsdiskdiary01
DATAFILE '/oracle/oradata/stone/tsdiskdiary01.dbf' SIZE 100M
DEFAULT STORAGE
(INITIAL    10K
NEXT      10K
MINEXTENTS 2
MAXEXTENTS 50
PCTINCREASE 50);

 

[테이블스페이스 생성하기]

create tablespace tsdiskdiary01
datafile '/oracle/oradata/stone/tsdiskdiary01.dbf' size 500M
extent management local uniform size 1M;

create user diskdiary identified by diskdiary      -- 일반계정
    default tablespace tsdiskdiary01
    profile default;


grant connect, resource to diskdiary;

drop tablespace tsdiskdiary01 including contents and datafiles;

drop user diskdiary cascade;  
-- 데이터파일 추가하기
alter tablespace sample_stone add datafile  '/oracle/oradata/stone/sample_stone02.dbf' SIZE 200M

 

[테이블스페이스 용량 확인하기]

SELECT a.tablespace_name,
             a.total "Total(Mb)",
             a.total - b.free "Used(Mb)",
             nvl(b.free,0) "Free(Mb)",
             round((a.total - nvl(b.free,0))*100/total,0)  "Used(%)"
from     (select   tablespace_name, round((sum(bytes)/1024/1024),0) as total
             from     dba_data_files
             group   by tablespace_name) a,
           (select  tablespace_name, round((sum(bytes)/1024/1024),0) as free
            from      dba_free_space
            group by tablespace_name) b
where   a.tablespace_name = b.tablespace_name(+)
order by a.tablespace_name;

select SEGMENT_NAME, SEGMENT_TYPE, INITIAL_EXTENT, NEXT_EXTENT
   where TABLESPACE_NAME ='SAMPLE_STONE'
   and    SEGMENT_NAME= 'AAA ';

alter tablespace sample_stone add datafile  '/oracle/oradata/stone/sample_stone02.dbf' SIZE 200M


+ Recent posts