블로그 이미지
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

공지사항

최근에 올라온 글

GETTING IP ADDRESS OF ORACLE CLIENT 
=================================== 

PURPOSE 
------- 
Oracle의 SQL을 이용하여 
client host의 IP address를 알아내는 방법을 안내합니다. 

Explanation 
----------- 

Programmer 고객들로부터 가장 자주 문의되는 것 중에 하나가 
source code에서 client host의 IP address를 알아내는 것입니다. 

그런데, Oracle software에서는 Oracle Server 8.1.x, 
즉 Oracle Server 8i부터 가능합니다. 

Oracle 8까지는 Oracle Server나 Net8를 통하여 
IP를 알아내는 것이 불가능하기 때문에 
Oracle 외적인 방법(Network programming)을 구하시는 등 
Oracle과 관련이 없는 방법을 찾아야 하였으나 
8i부터는 sys_context function으로 가능하여 졌습니다. 

SQL> select sys_context('USERENV', 'IP_ADDRESS') as ip from dual; 

sys_context function에 대한 모든 설명은 
각 Oracle Server Release 별 SQL Reference를 보시기 바라며 
여기서는 예를 들기위해 sample source code를 하나 작성하여 보았습니다. 

주의: 
sample source code는 고객의 편의를 위해 교육용 목적으로 작성된 것으로 
여기에 담겨진 개념을 실제 적용하고자 할 때 고객의 면밀한 검토가 필요하며 
sample source code의 관한 문의나 그 사용 등에 대해서는 
지원이 되지 않습니다. 


Example 
------- 

다음의 sample source code에 있는 trigger는 system user로 compile되며 
그 후 각 user가 database에 logon/logoff할 때 
특정 directory/file에 시각, client IP, oracle username, logon/off를 
기록하여 줍니다. 

prompt$ su - [oracle user] 
prompt$ vi $ORACLE_HOME/dbs/init$ORACLE_SID.ora 
또는 
prompt$ vi $ORACLE_BASE/admin/$ORACLE_SID/pfile/init$ORACLE_SID.ora 
... 
# utl_file_dir parameter에 Oracle server가 write permission이 있는 
directory를 설정 
utl_file_dir=/tmp 
:wq 
# instance를 restart 
prompt$ svrmgrl 
SVRMGR> connect internal 
SVRMGR> shutdown 
SVRMGR> startup 
SVRMGR> exit 
# trigger 작성 
prompt$ cd $HOME 
prompt$ vi logonoff_trig.sql 
create or replace trigger logon_trigger after logon on database 
declare 
hFile utl_file.file_type; 
begin 
hFile := utl_file.fopen('/tmp', 'connection.log', 'a'); 
utl_file.putf(hFile, '%s %s %s LOGON', to_char(sysdate, 'YYYY-MM-DD HH24:MI:SS'), sys_context('USERENV', 'IP_ADDRESS'), sys_context('USERENV', 'SESSION_USER')); 
utl_file.fclose(hFile); 
exception 
when others then 
if utl_file.is_open(hFile) then 
utl_file.fclose(hFile); 
end if; 
end; 

show errors 

create or replace trigger logout_trigger before logoff on database 
declare 
hFile utl_file.file_type; 
begin 
hFile := utl_file.fopen('/tmp', 'connection.log', 'a'); 
utl_file.putf(hFile, '%s %s %s LOGOFF', to_char(sysdate, 'YYYY-MM-DD HH24:MI:SS'), sys_context('USERENV', 'IP_ADDRESS'), sys_context('USERENV', 'SESSION_USER')); 
utl_file.fclose(hFile); 
exception 
when others then 
if utl_file.is_open(hFile) then 
utl_file.fclose(hFile); 
end if; 
end; 

show errors 
:wq 
prompt$ sqlplus system/manager 
SQL> @logonoff_trig 
SQL> exit 
prompt$ sqlplus system/manager 
SQL> exit 
prompt$ sqlplus username/password 
SQL> exit 
prompt$ cat /tmp/connection.log 
2002-04-02 20:29:39 152.69.41.15 SYSTEM LOGOFF 
2002-04-02 20:29:58 152.69.41.15 SYSTEM LOGON 
2002-04-02 20:29:59 152.69.41.15 SYSTEM LOGOFF 
2002-04-02 20:29:58 152.69.41.15 USERNAME LOGON 
2002-04-02 20:29:59 152.69.41.15 USERNAME LOGOFF 


Reference Documents 
------------------- 
Oracle Server Documentation 
SQL Reference


Posted by redkite
, |

최근에 달린 댓글

최근에 받은 트랙백

글 보관함