본문 바로가기
PostgreS/PPAS

Dynamic Runtime Instrumentation Tools Architecture (DRITA) 설정

by 타마마임팩트_쫀 2014. 3. 14.

Dynamic Runtime Instrumentation Tools Architecture (DRITA) 설정

 

1. 초기 파라미터 설정

postgresql.conf 에 snapshot 설정을 위한 파라미터를 수정한다

timed_statistics = off    => 초기 설정 (default 값)

timed_statistics = on    => 설정 변경 후 DB 재기동 필요

 

2. 테이블 및 function 생성

DRITA를 사용하기 위해 테이블과 함수를 생성한다. 아래 스크립트를 수행하자.

snap_tables.sql
snap_functions.sql

 

3. 스냅샷 설정

SELECT * from edbsnap()

시간을 두고 다시 한번 스냅샷을 생성하자.

SELECT * from edbsnap()

 

4. 생성된 스냅샷 조회 

현재 생성된 스냅샷을 조회하자.

edb=# SELECT * FROM get_snaps();
          get_snaps          
------------------------------
1  11-FEB-10 10:41:05.668852
2  11-FEB-10 10:42:27.26154
3  11-FEB-10 10:45:48.999992
4  11-FEB-10 11:01:58.345163
5  11-FEB-10 11:05:14.092683
6  11-FEB-10 11:06:33.151002
7  11-FEB-10 11:11:16.405664
8  11-FEB-10 11:13:29.458405
9  11-FEB-10 11:23:57.595916
10 11-FEB-10 11:29:02.214014
11 11-FEB-10 11:31:44.244038

 

5. system wait 정보 조회

생성된 스냅샷으로 wait 정보를 확인하자.

edb=# SELECT * FROM sys_rpt(9, 10, 10);
                                   sys_rpt                                  
-----------------------------------------------------------------------------
WAIT NAME                                COUNT      WAIT TIME       % WAIT
---------------------------------------------------------------------------
wal write                                21250      104.723772      36.31
db file read                             121407     72.143274       25.01
wal flush                                84185      51.652495       17.91
wal file sync                            712        29.482206       10.22
infinitecache write                      84178      15.814444       5.48
db file write                            84177      14.447718       5.01
infinitecache read                       672        0.098691        0.03
db file extend                           190        0.040386        0.01
query plan                               52         0.024400        0.01
wal insert lock acquire                  4          0.000837        0.00

 

※ 함수 정보

    sys_rpt(beginning_id, ending_id, top_n)

Parameters :

beginning_id - 스냅샷의 시작 번호

ending_id    - 스냅샷의 종료 번호

top_n        - top 인벤트 개수

 

6. 세션 wait 정보 조회

SELECT * FROM sess_rpt(18, 19, 10);

                              sess_rpt                                      
-----------------------------------------------------------------------------
ID    USER       WAIT NAME              COUNT TIME(ms)   %WAIT SES  %WAIT ALL
----------------------------------------------------------------------------

17373 enterprise db file read           30   0.175713   85.24      85.24
17373 enterprise query plan             18   0.014930   7.24       7.24
17373 enterprise wal flush              6    0.004067   1.97       1.97
17373 enterprise wal write              1    0.004063   1.97       1.97
17373 enterprise wal file sync          1    0.003664   1.78       1.78
17373 enterprise infinitecache read     38   0.003076   1.49       1.49
17373 enterprise infinitecache write    5    0.000548   0.27       0.27
17373 enterprise db file extend         190  0.04.386   0.03       0.03
17373 enterprise db file write          5    0.000082   0.04       0.04
17373 enterprise wal write lock acquire 0    0.000000   0.00       0.00
17373 enterprise bgwriter comm lock ac  0    0.000000   0.00       0.00

 

※ 함수 정보

    sess_rpt(beginning_id, ending_id, top_n)

Parameters :

beginning_id - 스냅샷의 시작 번호

ending_id    - 스냅샷의 종료 번호

top_n        - top 인벤트 개수

 

 

7. 세션의 wait 이벤트 정보 조회

edb=# SELECT * FROM sesshist_rpt (9, 5531);
                              sesshist_rpt                                                  
----------------------------------------------------------------------------
ID    USER       SEQ  WAIT NAME               
   ELAPSED(ms)   File  Name                 # of Blk   Sum of Blks
----------------------------------------------------------------------------
5531 enterprise 1     db file read
   18546        14309  session_waits_pk     1          1          
5531 enterprise 2     infinitecache read      
   125          14309  session_waits_pk     1          1          
5531 enterprise 3     db file read            
   376          14304  edb$session_waits    0          1          
5531 enterprise 4     infinitecache read      
   166          14304  edb$session_waits    0          1          
5531 enterprise 5     db file read            
   7978         1260   pg_authid            0          1          
5531 enterprise 6     infinitecache read      
   154          1260   pg_authid            0          1          
5531 enterprise 7     db file read            
   628          14302  system_waits_pk      1          1          
5531 enterprise 8     infinitecache read      
   463          14302  system_waits_pk      1          1          
5531 enterprise 9     db file read            
   3446         14297  edb$system_waits     0          1          
5531 enterprise 10    infinitecache read      
   187          14297  edb$system_waits     0          1          
5531 enterprise 11    db file read            
   14750        14295  snap_pk              1          1          
