BLOG main image
정민군's Blog
miniya devlog

모든 테이블의 ROW수 계산

Database/Oracle 2007. 3. 20. 15:32 by 정민군
set linesize 1000 pagesize 10000 feedback off
spool count_tb
select 'select count(*) from ' || table_name || ';' from user_tables;
spool off
@count_tb.lst

ORA-01157 cannot identify data file %s
 
01157, 00000, "cannot identify data file %s - file not found"
// *Cause: The background process was not able to find one of the data files.
// The database will prohibit access to this file but other files will
// be unaffected. However the first instance to open the database will
// need to access all online data files. Accompanying error from the
// operating system describes why file was not found.
// *Action: Have operating system make file available to database. Then either
// open the database or do ALTER SYSTEM CHECK DATAFILES.
 
1. 데이타 화일을 백업받아놨다면
--- ERROR위치에 데이타화일을 옮겨 놓고 기동시킨다.
2. 데이타 화일이 없을시
--- 문제의 데이타 화일을 확인후 회이을 오라클상에서 삭제하여 오라클이 정상적으로 가동하도록 만들어 주어야 한다.
가동한 후에는 이 데이타 화일로 구성된 테이블 스페이스도 지워주어야 한다.
1>connect internal
2>startup mount
3>alter database datafile '/oracle/data/user1.dbf' offline drop
4>drop tablespace 테이블스페이스명 including contents;
 
ORA-1547 Tablesapce에서 Free Space 부족시
 
***ORA-1547(Failed to allocate extent of sizes% in tablespace ‘USERS’)
 
***발생원인
1. table이 요구하는 next extent의 크기가 tablespace의 freespace를 초과할때.
2. index생성시 rollback segment나 sort area로 쓰이는 temporay tablespace부족할때
3. SQL*Forms30등을 사용할때, 관련 table을 포함하고 있는 Tool tablespace부족할때 발생한다.
 
***해결방법
 
1. 다음 스크립트을 이용해 테이블 스페이스별 프리영역을 체크한다.
 
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;
 
->FREE영역의 사용율을 보고 사용되는 FREE SPACE를 볼수 있다.
 
2. 해당 테이블 스페이스가 사용하는 SEGMENT를 DBA_SEGMENTS를 이용해 조사하여 불필요하게 혹은 TEMP성으로 생성된 테이블을 DROP한다.
 
3. 해당 tablespace의 datafile size를 늘려준다
-> alter database datafile ‘users01’ resize 10m;
-> alter tablespace add datafile ‘users02’ to TBLSPACE;
 
4. table의 next를 check 후 지나치게 큰 next size 조정한다
-> alter table AAA storage ( next 2m);
 
5. export/Import로 fragmenation을 정리한다.
 
ORA-00604 error occurred at recursive SQL level %s
 
// *Cause: An error occurred while processing a recursive SQL statement
// (a statement applying to internal dictionary tables).
// *Action: If the situation described in the next error on the stack
// can be corrected, do so; otherwise contact Oracle Support
 
이 에러는 내부적으로 SQL명령이 실행될 때 발생한다. 예를 들어 현재 할당된 익스텐트가 가득 차서
다음 익스텐트를 할당 받으려고 할 때 오라클이 다음 익스텐트의 크기와 위치를 결정하기 위하여
SELECT명령을 내리게 되는 것과 같은 경우이다.
 
이 문제가 발생하 우선 alert.log 화일을 검사하여 ORA-600 과 같은 에러가 발생했는가를 확인한다. ORA-600 에러가 발생했다면 오라클측에 지원을 요청하도록 하고 그렇지 않다면 다른 원인을 검사해 봐야 한다.
 
가장 먼저 고려할 사항은 ?/dbs/init.ora 화일에 지정된 open_cursors 의 크기를 알아보는 것이다.
이 값이 설정이 안되어 있으면 Default가 50이므로
open_cursors=255
----------------
와 같이 설정하도록 한다. 이 값은 단지 커서의 최대 값을 지정하는 것이므로 커서를 적게 쓰는 프로그램에 아무런 영향을 끼치지 않는다. open_cursors를 변경하고 DB를 Shutdown 하고 Startup 시키면 된다.
 
