Apollo89.com - 아폴로89의 이야기 ^o^/ -
| List | About | Tag | Location | Guest | | Navigation |
2008/07 에 해당하는 글10 개
2008년 07월 31일   오라클 쿼리 로그 뷰
2008년 07월 25일   rsync 하기
2008년 07월 25일   Rsync를 사용한 데이타 백업
2008년 07월 22일   INDEX 사용현황 확인 하는 방법
2008년 07월 22일   Oracle 10g에서 사용하는 기타 monitoring SQL들
2008년 07월 22일   ajax 관련 링크
2008년 07월 10일   보고 웃다가 기절하는줄 알았음..ㅋ
2008년 07월 07일   PostgreSQL 8.3.3 리눅스 설치..
2008년 07월 02일   properties 파일에서 한글사용..
2008년 07월 01일   Ruby on Rails 설치...


오라클 쿼리 로그 뷰
Dev | 2008년 07월 31일 08시 15분
select * from v$sql

select * from v$sqltext

select * from v$sqlarea


select * from v$sql
 where parsing_schema_name = 'ICSUSER'
   and last_active_time > TO_DATE('2007/07/31 08:50','RRRR/MM/DD HH:MI' )
   and last_active_time < TO_DATE('2007/07/31 08:11','RRRR/MM/DD HH:MI' )
 order by last_active_time desc ;

Trackback0 | Comment0
Trackback Address : http://apollo89.com/blog/trackback/237

Name :
Password :
Homepage :
  Secret
Comment :
 

rsync 하기
Dev | 2008년 07월 25일 18시 30분
보통 rsync는 원격지의 파일을 현재 로컬 내 PC로 땡겨오는대 주로 많이 쓰입니다.
rsync의 작동원리는 정확히 모릅니다.
하지만 rsync를 알게되고 부터는 원격지에서 서버의
데이터를 백업받을 때 사용하고 있습니다.

실제 서비스되고 있는 NewAL.NET 서버와 가상의 경우를 예로 들어봅시다.
NewAL.NET 서버는 IDC 구석에 꼴아박혀 불쌍하게도 나홀로 24시간 돌고 있습니다.

/home 디렉토리에는 여러 계정이 있고,
그 계정들은 계속 파일들이 갱신되거나 추가, 혹은 삭제되곤 합니다.
만약 /home 디렉토리에 대해 백업을 해야한다고 합시다.
가장 좋은건 NewAL.NET 서버에 /home 디렉토리를 통째로 압축해서
/root 안에 둔다거나할 수 있겠죠.

하지만 하드가 맛이 갔다면? 이런 쒯입니다.
기껏 백업받은게 전혀 필요가 없게됐죠.

하지만 전 ein1.com 이라는 백업서버를 두고 NewAL.NET의 모든 자료를 백업받고 있습니다.
NewAL.NET 서버는 페도라6 / ein1.com은 CentOS 6 입니다.

즉, NewAL.NET 서버가 폭파해도 ein1.com에 백업받은 데이터는 살아있게 되는 것이죠.
이것을 서버관리자가 생각날 때 마다 일일이 /home 압축해서 ein1.com에 업로드하고
이런 젠장 너무 짜증납니다. 용량도 지랄 맞습니다.. (전 무려 38GB나 되네요..)

이런 경우가 발생했을 때, 가장 쉽고 빠르게 대처할 수 있는 것이 바로 rsync 입니다.

이제부터 rsync를 통한 백업에 대해 설명해 보고자 합니다. 기억해 둡시다.
ein1.com은 백업서버, NewAL.NET은 실제 서비스 되는 서버입니다.

ein1.com / NewAL.NET 서버에 rsync를 설치합니다.
일단 ein1.com / NewAL.NET 둘다 rsync가 설치되어 있어야합니다.

# rsync 패키지 설치여부 확인
[root@newal ~]# rpm -qa |grep rsync
rsync-2.6.9-2.fc6
[root@newal ~]#

#만약 rsync가 안나온다면 yum을 이용해 설치합니다.
[root@newal ~]# yum -y install rsync openssh*
-y 옵션은 무조건 yum 실행 후 나오는 선택문 (y,n) 에서 무조건 yes한다는 뜻입니다.