5531 enterprise 12    infinitecache read      
   416          14295  snap_pk              1          1          
5531 enterprise 13    db file read            
   7139         14290  edb$snap             0          1          
5531 enterprise 14    infinitecache read      
   158          14290  edb$snap             0          1          
5531 enterprise 15    db file read            
   27287        14288  snapshot_num_seq     0          1          
5531 enterprise 16    infinitecache read      
   180          14288  snapshot_num_seq     0          1          
5531 enterprise 17    query plan              
   26           0      N/A                  0          0          
5531 enterprise 18    db file read            
   84552        16396  pgbench_accounts     4358       1          
5531 enterprise 19    infinitecache read      
   226          16396  pgbench_accounts     4358       1          
5531 enterprise 20    db file read            
   334838       16401  pgbench_accounts_pke 7792       1          
5531 enterprise 21    infinitecache read      
   213          16401  pgbench_accounts_pke 7792       1          
5531 enterprise 22    db file read            
   52619        16396  pgbench_accounts     24829      1          
5531 enterprise 23    infinitecache read      
   210          16396  pgbench_accounts     24829      1          
5531 enterprise 24    infinitecache read      
   216          16401  pgbench_accounts_pke 13460      1          
5531 enterprise 25    db file read            
   13925        16396  pgbench_accounts     27695      1

함수 파라미터는 거의 같으니 생략하자...

 

8. 스냅샷 삭제

불필요한 스냅샷은 공간 낭비를 초래하니 삭제하자.

SELECT * FROM purgesnap(6, 9);

             purgesnap             
------------------------------------
Snapshots in range 6 to 9 deleted.

 

 

9. 전체 스냅샷 삭제

SELECT * FROM truncsnap();

      truncsnap      
----------------------
Snapshots truncated.

 

10. 성능 리포트 출력

오라클의 statspack이나 AWR report와 비슷하게 출력되는 함수도 있다.

stat_db_rpt()

stat_tables_rpt()

statio_tables_rpt()

stat_indexes_rpt()

statio_indexes_rpt()

 

11. 더 자세한 성능 정보 출력

edbreport는 시스템 정보를 보함한 자세한 리포트를 출력한다.

edb=# SELECT * FROM edbreport(9, 10);
                                                                       edbreport                                                                      
----------------------------------------------------------------------------------------------------------------------------------------------------------
EnterpriseDB Report for database edb        11-FEB-10
Version: EnterpriseDB 8.4.0.1 on i686-pc-linux-gnu, compiled by GCC gcc (Ubuntu 4.3.2-1ubuntu12) 4.3.2, 32-bit

      Begin snapshot: 9 at 11-FEB-10 11:23:57.595916
      End snapshot:   10 at 11-FEB-10 11:29:02.214014

Size of database edb is 909 MB
      Tablespace: pg_default Size: 925 MB Owner: jeevan
      Tablespace: pg_global Size: 448 kB Owner: jeevan

Schema: public                         Size: 900 MB          Owner: jeevan             
Schema: pg_toast_temp_1                Size: 0 bytes         Owner: jeevan             

                Top 10 Relations by pages

TABLE                                        RELPAGES 
----------------------------------------------------------------------------
pgbench_accounts                              95282    
pg_proc                                       107      
pg_depend                                     71       
pg_attribute                                  48       
edb$statio_all_indexes                        47       

....중략...

 work_mem                           1795                                    
                                       user        64           2097151    
xmlbinary                          base64                                  
                                       user                                
xmloption                          content                                 
                                       user                                
zero_damaged_pages                 off                                     
                                       superuser                           
(402 rows)

엄청 길다. 궁금하면 직접 해보자!

 

12. 성능 튜닝

열심히 리포트를 뽑았다.

그럼 이제 뭘 어떻게 해야하지?

리포트를 분석해서 튜닝을 해야지!

Event type

Description

Checkpoint waits

체크포인트 매갸변수는 checkpoint_segments와 checkpoint_timeout 같이 조정 검토 필요 (checkpoint_segments = default 값은 3개, checkpoint_timeout = default 값은 5분)

WAL-related waits

wal_buffers 사이즈가 너무 작다.

SQL Parse waits

높으면 parsing된 SQL을 사용해라. ㅋㅋㅋ

db file random reads

높으면 적당한 인덱스와 통계가 존재하는지 확인해라.

db file random writes

높으면 bgwriter_delay 감소가 필요하다.

btree random lock acquires

인덱스 rebuild 를 나타낸다.

위대로 하면 안된다. 책대로 하면 안된다고...

항상 여러 데이터를 가지고 잘 분석을 해야 한다.

"선무당이 사람 잡는다."는 말을 명심하자!

 

여러 wait 이벤트가 있다. 자세한 내용은 documentation을 확인 하자.

 

postgres와 PPAS DRITA의 catalog 비교로 마치자.

 

postgres catalog table 

 DRITA catalog table

 pg_stat_database

 edb$stat_database

 pg_stat_all_tables

 edb$stat_all_tables

 pg_stat_io_tables

 edb$statio_all_tables

 pg_stat_all_indexes

 edb$stat_all_indexes

 pg_statio_all_indexes

 edb$statio_all_indexes

 

[참고] http://www.enterprisedb.com/docs/en/8.4/oracompat/Table%20of%20Contents.htm#TopOfPage