* Cursor란 무엇인가?
Cursor는 SQL문장을 실행하기위해 DATABASE가 사용하는 Memory의 영역을 말한다.
DATABASE에서 갖는 Open_Cursor의 Default값은 50이다.
Maximum값은 User가 사용하는 System 에 따라 결정된다.
User의 환경에 따라 Open_Cursor의 적정값을 설정할 필요 있다.
 
만약 이 방법으로 해결이 안되면 다음의 방법을 따른다.
정확한 에러의 원인을 찾기 위해서 init.ora 화일에 다음과 같은 라인을 추가한다.
events = "604 trace name errorstack"
 
이렇게 init.ora를 변경하고 DB를 Shutdown 하고 Startup 하면 ORA-604 에러가 발생하는 경우에 자세한 정보를 Trace 화일에 기록해 주므로 이 화일을 검사하여 에러의 원인을 찾을 수 있다.
 
에러의 다른 원인으로는 init.ora 화일의 파라미터 가운데 DC_FREE_EXTENTS 나 ROW_CACHE_ENQUEUES 의 값이 너무 작게 설정된 경우를 생각해 볼 수 있다.
이와같은 경우는 이들 값을 크게 설정해 주도록 한다.
 
테이블 스페이스가 가득 차거나 Extent 갯수의 최대 허용값을 초과해서 에러가 발생하는 경우 ORA-604 에러가 함께 발생할 수가 있는데 이와같은 경우에는 이들 문제를 먼저 해결하면 ORA-604 에러는 함께 해결 된다.
 
**참조:ORACLE BULLETIN NOTES
 
ORA-12154: TNS:서비스명를 해석할 수 없습니다.
 
oracle 홈아래 networkadmin의 tnsnames.ora file에서 설정한 alias를 해석못한다는 의미입니다.
아마도 tnsnames.ora file에서 설정한 host나 db sid등이 맞는지 확인 해 조세요,,,
 
< 예제 : TNSNAMES.ORA >
NT_SRV.world =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS =
(COMMUNITY = NTCommun.world)
(PROTOCOL = TCP)
(Host = 127.1.1.10)
(Port = 1521)
)
)
(CONNECT_DATA = (SID = ORCL)
)
)
 
ORA-01658: unable to create INITIAL extent for segment in tablespace WEBDB01
 
ORA 01658 ERROR는 다음과 같은 경우에 발생합니다.
* DML 수행시
* OBJECT 생성시
* Forms, Reports, CDE TOOL 수행시
* application. 수행시
 
ct40:/user4/guest/sdh/sql> oerr ora 01658
01658, 00000, "unable to create INITIAL extent for segment in tablespace %s"
// *Cause: Failed to find sufficient contiguous space to allocate INITIAL
// extent for segment being created.
// *Action: Use ALTER TABLESPACE ADD DATAFILE to add additional space to the
// tablespace or retry with a smaller value for INITIAL

오라클에서 EXTENT를 ALLLOCATE할려구 할시.. 충분한 여유공간이 없어서 생기는 에러입니다..
그럼 원인은
1. WEBDB01에 층분한 여유공간이 없다.
2. INITIAL EXTENT의 크기가 지나치게 크게 잡혔다.
 
CASE1 :
다음 스크립트로 먼저 FREESPACE를 CHECK하시면 FREE영역이 거의 없음을 확인 할수 있을 겁니다..
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
TABLESPACE_NAME                 Total(Mb)   Used(Mb)   Free(Mb)    Used(%)
------------------------------ ---------- ---------- ---------- ----------
BRS1_CODE                               4          1          3         25
D2K_D1                               2000       1232        768         62
D2K_D2                               2000       1418        582         71
..............................................
WEBDB01에 여유분의 데이타 화일을 추가시키시거나, 불필요하게 그 테이블스페이스를 점유하고
있는 OBJECT를 정리합니다.
CASE2:
   select SEGMENT_NAME, SEGMENT_TYPE, INITIAL_EXTENT, NEXT_EXTENT
   where TABLESPACE_NAME ='WEBDB01'
   and    SEGMENT_NAME= 'AAA '
로 INITIAL_EXTENT의 크기를 확인해 크게 잡혔다면 작게 사이즈를 조정합니다.
 
ORA-20003 - The object that you specified is invalid and cannot be described.
 
1. 호출하고 있는 프로시져의 권한이 있는지, VALID 한지 확인 합니다.
 