두대의 서버에 모두 rsync를 설치했다면 이제 SSH 설정을 해야합니다.
ein1.com 서버에서는 rsync를 통해 NewAL.NET 서버에 접근하여 /home 디렉토리를 그대로 땡겨와야 합니다.
즉, ein1.com 서버가 => NewAL.NET 서버로 접속한다는 뜻이죠.

하지만, ein1.com 서버와 NewAL.NET 서버는 서로 신뢰하는 서버가 아닙니다.
즉, 두 서버는 완전히 다른 서버라는 뜻이고 서로 경계하고 있다고 봐야합니다.
아무것도 없이 ein1.com 서버가 NewAL.NET 서버에가서..

'야 거기 NewAL.NET. 나 ein1.com 인데 니 /home 디렉토리 아래 있는 모든파일 내놔'

이게 과연 될까요? 전혀 불가능한 예깁니다. 미쳤다고 누가 줍니까.. -_-
이것이 가능하기 위해서는 무언가 두 서버간에 서로 약속된 키(열쇠)가 있어야합니다.
그래야만 열쇠로 문을열고 서로의 서버 안으로 접근할 수 있게 되겠죠.

그 열쇠가 바로 SSH 키입니다.

이제 이 SSH 키를 생성해야 합니다.

자 그럼 키는 누가 만들어야하는가..
ein1.com => NewAL.NET 이렇게 접속해야합니다.
그러니 키를 NewAL.NET이 만들어서 ein1.com 한테 줘야하나요?
그렇게 생각하셨겠지만 틀렸습니다. 이는 보안 문제가 엄청 심각해집니다.
즉 키하나 유출되면 서버가 끝장이죠..

그로인해 ein1.com이 키를 만들어 NewAL.NET에 심어두는 거죠..
이렇게되면 NewAL.NET은 ein1.com에서 생성한 키가 내 PC에 있는지 확인하고 있다면 ein1.com의 접근을 허락하게 됩니다.


# ein1.com에서의 SSH 키 생성
[root@ein1 ~]# ssh-keygen -d
Generating public/private dsa key pair.
Enter file in which to save the key (/root/.ssh/id_dsa): [엔터]
Enter passphrase (empty for no passphrase): [엔터]
Enter same passphrase again: [엔터]
Your identification has been saved in /root/.ssh/id_dsa.
Your public key has been saved in /root/.ssh/id_dsa.pub.
The key fingerprint is:
.................................................................. root@ein1.com
[root@ein1~]#

마지막 줄은 보안상 ....... 처리했습니다.


Enter passphrase (empty for no passphrase): [엔터]
이부분에에 비밀번호를 입력할 수 있습니다.
하지만 비밀번호 없이 rsync를 바로 땡겨쓰기 위해서는 엔터 공란으로 가야합니다.



# 공용키 /root/.ssh/id_dsa.pub 파일을 NewAL.NET 서버에 올려야합니다.
우선 NewAL.NET 서버에 .ssh 폴더를 생성합니다.
ssh-keygen을 실행하여 키를 생성하면 .ssh 폴더가 자동 생성되지만 한번도 안해봤다면 수동으로 생성합니다. 퍼미션은 아무도 접근못하게 700으로 줘야합니다.

[root@newal ~]# cd ~
[root@newal ~]# mkdir .ssh
[root@newal ~]# chmod 700 .ssh


이제 ein1.com 서버에서 아래 명령을  실행합니다.

NewAL.NET 서버의 root 계정의 비밀번호를 입력하면 NewAL.NET 서버의 위에 생성한 /root/.ssh/ 디렉토리 아래 authorized_keys2 파일을 생성하게 됩니다.

이렇게 함으로써 이젠 ein1.com 서버가 NewAL.NET 서버에 아무런 제약 없이 바로 키를 가지고 내부로 접근할 수 있게 됩니다.


이제 모든게 끝났습니다.

ein1.com에 /backup 디렉토리를 만들고 아래 명령을 실행하여 NewAL.NET의 /home 디렉토리를 땡겨와 봅시다.

