블로그 이미지
redkite

카테고리

분류 전체보기 (291)
00.SI프로젝트 산출물 (0)
00.센터 운영 문서 (0)
01.DBMS ============.. (0)
01.오라클 (117)
01.MS-SQL (15)
01.MySQL (30)
01.PostgreSql (0)
01.DB튜닝 (28)
====================.. (0)
02.SERVER ==========.. (0)
02.서버-공통 (11)
02.서버-Linux (58)
02.서버-Unix (12)
02.서버-Windows (2)
====================.. (0)
03.APPLICATION =====.. (11)
====================.. (0)
04.ETC =============.. (0)
04.보안 (5)
====================.. (0)
05.개인자료 (1)
06.캠핑관련 (0)
07.OA관련 (1)
Total
Today
Yesterday

달력

« » 2024.5
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

공지사항

최근에 올라온 글

오라클 9i 이상

- Locally Management Tablespace 권장

 

1. 기존 TEMP TABLESPACE를 DROP 후 CREATE

   SQL> connect / as sysdba

 

   SQL> CREATE TEMPORARY TABLESPACE IMSI TEMPFILE  '/oradata/imsi.dbf' size 10m;

   SQL> ALTER DATABASE DEFAULT TEMPORARY TABLESPACE IMSI;

   SQL> ALTER DATABASE TEMPFILE '/oradata/temp01.dbf' OFFLINE;
   SQL> DROP TABLESPACE TEMP INCLUDING CONTENTS AND DATAFILES;


   SQL> CREATE TEMPORARY TABLESPACE TEMP

                         TEMPFILE '/oradata/temp01.dbf' SIZE 1000M
                         EXTENT MANAGEMENT LOCAL UNIFORM SIZE 1M;
   SQL> ALTER DATABASE DEFAULT TEMPORARY TABLESPACE TEMP;

   SQL> ALTER DATABASE TEMPFILE '/oradata/imsi.dbf' OFFLINE;
   SQL> DROP TABLESPACE IMSI INCLUDING CONTENTS AND DATAFILES;

 

2. TEMPFILE RESIZE

   SQL> connect / as sysdba
   SQL> alter database tempfile '/oradata/temp01.dbf' resize 4000M; 

 

3. TEMPFILE RENAME

   SQL> shutdown immediate;
   SQL> !mv /data1/temp.dbf /data2/temp01.dbf (만약을 위해 cp를 사용할 것을 권장합니다.)
   SQL> startup mount
   SQL> alter database rename file '/data1/temp.dbf' to '/data2/temp01.dbf';
   SQL> alter database open;

8i에서는 tempfile이란 개념은 있었으나 default temporary tablespace라는
개념은 없었습니다. 그래서 유저에게 직접 default tablespace를 지정해주어야
했었습니다.
하지만.. 9i부터는 alter database default temporary tablespace new_temp;
명령을 하기만 하면 모든 유저의 default temporary tablespace가 default로
지정되어 있지 않으면 new_temp로 됩니다.
물론 이 경우에도 수동으로 temp를 지정할 수 있으니 실제로 유저가
temp공간을 어디에 사용하는지는..
select username, temporary_tablespace from dba_users; 를 통해서
확인해야 합니다.
scott유저는 default temporary tablespace로 지정되어서 그 쪽 temp를
사용하게 되니, 에러가 나지 않겠죠.

default temporary tablespace가 무엇으로 지정되어 있는지는,
select * from database_properties; 또는 select * from sys.props$; 로 조회하면
temporary tablespace라는 이름으로 어떤 값이 들어가 있는지 보입니다.

그리고 temp는 DB를 내렸다가 올리면 smon프로세스가 clear시켜줍니다.
temp는 아시다 싶이 당연히 sort를 해서 발생하는 것이구요. 그렇다면..
temp가 계속해서 full이 난다면.. temp를 사용하는 세션을 확인하고
temp를 사용하는 세션의 쿼리를 뽑아낸다면 쉽게 해결이 되겠죠.
아래는 제가 경험해서 처리한 것입니다.


저는 temporary tablespace가 full 났는데 도대체 쿼리를 못잡는 것이었습니다.
그래서 어떻게 했을까요? Secure CRT에 세션로그를 걸어두고 모니터링을 했죠.

vi stat.sh

interval=30 # Sleep interval in seconds
reps=1000000 # n times
j=1 # Loop variable

while [ $j -le ${reps} ]
do
echo " ----cycle ${j} / ${reps} --------"

