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. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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;
    (1 row)

    test=# show shared_buffers;
    (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.


share|improve this question

migrated from Apr 22 '13 at 5:50

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

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);
(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 );
 24 MB
(1 row)


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;
(1 row)

regress=> SET work_mem = 25165824;
regress=> SHOW work_mem;
(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

Your Answer


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