# rsync를 통해 NewAL.NET 서버의 /home 디렉토리 전체를 땡겨옵니다.
# mkdir /backup
# rsync -avzP -e ssh 222.237.78.65:/home/ /backup/



이로써 ein1.com 서버의 /backup 디렉토리에는 NewAL.NET의 /home 디렉토리 아래 모든 하위 디렉토리 포함 파일을 퍼미션 정보와 함께 그대로 땡겨와서 저장하게 됩니다.

처음 실행 시에는 조금 시간이 오래 걸립니다.
하지만, 처음 실행 이후에는 rsync의 최대 장점인 변경된 파일에 대해서만 땡겨오게 됩니다.
그로인해 NewAL.NET의 /home 디렉토리와 ein1.com의 /backup 디렉토리를 서로 동기화가 되는 것이죠.


이제 이놈을 Cron(크론)에 올려놓으면 금상첨화겠네요.

# touch /etc/cron.daily/rsync
# vi /etc/cron.daily/rsync

========================= // rsync 파일 내용은 아래와 같이 하고 저장합니다.

#!/bin/sh
rsync -avzP -e ssh 222.237.78.65:/backup/ /backup/


페도라의 경우 cronttab에 /etc/cron.daily 디렉토리 안에 있는 모든 파일이 매일 실행됩니다.

/etc/cronttab 파일을 열어보면 아래와 같이 되어 있을 겁니다.
02 4 * * * root run-parts /etc/cron.daily

출처는 http://newal.net/tag/rsync 입니다.

[출처] rsync 하기|작성자 맥스


Trackback0 | Comment0
Trackback Address : http://apollo89.com/blog/trackback/236

Name :
Password :
Homepage :
  Secret
Comment :
 

Rsync를 사용한 데이타 백업
Dev | 2008년 07월 25일 18시 23분

http://samba.org/rsync/

http://www.wangsy.com/linux/rsync/

 

1. Rsync란?

 

Network을 통해서 데이터 백업을 하는 툴이다. 기존 RCP를 보완하고, 현재 SCP(SSH)를 통해서 보안을 유지할 수 있다.

command는 웹 서버의 부하를 분산하기 위해서 remote sync(copy)를 하기 위한 용도로 개발되었다.

 

 

l        RSYNC Memory 사용 비율

File당 100byte의 메모리가 소요된다. 파일 사이즈에 상관없이 파일 수에 의존하며

1000,000 files이 있을 경우 100Mbyte의 메모리가 소요된다. 또한 option에 따라서 메모리가 더 소요될 수 있다.

l        서비스 설정의 기본
1. 서비스 포트: 873
2. 내부 사용 Shell  (RSH,SSH) 초기 configuration에서 선택 적용할 수 있다.
   현재 Default로 Remote shell은 SSH를 적용하고 있다.
3. /etc/rsyncd.conf, 각종 rsync option을 설정해 주는 부분이다.

l        RSYNC에서 사용되는 Algorithm의 구성
1. Rolling Checksum (16-bit hash of the 32-bit rolling checksum)
2. Checksum searching 은 3단계에 나누어서 데이터를 비교한다.

l        RSYNC 란 무엇인가?
rsync Algorithm을 사용해서 원격지 파일을 가장 빠른 방법으로 가져오게 된다.
단순히 건너편 원격지의 파일 차이점만을 보내는 것에 의해 운영이 된다.
전체 파일정보를 가져와서 처리하는 것이 없이 진행 된다. 이것은 언뜻 보기에 두개의 파일을 local access하는 것 없이 파일 비교를 한다는 것이 이해가 안될지 모르지만
rsync Algorithm을 확인하면 이것이 가능하다는 것을 알 수 있다.

l        RSYNC Server 취약성 점검
1. netstat를 사용해서 현재 TCP port 873을 점검한다. 아무런 값이 없다면 rsync server가 동작하지 않는 것이다.

 

 

 

 

 

2. Rsync Algorithm

알파서버 그리고 베타서버가 있다고 가정한다. 알파서버는 파일 A에 access하고 베타서버는 파일 B에 access한다. 그리고 그 파일 두개는 similar하다. 두 서버사이는 느린 네트워크로 연결되어 있다. (느린 네트워크에서 동작한다는 가정 하에 진행)