sqlplus -s system/패스워드<<EOF
@sw.sql ${j}
exit
EOF
cat sess_${j}.dat >> sw.dat
rm sess_${j}.dat
sleep ${interval}
j=`expr ${j} + 1`
done
exit 0

vi sw.sql
set line 150
set concat "+"
col username format a10
col osuser format a10
col tablespace format a15
spool sess_&1.dat

SELECT b.tablespace,
b.segfile#,
b.segblk#,
b.blocks,
a.sid,
a.serial#,
c.spid,
a.username,
a.osuser,
a.status,
a.sql_hash_value
FROM v$session a,
v$sort_usage b,
v$process c
WHERE a.saddr = b.session_addr and a.paddr=c.addr
ORDER BY b.tablespace, b.segfile#, b.segblk#, b.blocks;
spool off

stats.sh 를 수행하고 PC킨 상태로 그냥두고 다음날 왔더니 아래처럼 temp를
계속 쓰는 넘이 나온거죠..
딱걸렸습니다.ㅎㅎ

TEMP 93 2550817 13824 92 58284 3193 PVB oracle ACTIVE 1126923165
----cycle 1792 / 1000000


TEMP 93 2550817 43008 92 58284 3193 PVB oracle ACTIVE 1126923165
----cycle 1793 / 1000000


TEMP 93 2550817 72192 92 58284 3193 PVB oracle ACTIVE 1126923165
----cycle 1794 / 1000000


TEMP 93 2550817 101376 92 58284 3193 PVB oracle ACTIVE 1126923165
----cycle 1795 / 1000000


TEMP 93 2550817 131072 92 58284 3193 PVB oracle ACTIVE 1126923165
----cycle 1796 / 1000000


TEMP 93 2416673 18944 123 5171 3197 PVB oracle ACTIVE 1126923165
TEMP 93 2550817 159744 92 58284 3193 PVB oracle ACTIVE 1126923165
----cycle 1797 / 1000000


TEMP 93 2416673 48128 123 5171 3197 PVB oracle ACTIVE 1126923165
TEMP

sql_hash_value값이 1126923165 이니 아래 쿼리에다가 넣으면 full 쿼리가 나오죠..
결국엔 개발자가 모든 소스코드에서 변경을 했어야 했는데.. 그렇게 하지 않아서
일부 웹서버에서의 쿼리가 이상하게 where조건없이 수행되었고 그래서 temp가
full 났던 것이랍니다.

vi sidhashsql.sql
set pages 1000
col sql_text format a120
select sql_text from v$sqltext_with_newlines
where hash_value=&hash_value order by piece;

SQL> @sidhashsql
Enter value for hash_value: 1126923165
old 2: where hash_value=&hash_value order by piece
new 2: where hash_value=1126923165 order by piece

SQL_TEXT

boan~~~~!!

###################################################

아래 너무 자세하게 나와있죠?
No. 18484

TEMPORARY TABLESPACE에서 TEMPFILE 과 DATAFILE의 차이점 (8.1.X ~ 9I)
============================================================

PURPOSE

이 문서에서는 Oracle 7.3부터 사용되어 오던 create tablespace ... temporary
형태와, 8i부터 사용되는 create temporary tablespace... 의 차이점을 정리해
본다.
tablespace의 temporay type과 permanent type에 대한 비교는 <Bulletin#: 11938>
를 참조하도록 하고 여기에서는 permanent에 대해서는 논외로 한다.

Explanation

temporary segment가 생성 가능한 tablespace의 type과 temporary tablesapce에서
datafile과 tempfile의 차이점을 설명한다.

1. temporary segment를 생성가능한 tablespace type 정리

temporary tablespace의 tempfile과 datafile을 비교하기 전에, tablespace의
type들을 확인해 보고, 이 중 temporary segment가 생성될 수 있는 tablespace
type을 version별로 정리해본다.

tablespace는 7.2까지는 permanent type으로 dictionary managed방식으로
space를 할당/해제하던 방식만이 존재했다. db user의 temporary tablespace로
임의의 tablespace를 지정가능하였고, 해당 db user의 sort operation은
지정된 tablespace에서 발생하며, 다른 tablespace와 특별히 구분되는 것은
없었다.