** PROCEDURE 의 INVALID
select count(*) from dba_objects
where status='INVALID';
 
select object_name,object_type,owner
from dba_objects
where status='INVALID';
 
 
OBJECT_NAME OBJECT_TYPE OWNER
----------- ----------- -----
CURSOR_TEST PROCEDURE SCOTT
 
-> INVALID 하다면 재 컴파일 합니다.

2. 프로시져가 실제로 존재하는지 확인합니다.
3. 포로시져 이름이나 파라미터를 확인합니다.
 
ora-00102 에러중에서 MTS_DISPATCHERS
 
발생윈인:
 
ORA-00101 에러는 MTS_DISPATCHERS 파라미터에 대한 잘못고니 SETTING 으로 발생합니다.
 
o You are installing 8.1.5 software and creating the default
database on NT (or Linux) and receive the ORA-0101 error.
 
00101, 00000, "invalid specification for system parameter mts_dispatchers"
// *Cause: The syntax for the "mts_dispatchers" parameter is incorrect.
// *Action: refer to the manual for correct syntax.
 
o You ignore this error and continue with the install and
immediately receive the ORA-0102 error.
 
00102, 00000, "network protocol %s cannot be used by dispatchers"
// *Cause: The network specified in "mts_dispatchers" doesn't have the
functionalities required by the dispatchers.
// *Action: refer to the manual on network protocols supported by the
dispatchers.
 
 
해결 방법:
 
Solution Description:
=====================
mts_dispatchers = "(PROTOCOL=TCP)(PRE=oracle.aurora.server.SGiopServer)"
# Uncomment the following line when your listener is configured for
# SSL
# (listener.ora and sqlnet.ora)
# mts_dispatchers =
# "(PROTOCOL=TCPS)(PRE=oracle.aurora.server.SGiopServer)"
 
mts_servers = 1
 
o After this you should be able to complete your install without
receiving these errors.
 
o A possible workaround may be to # out the parameters
mts_dispatchers and mts_servers.
 
00102 문제에서 log 파일에서 에러와 어떻게 풀어야 할지
## listener.ora
LISTENER =
(ADDRESS_LIST =
(ADDRESS= (PROTOCOL= TCP)(Host=192.168.1.1)(Port= 1521))
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = naun)
(ENVS = 'EPC_DISABLED = TRUE')
)
)
STARTUP_WAIT_TIME_LISTENER = 0
CONNECT_TIMEOUT_LISTENER = 10
TRACE_LEVEL_LISTENER = OFF
 
## tnsnames.ora
linux.world =
(DESCRIPTION =
(ADDRESS = (PROTOCOL=TCP) (host= 192.168.1.1)(port= 1521))
(CONNECT_DATA =
(SID = naun))
)
 
이와같이 고치시고 리스너 다시 START후 실행해보세요
 
ORA-12571: TNS:packet writer failure 에러
 
LISTENER.ORA and TNSNAMES.ORA,의 IP와 host명을 확인해 보세여
 
또한
SQLNET.ORA 의 다음 entry를 Client, 서버단에서 모두 제거 하세요..
SQLNET.EXPIRE_TIME=0

정렬된 상태에서
oracle : select * from test where id > 0 and rownum <=5
mysql : select * from test order by id limit 5
똑같은 결과 나오죠?

이번에는 원하는 위치잘라내기
oracle : select id , name from (select rownum as rnum, id, name)
        from test where id >0 ) where rnum >5 and rownum <=3
mysql : select * from test order by id limit 5, 3
똑같은 결과 나오죠?

그럼 역정렬을 한다면?
mysql : select * from test order by id desc;
oracle : select * from test order by id desc; (이걸 인덱스로 구현..)
select /*+ index_desc(test id_pk) id, name from test where thid>0

그럼 이것을 다 합한다면..
mysql : select * from test order by id desc limit 5, 3
oracle : 위에꺼 그대로 따라서 조합해보시죠..
1 2 3 

카테고리

분류 전체보기 (46)
Technic (5)
Language (16)
Database (8)
Oracle (7)
System (5)
Algorithm (1)
Design (1)
Tool (3)
Framework (2)
Network (1)
Utility (1)
SmartPhone (2)

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

달력

«   2025/08   »
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

글 보관함