Checksum만을 가지고서 변경된 블록과 동일한 블록에 대한 reference만을 전송하는 것으로 네트워크 속도가 느린 환경에서 변경된 데이터의 빠른 복사가 가능하게 된다.

 

The rsync algorithm consists of the following steps:

1)      베타 서버가 S bytes의 overlapping되지 않은 고정된 블록사이즈에 연속으로 file B를 분할한다. (S bytes는 500~1000사이의 가장 최적의 상태)

2)      베타 서버에서는 이들 블록을 두개의 checksum으로 계산한다. Rolling 32-bit checksum, strong 128-bit MD4 checksum으로 계산한다.

3)      베타 서버가 알파서버에게 이들 checksum값을 전송한다.

4)      알파서버는 B블록의 하나를 가지고서 동일한 weak checksum과 strong checksum을 가진 S bytes 길이의 모든 블록을 파일 A에서 찾는다.
이것은 rolling checksum의 특수한 성질을 이용해서 가장 빠른 single pass로 진행된다.

5)      알파서버는 베타에게 A파일 copy를 구성하기위한 instruction을 보낸다. 각각의 instruction은 B의 블록 reference또는 문자데이타이다. 문자데이터는 B블록과 일치하지 않는 A의 부분들로 전송된다. (전송될 때는 checksum과 Block index들을 위한 작은 양의 데이터를 포함한다).

 

결과적으로 베타서버는 A를 복사해서 가지게 된다. 이것은 B에서 발견되지 않은 A의 부분들에 한정해서다. 그리고 이 Algorithm은 네트워크 부하를 최소화하기 위해서 단지 한번의 round trip만을 사용해서 전송한다.

 

참고)

파일의 변경부분만을 가지고서 변경 블록만을 전송하는 방식이 실제 데이터의 consistency를 보장하지는 못한다. 변경된 파일이 있을 경우 이 파일을 전체 전송하는 방식이 아니기 때문에 전송 중에 네트워크 장애로 인한 또는 Checksum 에러로 인한 파일 데이터의 consistency를 보장할 수 없다.

 

 

 

 

 

2.1 RSYNC Algorithm Picture1.

전제: 두개 파일 A와 B는 유사하다.









TITLE:

 

                           HOW TO USE RSYNC

 

 

CONTENTS:

 

http://samba.org/ftp/rsync/rsync-2.6.0.tar.gz

 

[root@quest root]# tar -xvzf rsync-2.6.0.tar.gz

[root@quest rsync-2.6.0]# ./configure

[root@quest rsync-2.6.0]# make

[root@quest rsync-2.6.0]# make install

mkdir -p /usr/local/bin

/usr/bin/install -c  -m 755 rsync /usr/local/bin

mkdir -p /usr/local/man/man1

mkdir -p /usr/local/man/man5

/usr/bin/install -c -m 644 ./rsync.1 /usr/local/man/man1

/usr/bin/install -c -m 644 ./rsyncd.conf.5 /usr/local/man/man5

[root@quest rsync-2.6.0]#

 

 

[acl지원되는 최신 버전]

rsync-2.5.6.tar.gz

rsync-2.5.6-acl-2.diff.gz

 

 

[NOTE]

rsync-2.6.0은 default로 ssh를 사용한다. 기존의 rcp를 사용하기 위해서는 configuration

을 재구성해야 한다.

    **********************************************************************

    *   As of v2.6.0, the default remote shell is ssh instead of rsh!!   *

    *   To use previous default of rsh:   ./configure --with-rsh=rsh     *

    **********************************************************************

 

    rsync 2.6.0 configuration successful

[Installation]

현재 테스트는 rpm버전으로 진행을 했다.

rpm버전은 다음과 같다.

[root@quest data]# rpm -qa rsync

rsync-2.5.5-4

[root@quest data]# rpm -ql rsync

/etc/xinetd.d/rsync

/usr/bin/rsync

/usr/share/doc/rsync-2.5.5

/usr/share/doc/rsync-2.5.5/COPYING