이후, 7.3에 temporary type이 추가되고, 8i에서 locally managed type과 일반
datafile이 아닌 tempfile이 소개되면서 8i를 기준으로 기본적으로 다음과 같이
4가지 형태의 tablespace 형태가 가능하다.
이중 (1) ~ (3)번까지는 일반 datafile형태이고, (4)번의 경우는 이 문서에서
자세히 살펴볼 tempfile이다.
(locally managed와 dictionary managed의 차이점 및 사용 방법은
<Bulletin #: 18261>과 <Bulletin #: 11860> 참조)

(1) permanent-dictionary managed
(2) permanent-locally managed
(3) temporary-dictionary managed
(4) tempfile-locally managed

[주의] 위의 종류에 temporary datafile에 locally managed 형태의 tablespace는
없는것에 주의한다.
그리고 만약 system tablespace가 locally managed로 이미 생성된 경우에는
이후 모든 tablespace는 locally managed로 생성이 가능하고, dictionary
managed 형태는 생성하면 ORA-12913 (Cannot create dictionary managed
tablespace) 오류가 발생하게 된다.

이러한 여러가지 type의 tablespace중 temporary segment를 생성할 수 있는
tablespace에 제약이 존재한다.

- 8i: 어떠한 형태의 tablespace라도 db user의 temporary tablespace로 지정
가능하다. 단, permanent-locally managed 형태의 tablespace에 sort가
발생하게 되면 ORA-3212 (Temporary Segment cannot be created in
locally-managed tablespace) 오류가 발생하게 된다.

SQL> alter user scott temporary tablespace PERM_LOCAL;
User altered.

connect scott/tiger
SQL> select * from dept order by 1;
ORA-03212: Temporary Segment cannot be created in locally-managed
tablespace

- 9i: db user의 default temporary tablespace 지정 자체가 다음 두 가지
type만이 가능한다.

-temporary-dictionary managed
-tempile-locally managed

만약 permanent type의 tablespace를 db user의 tempoary tablespace로
지정하면, ORA-12911 (permanent tablespace cannot be temporary tablespace)
오류가 발생한다.

2. tempfile과 datafile의 비교

아래에서 tablespace지정시 tempfile과 datafile형태를 비교하게 되는데,
단, datafile형태의 경우 permanent type에 대해서는 언급하지 않는다.

(1) tempile의 특징

Oracle7.3에서 tablespace에 생성시 temporary option을 이용하여 생성되는
tablespace를 구성하는 화일은 datafile이다. 단지 이것이 기존의 permanent
type과 구별되는것은 이 tablespace에 생성되는 segment들이 매번 sort
operation마다 별도로 생성되는 대신, 하나의 segment로 만들어지면서
다른 session에서의 sort operation이 같은 segment를 공유하는 것이다.
(자세한 것은 <Bulletin#: 11938> 참조)

Oracle8.1부터 추가된 tempfile형태의 중요한 특징은 tempfile에 발생하는
변경사항은 redo log file에 기록되지 않는다는 것이다. tempfile에
checkpoint정보도 기록하지 않고 이에 따라 datafile recovery시에도
tempfile에 대해서는 recovery가 필요없게 된다.
이와 같은 이유로 standby database에서 read-only mode로 open하고
조회시 sort가 발생하여 tempfile이 변경되는것은 문제가 되지 않아
사용이 가능하다.

그리고 이미 앞에서 설명한 것과 같이 tempfile은 항상 locally managed
type으로만 생성이 되며, datafile형태의 temporary tablespace는 다음과
같이 locally managed type으로 생성 자체가 불가능하다.

SQL> create tablespace temp_datafile_local
2 DATAFILE '/ora/oradata/V920/temp_data.dbf' size 100M
3 TEMPORARY
4 EXTENT MANAGEMENT LOCAL UNIFORM SIZE 128K;

ORA-25144: invalid option for CREATE TABLESPACE with TEMPORARY contents


(2) temporary tablespace 생성 방법 비교

- tempfile형태의 경우
tempfile로 temporary tablespace를 생성하는 경우는 다음과 같이
생성하여야 하며, 반드시 locally managed 형태로만 생성 가능하다.

SQL> create TEMPORARY tablespace temp_tempfile_local
2 TEMPFILE '/ora/V920/temp_temp.dbf' size 100M
3 EXTENT MANAGEMENT LOCAL UNIFORM SIZE 128K;

아래 명령어에서 3번 line을 제거하고 생성하여도 default로 locally
managed로 생성이 되며, dictionary managed 형태로 생성하고자
3번 line대신 storage option을 추가하면
ORA-2180 (invalid option for CREATE TABLESPACE) 오류가 발생한다.

- datafile형태의 경우
다음과 같은 형태로 생성하게 되면, dictionary managed type의
temporary datafile형태로 tablespace가 만들어진다. 단, 9i의 경우
이미 앞에서 언급한대로 system tablespace가 locally managed인 경우에는
이와 같은 dictionary managed tablespace 생성은 ORA-12913이 발생하면서
불가능하게 된다.

SQL> create tablespace temp_datafile_dict
2 datafile '/ora/oradata/V920/temp_data.dbf' size 100M
3 TEMPORARY;

(3) dictionary view 의 차이

먼저 dba_tablespaces를 통해
SQL> select tablespace_name, contents, extent_management,
allocation_type from dba_tablespaces;

TABLESPACE_NAME CONTENTS EXTENT_MAN ALLOCATIO

TEMP_TEMPFILE_LOCAL TEMPORARY LOCAL UNIFORM
TEMP_DATAFILE_DICT TEMPORARY DICTIONARY

- tempfile의 경우

SQL> select STATUS, ENABLED, NAME from v$tempfile;

STATUS ENABLED NAME

ONLINE READ WRITE /ora/V920/temp_temp.dbf

SQL> select FILE_NAME, TABLESPACE_NAME from dba_temp_files;

FILE_NAME TABLESPACE_NAME

/ora/V920/temp_temp.dbf TEMP_TEMPFILE_LOCAL


- datafile 형태의 경우

다음과 같이 v$datafile과 dba_data_files를 통해 조회한다.

SQL> select STATUS, ENABLED, NAME from v$datafile;

STATUS ENABLED NAME

ONLINE READ WRITE /ora/oradata/V920/temp_data.dbf

SQL> select FILE_NAME, TABLESPACE_NAME from dba_data_files;

FILE_NAME TABLESPACE_NAME

/ora/oradata/V920/temp_data.dbf TEMP_DATAFILE_DICT

(4) tempfile의 삭제에 대해서

datafile의 경우 tablespace를 삭제하지 않고 datafile만 삭제하는 방법은
존재하지 않는다. 물론 alter database datafile 'filename' offline drop;
과 같은 command가 있지만 이것도 datafile을 데이타베이스에서 지워주는
것이 아니며 이렇게 offline drop된 datafile을 포함하는 tablespace는
recovery가 불가능한 경우라면 tablespace자체를 삭제해야 한다.

그런데 tempfile의 경우는 temporary tablespace는 그대로 유지한 채,
tempfile만 삭제하는 것이 가능하다.

SQL> alter database tempfile '/oradata/V817/temp_temp01.dbf'
2 drop;

8i의 경우라면 이와 같은 명령어 후 실제 directory로 이동하여 직접
tmep_temp01.dbf를 삭제하여야 한다.

9i에서는 drop뒤에 including datafiles 라는 option을 추가하여 tempfile의
drop시 바로 os상에서도 삭제되도록 할 수 있다.

SQL> alter database tempfile '/oradata/V817/temp_temp01.dbf'
2 drop including contents;

만약 이러한 방법으로, tempfile을 해당 temporary tablespace에서 모두
삭제한 경우, 실제 해당 tablespace에 disk sort가 필요하게 되면,
그때는 ORA-25153 (Temporary Tablespace is Empty) 오류가 발생하게 된다.

이때는 다음과 같이 임의의 tempfile을 다시 추가할 수 있다.

SQL> alter tablespace TEMP_TEMPFILE_LOCAL
2 add tempfile '/oradata/V817/temp_temp02.dbf';

Reference Documents

광주은행 안심클릭 DB 작업

### default temp 파일로 생성되어 있을 경우 아래처럼 drop 후 추가하면 됨
SQL> alter database tempfile '/logs/oradata/temp01.dbf' drop;

Database altered.

SQL> alter tablespace TEMP add tempfile '/logs/oradata/acsdb/temp01.dbf' SIZE 100M;

Tablespace altered.

### datafile type으로 temp 생성 되어 있을 경우
SQL> CREATE TEMPORARY TABLESPACE TEMP02 TEMPFILE '/logs/oradata/temp02.dbf' SIZE 100M
Tablespace created.
SQL> alter user VISA3D temporary tablespace TEMP02;
SQL> alter tablespace TEMP offline;
Tablespace altered.

SQL> drop tablespace temp;
Database droped.


### DATA 파일 이동
SQL> ALTER TABLESPACE USER_DATA RENAME DATAFILE '<OLD FILE>' TO '<NEW FILE>';

Posted by redkite
, |

최근에 달린 댓글

최근에 받은 트랙백

글 보관함