DB2 查看缓冲池真实大小

DB2中,修改缓冲池大小的命令有两个选项,默认的是IMMEDIATE,也就是立刻生效。 另一种是DEFERRED, 它只是在系统表中做了修改,实际上没有生效,需要重新激活数据库生效,也就是使用视图SYSCAT.BUFFERPOOLS查到的,并不一定是真实大小,那么如何查看缓冲池真实大小呢?

If the statement is executed as deferred, the following is true: Although the buffer pool definition is transactional and the changes to the buffer pool definition will be reflected in the catalog tables on commit, no changes to the actual buffer pool will take effect until the next time the database is started. The current attributes of the buffer pool will exist until then, and there will not be any impact to the buffer pool in the interim. Tables created in table spaces of new database partition groups will use the default buffer pool. The statement is IMMEDIATE by default when that keyword applies.


>>-ALTER BUFFERPOOL--bufferpool-name---------------------------->


     .-IMMEDIATE-.                                                                                        
>--+-+-----------+--+-------------------------------------+--SIZE--+-number-of-pages----------------+-+-><
   | '-DEFERRED--'  '-DBPARTITIONNUM--db-partition-number-'        '-+-----------------+--AUTOMATIC-' |   
   |                                                                 '-number-of-pages-'              |   
   +-ADD DATABASE PARTITION GROUP--db-partition-group-name--------------------------------------------+   
   +-NUMBLOCKPAGES--number-of-pages--+----------------------------+-----------------------------------+   
   |                                 '-BLOCKSIZE--number-of-pages-'                                   |   
   '-BLOCKSIZE--number-of-pages-----------------------------------------------------------------------'   



答案是使用MON_GET_BUFFERPOOL表函数。


参考测试如下:

$ db2 "create bufferpool bffpl1 immediate size 1000 PAGESIZE 4k"    
DB20000I  The SQL command completed successfully.


$ db2 "select substr(BPNAME, 1, 30) as BPNAME, BUFFERPOOLID, NPAGES, PAGESIZE from SYSCAT.BUFFERPOOLS"


BPNAME                         BUFFERPOOLID NPAGES      PAGESIZE   
------------------------------ ------------ ----------- -----------
IBMDEFAULTBP                              1          -2        4096
BFFPL1                                    2        1000        4096


  2 record(s) selected.


1.)
$ db2 "alter bufferpool bffpl1 size 1500"
DB20000I  The SQL command completed successfully.


$ db2 "select substr(BPNAME, 1, 30) as BPNAME, BUFFERPOOLID, NPAGES, PAGESIZE from SYSCAT.BUFFERPOOLS"


BPNAME                         BUFFERPOOLID NPAGES      PAGESIZE   
------------------------------ ------------ ----------- -----------
IBMDEFAULTBP                              1          -2        4096
BFFPL1                                    2        1500        4096


  2 record(s) selected.


$ db2 "select substr(BP_NAME, 1, 30) as BP_NAME, BP_CUR_BUFFSZ from table(MON_GET_BUFFERPOOL('BFFPL1',-1))"


BP_NAME                        BP_CUR_BUFFSZ       
------------------------------ --------------------
BFFPL1                                         1500


  1 record(s) selected.


采用默认的方式,发现系统表里发生了变化,实际大小也改变了。
  
2.)
$  db2 "alter bufferpool bffpl1 DEFERRED size 2000" 
DB20000I  The SQL command completed successfully.


$ db2 "select substr(BPNAME, 1, 30) as BPNAME, BUFFERPOOLID, NPAGES, PAGESIZE from SYSCAT.BUFFERPOOLS"


BPNAME                         BUFFERPOOLID NPAGES      PAGESIZE   
------------------------------ ------------ ----------- -----------
IBMDEFAULTBP                              1          -2        4096
BFFPL1                                    2        2000        4096


  2 record(s) selected.


$ db2 "select substr(BP_NAME, 1, 30) as BP_NAME, BP_CUR_BUFFSZ from table(MON_GET_BUFFERPOOL('BFFPL1',-1))"


BP_NAME                        BP_CUR_BUFFSZ       
------------------------------ --------------------
BFFPL1                                         1500


  1 record(s) selected.


采用了DEFERRED,虽然系统表发生了变化(1500->2000),但缓冲池实际大小没变(1500->1500),必须重新激活数据库才生效。


$ db2 terminate
DB20000I  The TERMINATE command completed successfully.


$ db2 connect to qsmiao


   Database Connection Information


 Database server        = DB2/AIX64 9.7.6
 SQL authorization ID   = E97Q6C
 Local database alias   = QSMIAO


$  db2 "select substr(BP_NAME, 1, 30) as BP_NAME, BP_CUR_BUFFSZ from table(MON_GET_BUFFERPOOL('BFFPL1',-1))"


BP_NAME                        BP_CUR_BUFFSZ       
------------------------------ --------------------
BFFPL1                                         2000


  1 record(s) selected.  

你可能感兴趣的:(DB2)