/usr/share/doc/rsync-2.5.5/README

/usr/share/doc/rsync-2.5.5/tech_report.tex

/usr/share/man/man1/rsync.1.gz

/usr/share/man/man5/rsyncd.conf.5.gz

 

 

모든 설정은 백업할 서버와 백업대상 서버가 동일하다.

백업서버: BS -- backup server

백업소스서버: SU -- Source server(백업할 데이타가 있는 서버)

 

1. rsync

/etc/xinetd.d/rsync

disable = yes를 no로 바꾼다.

# default: off

# description: The rsync server is a good addition to an ftp server, as it \

#       allows crc checksumming etc.

service rsync

{

        disable = no

        socket_type     = stream

        wait            = no

        user            = root

        server          = /usr/bin/rsync

        server_args     = --daemon

        log_on_failure  += USERID

}

 

2. /etc/services

rsync의 port를 추가한다.

rsync           873/tcp                         # rsync

rsync           873/udp                         # rsync

 

3. host.allow

/etc/hosts.allow 를 설정한다.

BS(backup server)가 각각 백업할 데이터가 있는 서버(SU)에 접근할 수 있도록

SU서버에서 host.allow에 BS의 IP를 넣어 준다.

 

rsyncd : 1.2.3.182, local

 

4. xinetd의 재시작.

/etc/rc.d/init.d/xinetd restart

 

 

5. rsyncd.conf 파일의 생성.

백업소스가 있는 서버(SU)에서 /etc/rsyncd.conf를 생성한다.

내용은 /home/backup/data밑에 있는 곳을 원본 소스로 지정한다는 내용이다.

접근은 read only로 되어 있다 왜냐하면 파일이 read만 될 것이기 때문이다.

timeout은 접속되어 있는 시간을 말하는데 시간이 너무작게 되어 있을 경우에

전송이 timeout error가 발생할 수도 있다.

max connections은 연결하는 동시 접속 숫자이다.

 

[quest]

path = /home/backup/data

comment = Source-Server

uid = nobody

gid = nobody

use chroot = yes

read only = yes

hosts allow = 1.2.3.182

max connections = 2

timeout 600

 

6. 실행.

실행은 BS(백업서버)에서 실행하게 된다.

옵션에서

-a는 achive mode로 기존 속성이 넘어간다는 이야기이다.

-v는 verbose mode로서 작업내용을 상세하게 보여준다.

-z는 전송속도를 높이기 위해 압축수행 후 전송을 한다는 이야기 이다.

설정자료에 보면 압축을 할 경우 파일 사이즈가 크면 전송이 잘 안될 수도 있다

이럴 경우에는 z 옵션을 제거한다.

-r는 --recursive

This tells rsync to copy directories recursively. If you don't

specify this then rsync won't copy directories at all.

 

 

rsync -avz 1.2.3.184::quest/ /home/backup/data

rsync -avz foo:src/bar /data/tmp

rsync -avz foo:src/bar/ /data/tmp

rsync -Cavz . arvidsjaur:backup

 

  

SUB TITLE:

 

                           HOW TO MAKE rsyncd.conf

 

 

CONTENTS:

 

EXAMPLE1)

A simple rsyncd.conf file that allow anonymous rsync to a ftp area at /home/ftp would be:

 

[ftp]

        path = /home/ftp

        comment = ftp export area

 

A more sophisticated example would be:

 

uid = nobody

gid = nobody

use chroot = no

max connections = 4

syslog facility = local5

pid file = /var/run/rsyncd.pid

 

[ftp]

        path = /var/ftp/pub

        comment = whole ftp area (approx 6.1 GB)

 

[sambaftp]

        path = /var/ftp/pub/samba

        comment = Samba ftp area (approx 300 MB)

 

[rsyncftp]

        path = /var/ftp/pub/rsync

        comment = rsync ftp area (approx 6 MB)

       

[sambawww]

        path = /public_html/samba

        comment = Samba WWW pages (approx 240 MB)

 

[cvs]

        path = /data/cvs

        comment = CVS repository (requires authentication)

        auth users = tridge, susan

        secrets file = /etc/rsyncd.secrets

 

 

