Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I have a rather naive question regarding the size of shared_buffers computed from pg_buffercache and the shared_buffers size mentioned in postgresql.conf. Based on my understanding pg_buffercache shows the state of all the buffers in shared_buffers. Thus, size of shared buffers = Number of entries in pg_buffercache * Size of one page (8192 bytes). When I run this on my system :

    test=# select count(1) from pg_buffercache;
    count 
    -------
    3072
    (1 row)

    test=# show shared_buffers;
    shared_buffers 
    ----------------
    24MB
    (1 row)

Calculated size of shared buffers = 3072 * 8192 ~= 25.17 MB. Actual size of shared buffers = 24 MB.

Why is there a difference between the computed size of shared buffers and the actual size of shared buffers ? Let me know if my understanding is wrong.

Thanks.

share|improve this question
add comment

migrated from stackoverflow.com Apr 22 '13 at 5:50

This question came from our site for professional and enthusiast programmers.

1 Answer

up vote 3 down vote accepted

Looks like MB vs MiB, ie decimal SI vs binary megabyte:

regress=> SELECT round(25.17*1000*1000 / (1024*1024),1);
 round 
-------
  24.0
(1 row)

You've done your conversion into megabytes using decimal SI units (MB) not binary megabytes (MiB). Divide by 1024 not by 1000, or use pg_size_pretty:

regress=> select pg_size_pretty( 3072 * 8192::bigint );
 pg_size_pretty 
----------------
 24 MB
(1 row)

Compare:

regress=> select 
          pg_size_pretty( 3072 * 8192::bigint ),
          (3072::real * 8192)/(1024*1024) AS binaryMiB,
          (3072::real * 8192)/(1000*1000) AS decimalMB_SI;
 pg_size_pretty | binarymib | decimalmb_si 
----------------+-----------+--------------
 24 MB          |        24 |    25.165824
(1 row)

The GUC display code uses kiB / MiB / GiB too, but (IMO) mislabels it kB / MB / GB:

regress=> SELECT 24*1024*1024;
 ?column? 
----------
 25165824
(1 row)

regress=> SET work_mem = 25165824;
SET
regress=> SHOW work_mem;
 work_mem 
----------
 24GB
(1 row)

(It's GB because work_mem is measured in kb not bytes; ignore the factor-of-1024 difference).

share|improve this answer
    
Oh thanks. Silly me :) –  invinc4u Apr 22 '13 at 1:23
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.