PostgreSQLにおけるNbuffersの理解

7054 ワード

スタート
PostgreSQLのshared_を見てbuffersの値は32 MBです
印刷src/backend/storage/buffer/bufmgr.cでは、Nbuffersの値:
結果:
[postgres@localhost bin]$ ./postgres -D /usr/local/pgsql/data

LOG:  database system was shut down at 2012-11-01 17:19:27 CST

NBuffers is: 4096

LOG:  autovacuum launcher started

LOG:  database system is ready to accept connections

NBuffers is: 4096

NBuffers is: 4096

NBuffers is: 4096

NBuffers is: 4096

NBuffers is: 4096

NBuffers is: 4096

NBuffers is: 4096

NBuffers is: 4096

NBuffers is: 4096

NBuffers is: 4096

NBuffers is: 4096

NBuffers is: 4096

NBuffers is: 4096

......

[作者:技術者高健@ブログ園mail:[email protected]]
Nbuffersの資料を見てみましょう.-B NbuffersはPostgresの実行時のコマンドラインパラメータとして使用できます.
http://www.postgresql.org/docs/current/static/app-postgres.html
-B nbuffers
Sets the number of shared buffers for use by the server processes. The default value of this parameter is chosen automatically by initdb. Specifying this option is equivalent to setting the  shared_buffers  configuration parameter.
つまりNbuffersとShared_Buffersは同じはずです.
32 MBはどのように4096に等しいのでしょうか.
32 MB=32*1024*1024=33554432バイト
4096ページ*8 K/ページ=4096*8*1024=33554432バイト.
修正したらどうなるか見てみましょう.
[postgres@localhost bin]$ ./postgres -D /usr/local/pgsql/data -B 8192

LOG:  database system was shut down at 2012-11-02 09:32:27 CST

NBuffers is: 8192

LOG:  autovacuum launcher started

LOG:  database system is ready to accept connections

NBuffers is: 8192

NBuffers is: 8192

NBuffers is: 8192
[postgres@localhost bin]$ ./psql

psql (9.2.0)

Type "help" for help.



postgres=# show shared_buffers;

 shared_buffers 

----------------

 64MB

(1 row)



postgres=# 

guc.cのコードは、その対応関係を論証することもできます.
/*                                    

 * We sometimes multiply the number of shared buffers by two without                                    

 * checking for overflow, so we mustn't allow more than INT_MAX / 2.                                    

 */                                    

{                                    

    {"shared_buffers", PGC_POSTMASTER, RESOURCES_MEM,                                

        gettext_noop("Sets the number of shared memory buffers used by the server."),                            

        NULL,                            

        GUC_UNIT_BLOCKS                            

    },                                

    &NBuffers,                                

    1024, 16, INT_MAX / 2,                                

    NULL, NULL, NULL                                

},                                    

.....

[作者:技術者高健@ブログ園mail:[email protected]]
の最後の部分