The /etc/rsyncd.secrets file would look something like this:

 

tridge:mypass

susan:herpass

 

EXAMPLE2)

The contents of a /etc/rsyncd.conf file may be:

 

#### rsyncd.conf file ####

uid = username

gid = usergid

pid file = /etc/rsyncd.pid

syslog facility = daemon

 

[modulename]  #Module name could be any name

path = /path/to/yourdata

comment = user related any info

auth users = anonymous username

hosts allow = x.x.x.x

secrets file =/etc/rsyncd.secrets

max connection = 0

use chroot = true

timeout = 60

#### End of configuration file ####

 

 

EXAMPLE3)

[dell]

path = /home/backup/data

comment = Source-Server

uid = nobody

gid = nobody

use chroot = yes

read only = yes

hosts allow = 1.2.3.182

max connections = 2

timeout 600

 

 

 

If you have a problem with scripts or cron jobs that produce stderr

then I suggest you use your shell to redirect stderr and stdout.

For example you could do a cron line like this:

 

 

0 0 * * * /usr/local/bin/rsync -avz /foobar /foo > logfile 2>&1

 

this would send both stderr and stdout to "logfile".

The magic bit is the "2>&1" which says to redirect stderr to

to the same descriptor to which stdout is currently directed.

   

 

 

rsync는 전체 OS를 다 지원한다고 보면 됩니다.

아래의 binaries사이트는 실제 rsync 바이너리 파일입니다.

바이너리가 맞지 않을 경우에는 rsync source가 제공되므로 각 OS에서 컴파일 해서

사용하는 것이 좋을 것 같습니다.

 

그렇다면 O/S에 컴파일러가 없는지 있는지도 확인을 해야 할 것 같습니다.

 

 http://samba.org/ftp/rsync/binaries/
Index of /ftp/rsync/binaries

 

 

HP-UX NOTES
-----------

The HP-UX 10.10 "bundled" C compiler seems not to be able to cope with
ANSI C.  You may see this error message in config.log if ./configure
fails:

  (Bundled) cc: "configure", line 2162: error 1705: Function prototypes are an ANSI feature.

Install gcc or HP's "ANSI/C Compiler".

 

MAC OSX NOTES
-------------

Mac OS X (Darwin) seems to have an IPv6 stack, but it does not
completely implement the "New Sockets" API. 

<http://www.ipv6.org/impl/mac.html> says that Apple do not support
IPv6 yet.  If your build fails, try again with --disable-ipv6.

 

IBM AIX NOTES
-------------

IBM AIX has a largefile problem with mkstemp.  See IBM PR-51921.
The workaround is to append the below to config.h
 #ifdef _LARGE_FILES
 #undef HAVE_SECURE_MKSTEMP
 #endif

 

 

 

[참고]

http://samba.org/rsync/FAQ.html

 

memory usage

yes, rsync uses a lot of memory. The majority of the memory is used to hole the list of files being transferred. This takes about 100 bytes per file, so if you are transferring 800,000 files then rsync will consume about 80M of memory. It will be higher if you use -H or --delete. To fix this requires a major rewrite of rsync. I do plan on doing that, but I don't know when I'll get to it.

out of memory

 The usual reason for "out of memory" when running rsync is that you are transferring a _very_ large number of files. The size of the files doesn't matter, only the total number of files. As a rule of thumb you should expect rsync to consume about 100 bytes per file in the file list. This happens because rsync builds a internal file list structure containing all the vital details of each file. rsync needs to hold structure in memory because it is being constantly traversed. I do have a plan for how to rewrite rsync so that it consumes a fixed (small) amount of memory no matter how many files are transferred, but I haven't yet found a spare week of coding time to implement it! 
 

stderr & stdout

> Why does rsync produce some things on stdout and some on stderr?

All messages which originate from the remote computer are sent to stderr. All informational messages from the local computer are sent to stdout. All error messages from the local computer are sent to stderr.

There is a reason to this system, and it would be quite difficult to change. The reason is that rsync uses a remote shell for execution. The remote shell provides stderr/stdout. The stdout stream is used for the rsync protocol. Mixing error messages into this stdout stream would involve lots of extra overhead and complexity in the protocol because each message would need to be escaped, which means non-messages would need to be encoded in some way. Instead rsync always sends remote messages to stderr. This means they appear on stderr at the local computer. rsync can't intercept them.

If you have a problem with scripts or cron jobs that produce stderr then I suggest you use your shell to redirect stderr and stdout. For example you could do a cron line like this:

0 0 * * * /usr/local/bin/rsync -avz /foobar /foo > logfile 2>&1 

this would send both stderr and stdout to "logfile". The magic bit is the "2>&1" which says to redirect stderr to to the same descriptor to which stdout is currently directed.


Trackback0 | Comment0
Trackback Address : http://apollo89.com/blog/trackback/235

Name :
Password :
Homepage :
  Secret
Comment :
 

INDEX 사용현황 확인 하는 방법
Dev | 2008년 07월 22일 20시 15분

오라클에서 필요에 의해서 인덱스를 만들어 놓고 이후에 이 인덱스를 사용하는지 안하는지

알 수가 없어서 필요없는 인덱스에 의해서 사용되어지는 디스크 공간을 회수 하지 못하고 있는

경우가 많이 있다.


이 경우 인덱스 사용여부를 확인해서 사용하지 않는 인덱스의 경우 drop 하여

불필요한 디스크 공간을 줄여주는게 좋다.


Oracle 9i 부터 제공되는 Monitoring 기능에 대해서 간단하게 설명하고자 한다.


모니터링 하고자 하는 인덱스가 test_pk 라면


모니터링을 시작하기 위해서는 alter index test_pk monitoring usage;

모니터링을 중단하기 위해서는 alter index test_pk nomonitoring usage;


그리고 모니터링 결과를 확인하기위해서


select * from v$object_usage; 로 확인하면 된다.


하지만 v$object_usage 로 데이터가 없을 경우 sys.object_usage 를 조회하면 된다.


select o.owner, o.object_name, o.object_type, decode(bitand(u.flags, 1), 0, 'NO', 'YES'),

u.start_monitoring, u.end_monitoring from sys.object_usage u, all_objects o where

o.obj# = o.object_id;


여기서 decode(bitand(u.flags, 1), 0, 'NO', 'YES') 부분이 YES 이면 인덱스가 사용되는것이고

NO 상태로 계속 유지된다면 사용하지 않는 인덱스라고 보면 된다.


그리고 인덱스 모니터링 기간은 테이블에 따라서 조금 다르겠지만 일주일 정도 두고 보는게 좋다.

출처 : http://www.dbguide.net/dbqa/dbqa120001.jsp?mode=view&divcateno=243&divcateno_=243&pg=1&idx=879 


Trackback0 | Comment0
Trackback Address : http://apollo89.com/blog/trackback/234

Name :
Password :
Homepage :
  Secret
Comment :
 

Oracle 10g에서 사용하는 기타 monitoring SQL들
Dev | 2008년 07월 22일 20시 01분

----------------------------------------------------------------------
-- 10g의 statistics_level=typical이상이면 gathering됨.
-- but this view does not include undo block or undo header transfers
----------------------------------------------------------------------

select object_name, statistic_name, sum(value) waits from v$segment_Statistics
where statistic_name = 'buffer busy waits'
group by object_name, statistic_name
order by waits desc;

----------------------------------------------------------------------
-- 10g, transaction에 대한 rollback하고 있는 정보 보기
-- 함께 참조
-- select * from v$fast_start_servers;
-- SELECT message FROM v$session_longops;
select state, undoblocksdone, undoblockstotal, cputime
from v$fast_start_transactions;
----------------------------------------------------------------------

----------------------------------------------------------------------
-- 10g, global cache activity를 class별로 볼수 있음.
----------------------------------------------------------------------
select *
from v$instance_cache_transfer
where cr_busy > 0
order by instance, cr_busy desc;

----------------------------------------------------------------------
-- 10g, cluster wait 보기
-- 현재 수행중인 long running sql에대한 정보는 들어가지 않는다.
-- 끝난 sql의 정보만 들어간다.
----------------------------------------------------------------------
select substr(sql_text, 1, 100), cluster_wait_time wait_time_microsecond
from v$sql
where cluster_wait_time > 0
order by 2 desc;


----------------------------------------------------------------------
-- 10g, blocked session 과 blocking session 찾기
----------------------------------------------------------------------
select * from v$session;
select sid, blocking_session, event
from v$session
where blocking_session_status='VALID';

출처 : http://www.dbguide.net/dbqa/dbqa120001.jsp?mode=view&key=subject&search=10g&pg=2&idx=286 




-- 9i, 10g, PGA target Advsior 보기

-- estd_overalloc_count가 0인 가장 작은 target_MB가 적절한 PGA_target이 된다.

SELECT round(PGA_TARGET_FOR_ESTIMATE/1024/1024) target_mb,
       ESTD_PGA_CACHE_HIT_PERCENTAGE cache_hit_perc,
       ESTD_OVERALLOC_COUNT
FROM   v$pga_target_advice;


-- 10g, tablespace별 사용량 보기

select * from dba_tablespace_usage_metrics;


-- 10g, advisor 수행 task보기

select * from DBA_ADVISOR_TASKS
order by execution_end desc;


-- DB cache advisor 보기

SELECT size_for_estimate, buffers_for_estimate, estd_physical_read_factor, estd_physical_reads
   FROM V$DB_CACHE_ADVICE
   WHERE name          = 'DEFAULT'
     AND block_size    = (SELECT value FROM V$PARAMETER WHERE name = 'db_block_size')
     AND advice_status = 'ON';


-- 10g, Redo advisor 보기

-- Redo log advisor
-- init.ora에 Fast_start_mttr_target이 지정되어 있어야 한다.
select target_mttr, estimated_mttr, writes_mttr, optimal_logfile_size
from v$instance_recovery;


-- segment advisor 수행 흔적 보기

--
--
--AUTO_TASKID SNAPID      SEGMENTS_SE SEGMENTS_PR TABLESPACE_ TABLESPACE_ RECOMMENDAT STAR                       END_
------------- ----------- ----------- ----------- ----------- ----------- ----------- ----                       ----
--          1        2231           0           0           0           0           0 2006/03/01 15:02:25.773803
select * from DBA_AUTO_SEGADV_SUMMARY order by start_time desc;


-- 10g, segment advisor 수행 권고 보기

-- reclaimable_space (tablespace level로 확인 하기)
--
select tablespace_name, allocated_space, reclaimable_space,
       trunc(reclaimable_space/allocated_space,2)*100 reclaimable_pct
from   table(dbms_space.asa_recommendations('TRUE', 'TRUE', 'ALL'))
order by reclaimable_pct desc;


-- 10g, segment advisor 수행권고 보기 ( table별)

select trunc(reclaimable_space/allocated_space,2) reclaimable_pct,
--a.*
trunc(reclaimable_space/allocated_space,2) reclaim_raito,
Segment_owner,segment_name,Segment_type,Partition_name, Allocated_space,
Used_space,Reclaimable_space,Chain_rowexcess chian_ratio,substr(Recommendations,1,40) recommendations
--C1, C2, C3
from table (dbms_space.asa_recommendations()) a
order by trunc(reclaimable_space/allocated_space,2) desc,to_number(reclaimable_space) desc;


-- 10g, auto sga일경우, memory size 변동 결과 보기.

select * from V$SGA_RESIZE_OPS;


http://www.dbguide.net/dbqa/dbqa120001.jsp?mode=view&key=subject&search=10g&pg=2&idx=303 


Trackback0 | Comment0
Trackback Address : http://apollo89.com/blog/trackback/233

Name :
Password :
Homepage :
  Secret
Comment :
 

ajax 관련 링크
Dev | 2008년 07월 22일 11시 25분

개발자 커뮤니티
Sun
구글
One Week of Google Maps - Part 1, Part 2, Part 3, Part 4, Part 5, Part 6, Part 7
도조 Dojo
돔 DOM
브라우저 Browser
씨에스에스 CSS
애이작스 AJAX(XMLHttpRequest 포함)와 RIA
Ajax 강의 21회